Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: third_party/WebKit/Source/wtf/text/WTFString.h

Issue 2585063002: Cache contains only ascii in StringImpl (Closed)
Patch Set: DCHECK + static_Cast Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 static String fromUTF8(const CString&); 398 static String fromUTF8(const CString&);
399 399
400 // Tries to convert the passed in string to UTF-8, but will fall back to 400 // Tries to convert the passed in string to UTF-8, but will fall back to
401 // Latin-1 if the string is not valid UTF-8. 401 // Latin-1 if the string is not valid UTF-8.
402 static String fromUTF8WithLatin1Fallback(const LChar*, size_t); 402 static String fromUTF8WithLatin1Fallback(const LChar*, size_t);
403 static String fromUTF8WithLatin1Fallback(const char* s, size_t length) { 403 static String fromUTF8WithLatin1Fallback(const char* s, size_t length) {
404 return fromUTF8WithLatin1Fallback(reinterpret_cast<const LChar*>(s), 404 return fromUTF8WithLatin1Fallback(reinterpret_cast<const LChar*>(s),
405 length); 405 length);
406 } 406 }
407 407
408 bool containsOnlyASCII() const; 408 bool containsOnlyASCII() const {
409 return !m_impl || m_impl->containsOnlyASCII();
410 }
409 bool containsOnlyLatin1() const; 411 bool containsOnlyLatin1() const;
410 bool containsOnlyWhitespace() const { 412 bool containsOnlyWhitespace() const {
411 return !m_impl || m_impl->containsOnlyWhitespace(); 413 return !m_impl || m_impl->containsOnlyWhitespace();
412 } 414 }
413 415
414 size_t charactersSizeInBytes() const { 416 size_t charactersSizeInBytes() const {
415 return m_impl ? m_impl->charactersSizeInBytes() : 0; 417 return m_impl ? m_impl->charactersSizeInBytes() : 0;
416 } 418 }
417 419
418 // Hash table deleted values, which are only constructed and never copied or 420 // Hash table deleted values, which are only constructed and never copied or
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 548
547 #ifdef __OBJC__ 549 #ifdef __OBJC__
548 // This is for situations in WebKit where the long standing behavior has been 550 // This is for situations in WebKit where the long standing behavior has been
549 // "nil if empty", so we try to maintain longstanding behavior for the sake of 551 // "nil if empty", so we try to maintain longstanding behavior for the sake of
550 // entrenched clients 552 // entrenched clients
551 inline NSString* nsStringNilIfEmpty(const String& str) { 553 inline NSString* nsStringNilIfEmpty(const String& str) {
552 return str.isEmpty() ? nil : (NSString*)str; 554 return str.isEmpty() ? nil : (NSString*)str;
553 } 555 }
554 #endif 556 #endif
555 557
556 inline bool String::containsOnlyASCII() const {
557 if (isEmpty())
558 return true;
559
560 if (is8Bit())
561 return charactersAreAllASCII(characters8(), m_impl->length());
562
563 return charactersAreAllASCII(characters16(), m_impl->length());
564 }
565
566 WTF_EXPORT int codePointCompare(const String&, const String&); 558 WTF_EXPORT int codePointCompare(const String&, const String&);
567 559
568 inline bool codePointCompareLessThan(const String& a, const String& b) { 560 inline bool codePointCompareLessThan(const String& a, const String& b) {
569 return codePointCompare(a.impl(), b.impl()) < 0; 561 return codePointCompare(a.impl(), b.impl()) < 0;
570 } 562 }
571 563
572 WTF_EXPORT int codePointCompareIgnoringASCIICase(const String&, const char*); 564 WTF_EXPORT int codePointCompareIgnoringASCIICase(const String&, const char*);
573 565
574 template <bool isSpecialCharacter(UChar)> 566 template <bool isSpecialCharacter(UChar)>
575 inline bool String::isAllSpecialCharacters() const { 567 inline bool String::isAllSpecialCharacters() const {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 using WTF::String; 622 using WTF::String;
631 using WTF::emptyString; 623 using WTF::emptyString;
632 using WTF::emptyString16Bit; 624 using WTF::emptyString16Bit;
633 using WTF::charactersAreAllASCII; 625 using WTF::charactersAreAllASCII;
634 using WTF::equal; 626 using WTF::equal;
635 using WTF::find; 627 using WTF::find;
636 using WTF::isSpaceOrNewline; 628 using WTF::isSpaceOrNewline;
637 629
638 #include "wtf/text/AtomicString.h" 630 #include "wtf/text/AtomicString.h"
639 #endif // WTFString_h 631 #endif // WTFString_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringImpl.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698