Changeset 263665 in webkit
- Timestamp:
- Jun 29, 2020 10:23:27 AM (4 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r263635 r263665 1 2020-06-29 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [WTF] Add more StringView / ASCIILiteral helper functions and add ICUDeleter 4 https://bugs.webkit.org/show_bug.cgi?id=209774 5 6 Reviewed by Ross Kirsling and Darin Adler. 7 8 Add ICUDeleter for cleaner ICU object deletion. 9 Add ICU::majorVersion and ICU::minorVersion to switch the skeleton string in Intl.NumberFormat. 10 Add more features for ASCIILiteral. 11 12 This patch is part of https://bugs.webkit.org/show_bug.cgi?id=209774. I land it separately from 13 Intl.NumberFormat change to unlock the further Intl implementations using ICUDeleter. 14 15 * WTF.xcodeproj/project.pbxproj: 16 * wtf/CMakeLists.txt: 17 * wtf/text/ASCIILiteral.h: 18 * wtf/text/StringView.cpp: 19 (WTF::codePointCompare): 20 * wtf/text/StringView.h: 21 (WTF::StringView::StringView): 22 * wtf/unicode/icu/ICUHelpers.cpp: Copied from Source/WTF/wtf/text/ASCIILiteral.h. 23 (WTF::ICU::version): 24 (WTF::ICU::majorVersion): 25 (WTF::ICU::minorVersion): 26 * wtf/unicode/icu/ICUHelpers.h: 27 (WTF::ICUDeleter::operator()): 28 1 29 2020-06-28 Geoffrey Garen <ggaren@apple.com> 2 30 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r263529 r263665 181 181 E392FA2722E92BFF00ECDC73 /* ResourceUsageCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E392FA2622E92BFF00ECDC73 /* ResourceUsageCocoa.cpp */; }; 182 182 E3A32BC41FC830E2007D7E76 /* JSValueMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3A32BC21FC830E2007D7E76 /* JSValueMalloc.cpp */; }; 183 E3BE09A724A5854D009DF2B4 /* ICUHelpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3BE09A624A58545009DF2B4 /* ICUHelpers.cpp */; }; 183 184 E4A0AD391A96245500536DF6 /* WorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A0AD371A96245500536DF6 /* WorkQueue.cpp */; }; 184 185 E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A0AD3C1A96253C00536DF6 /* WorkQueueCocoa.cpp */; }; … … 732 733 E3A32BC21FC830E2007D7E76 /* JSValueMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSValueMalloc.cpp; sourceTree = "<group>"; }; 733 734 E3A32BC31FC830E2007D7E76 /* JSValueMalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSValueMalloc.h; sourceTree = "<group>"; }; 735 E3BE09A624A58545009DF2B4 /* ICUHelpers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ICUHelpers.cpp; sourceTree = "<group>"; }; 734 736 E3CF76902115D6BA0091DE48 /* CompactPointerTuple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompactPointerTuple.h; sourceTree = "<group>"; }; 735 737 E3E158251EADA53C004A079D /* SystemFree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemFree.h; sourceTree = "<group>"; }; … … 1274 1276 553071C91C40427200384898 /* TinyLRUCache.h */, 1275 1277 0FED67B51B22D4D80066CE15 /* TinyPtrSet.h */, 1278 521CC6B324A277C2004377D6 /* TranslatedProcess.cpp */, 1276 1279 2D1F2F462498F73300C63A83 /* TranslatedProcess.h */, 1277 521CC6B324A277C2004377D6 /* TranslatedProcess.cpp */,1278 1280 149EF16216BBFE0D000A4331 /* TriState.h */, 1279 1281 83FBA93119DF459700F30ADB /* TypeCasts.h */, … … 1453 1455 children = ( 1454 1456 A8A47350151A825B004123FF /* CollatorICU.cpp */, 1457 E3BE09A624A58545009DF2B4 /* ICUHelpers.cpp */, 1455 1458 52B228C12458DC8200753D91 /* ICUHelpers.h */, 1456 1459 ); … … 1677 1680 A8A473D8151A825B004123FF /* HashTable.cpp in Sources */, 1678 1681 93B5B44E2213D616004B7AA7 /* HexNumber.cpp in Sources */, 1682 E3BE09A724A5854D009DF2B4 /* ICUHelpers.cpp in Sources */, 1679 1683 7A05093F1FB9DCC500B33FB8 /* JSONValues.cpp in Sources */, 1680 1684 E3A32BC41FC830E2007D7E76 /* JSValueMalloc.cpp in Sources */, … … 1748 1752 0FDDBFA71666DFA300C55FEF /* StringPrintStream.cpp in Sources */, 1749 1753 93F1993E19D7958D00C2390B /* StringView.cpp in Sources */, 1750 521CC6B424A27809004377D6 /* TranslatedProcess.cpp in Sources */,1751 1754 93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */, 1752 1755 93934BD318A1E8C300D0D6A1 /* StringViewCocoa.mm in Sources */, … … 1765 1768 0F66B2901DC97BAB004A1D3F /* TimeWithDynamicClockType.cpp in Sources */, 1766 1769 0F7075F51FBF53CD00489AF0 /* TimingScope.cpp in Sources */, 1770 521CC6B424A27809004377D6 /* TranslatedProcess.cpp in Sources */, 1767 1771 0FA6F39520CCACE900A03DCD /* UniqueArray.cpp in Sources */, 1768 1772 5CC0EE7621629F1900A1A842 /* URL.cpp in Sources */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r263529 r263665 500 500 501 501 unicode/icu/CollatorICU.cpp 502 unicode/icu/ICUHelpers.cpp 502 503 ) 503 504 -
trunk/Source/WTF/wtf/text/ASCIILiteral.h
r263341 r263665 27 27 28 28 #include <wtf/ASCIICType.h> 29 #include <wtf/StdLibExtras.h> 29 30 30 31 namespace WTF { … … 48 49 } 49 50 50 const char* characters() const { return m_characters; } 51 constexpr const char* characters() const { return m_characters; } 52 const LChar* characters8() const { return bitwise_cast<const LChar*>(m_characters); } 53 size_t length() const { return strlen(m_characters); } 51 54 52 55 private: -
trunk/Source/WTF/wtf/text/StringView.cpp
r261661 r263665 339 339 { 340 340 return find(string) != notFound; 341 } 342 343 int codePointCompare(StringView lhs, StringView rhs) 344 { 345 bool lhsIs8Bit = lhs.is8Bit(); 346 bool rhsIs8Bit = rhs.is8Bit(); 347 if (lhsIs8Bit) { 348 if (rhsIs8Bit) 349 return codePointCompare(lhs.characters8(), lhs.length(), rhs.characters8(), rhs.length()); 350 return codePointCompare(lhs.characters8(), lhs.length(), rhs.characters16(), rhs.length()); 351 } 352 if (rhsIs8Bit) 353 return codePointCompare(lhs.characters16(), lhs.length(), rhs.characters8(), rhs.length()); 354 return codePointCompare(lhs.characters16(), lhs.length(), rhs.characters16(), rhs.length()); 341 355 } 342 356 -
trunk/Source/WTF/wtf/text/StringView.h
r260881 r263665 32 32 #include <wtf/RetainPtr.h> 33 33 #include <wtf/Vector.h> 34 #include <wtf/text/ASCIILiteral.h> 34 35 #include <wtf/text/CString.h> 35 36 #include <wtf/text/ConversionMode.h> … … 69 70 StringView(const char*); 70 71 StringView(const char*, unsigned length); 72 explicit StringView(ASCIILiteral); 71 73 72 74 static StringView empty(); … … 355 357 { 356 358 initialize(reinterpret_cast<const LChar*>(characters), length); 359 } 360 361 inline StringView::StringView(ASCIILiteral string) 362 { 363 initialize(string.characters8(), string.length()); 357 364 } 358 365 … … 1067 1074 } 1068 1075 1076 WTF_EXPORT_PRIVATE int codePointCompare(StringView, StringView); 1077 1069 1078 } // namespace WTF 1070 1079 -
trunk/Source/WTF/wtf/unicode/icu/ICUHelpers.cpp
r263663 r263665 1 1 /* 2 * Copyright (C) 20 18 Yusuke Suzuki <utatane.tea@gmail.com>2 * Copyright (C) 2020 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #pragma once 26 #include "config.h" 27 #include <wtf/unicode/icu/ICUHelpers.h> 27 28 28 #include <wtf/ASCIICType.h> 29 #include <mutex> 30 #include <unicode/uvernum.h> 29 31 30 32 namespace WTF { 33 namespace ICU { 31 34 32 class PrintStream; 33 34 class ASCIILiteral final { 35 public: 36 operator const char*() const { return m_characters; } 37 38 static constexpr ASCIILiteral fromLiteralUnsafe(const char* string) 39 { 40 return ASCIILiteral { string }; 41 } 42 43 WTF_EXPORT_PRIVATE void dump(PrintStream& out) const; 44 45 static constexpr ASCIILiteral null() 46 { 47 return ASCIILiteral { nullptr }; 48 } 49 50 const char* characters() const { return m_characters; } 51 52 private: 53 constexpr explicit ASCIILiteral(const char* characters) : m_characters(characters) { } 54 55 const char* m_characters; 56 }; 57 58 inline namespace StringLiterals { 59 60 constexpr ASCIILiteral operator"" _s(const char* characters, size_t n) 35 static const UVersionInfo& version() 61 36 { 62 #if ASSERT_ENABLED 63 for (size_t i = 0; i < n; ++i) 64 ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(characters[i])); 65 #else 66 UNUSED_PARAM(n); 67 #endif 68 return ASCIILiteral::fromLiteralUnsafe(characters); 37 static UVersionInfo versions { }; 38 static std::once_flag onceKey; 39 std::call_once(onceKey, [&] { 40 u_getVersion(versions); 41 }); 42 return versions; 69 43 } 70 44 71 } // inline StringLiterals 45 unsigned majorVersion() 46 { 47 static_assert(0 < U_MAX_VERSION_LENGTH); 48 return version()[0]; 49 } 72 50 73 } // namespace WTF 51 unsigned minorVersion() 52 { 53 static_assert(1 < U_MAX_VERSION_LENGTH); 54 return version()[1]; 55 } 74 56 75 using namespace WTF::StringLiterals; 76 using WTF::ASCIILiteral; 57 } } // namespace WTF::ICU -
trunk/Source/WTF/wtf/unicode/icu/ICUHelpers.h
r261386 r263665 29 29 #include <unicode/utypes.h> 30 30 #include <wtf/Forward.h> 31 #include <wtf/FunctionTraits.h> 31 32 32 33 namespace WTF { … … 108 109 } 109 110 110 } 111 template<auto deleteFunction> 112 struct ICUDeleter { 113 void operator()(typename FunctionTraits<decltype(deleteFunction)>::template ArgumentType<0> pointer) 114 { 115 if (pointer) 116 deleteFunction(pointer); 117 } 118 }; 119 120 namespace ICU { 121 122 WTF_EXPORT_PRIVATE unsigned majorVersion(); 123 WTF_EXPORT_PRIVATE unsigned minorVersion(); 124 125 } // namespace ICU 126 } // namespace WTF 111 127 112 128 using WTF::callBufferProducingFunction; 113 129 using WTF::needsToGrowToProduceCString; 114 130 using WTF::needsToGrowToProduceBuffer; 131 using WTF::ICUDeleter;
Note: See TracChangeset
for help on using the changeset viewer.