Changeset 57904 in webkit for trunk/JavaScriptCore/wtf/text/WTFString.cpp
- Timestamp:
- Apr 20, 2010, 12:28:41 PM (15 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/text/WTFString.cpp
r57828 r57904 21 21 22 22 #include "config.h" 23 #include "PlatformString.h" 24 25 #include "FloatConversion.h" 26 #include "SharedBuffer.h" 27 #include "StringBuffer.h" 28 #include "TextBreakIterator.h" 23 #include "WTFString.h" 24 29 25 #include <limits> 30 26 #include <stdarg.h> … … 641 637 } 642 638 643 #ifndef NDEBUG644 639 Vector<char> String::ascii() const 645 640 { … … 655 650 return buffer; 656 651 } 657 #endif658 652 659 653 CString String::latin1() const … … 951 945 { 952 946 // FIXME: This will return ok even when the string fits into a double but not a float. 953 return narrowPrecisionToFloat(charactersToDouble(data, length, ok)); 954 } 955 956 PassRefPtr<SharedBuffer> utf8Buffer(const String& string) 957 { 958 // Allocate a buffer big enough to hold all the characters. 959 const int length = string.length(); 960 Vector<char> buffer(length * 3); 961 962 // Convert to runs of 8-bit characters. 963 char* p = buffer.data(); 964 const UChar* d = string.characters(); 965 ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), true); 966 if (result != conversionOK) 967 return 0; 968 969 buffer.shrink(p - buffer.data()); 970 return SharedBuffer::adoptVector(buffer); 971 } 972 973 unsigned numGraphemeClusters(const String& s) 974 { 975 TextBreakIterator* it = characterBreakIterator(s.characters(), s.length()); 976 if (!it) 977 return s.length(); 978 979 unsigned num = 0; 980 while (textBreakNext(it) != TextBreakDone) 981 ++num; 982 return num; 983 } 984 985 unsigned numCharactersInGraphemeClusters(const String& s, unsigned numGraphemeClusters) 986 { 987 TextBreakIterator* it = characterBreakIterator(s.characters(), s.length()); 988 if (!it) 989 return min(s.length(), numGraphemeClusters); 990 991 for (unsigned i = 0; i < numGraphemeClusters; ++i) { 992 if (textBreakNext(it) == TextBreakDone) 993 return s.length(); 994 } 995 return textBreakCurrent(it); 947 return static_cast<float>(charactersToDouble(data, length, ok)); 996 948 } 997 949
Note:
See TracChangeset
for help on using the changeset viewer.