Changeset 239970 in webkit
- Timestamp:
- Jan 14, 2019 7:26:04 PM (5 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r239967 r239970 1 2019-01-14 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 Use unorm2_normalize instead of precomposedStringWithCanonicalMapping in userVisibleString 4 https://bugs.webkit.org/show_bug.cgi?id=192945 5 6 Reviewed by Alex Christensen. 7 8 Replace use of the nice NSString function precomposedStringWithCanonicalMapping with the ICU 9 API unorm2_normalize. This is to prep the code for translation to cross-platform C++. Of 10 course this is much worse than the preexisting code, but this is just a transitional 11 measure and not the final state of the code. It wouldn't make sense to do this if the code 12 were to remain Objective C++. 13 14 * wtf/cocoa/NSURLExtras.mm: 15 (WTF::toNormalizationFormC): 16 (WTF::userVisibleString): 17 1 18 2019-01-14 Alex Christensen <achristensen@webkit.org> 2 19 -
trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm
r239967 r239970 33 33 #import <unicode/uchar.h> 34 34 #import <unicode/uidna.h> 35 #import <unicode/unorm.h> 35 36 #import <unicode/uscript.h> 36 37 #import <wtf/Function.h> … … 1106 1107 } 1107 1108 1109 static String toNormalizationFormC(const String& string) 1110 { 1111 auto sourceBuffer = string.charactersWithNullTermination(); 1112 ASSERT(sourceBuffer.last() == '\0'); 1113 sourceBuffer.removeLast(); 1114 1115 String result; 1116 Vector<UChar, URL_BYTES_BUFFER_LENGTH> normalizedCharacters(sourceBuffer.size()); 1117 UErrorCode uerror = U_ZERO_ERROR; 1118 int32_t normalizedLength = 0; 1119 const UNormalizer2 *normalizer = unorm2_getNFCInstance(&uerror); 1120 if (!U_FAILURE(uerror)) { 1121 normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedCharacters.size(), &uerror); 1122 if (uerror == U_BUFFER_OVERFLOW_ERROR) { 1123 uerror = U_ZERO_ERROR; 1124 normalizedCharacters.resize(normalizedLength); 1125 normalizedLength = unorm2_normalize(normalizer, sourceBuffer.data(), sourceBuffer.size(), normalizedCharacters.data(), normalizedLength, &uerror); 1126 } 1127 if (!U_FAILURE(uerror)) 1128 result = String(normalizedCharacters.data(), normalizedLength); 1129 } 1130 1131 return result; 1132 } 1133 1108 1134 NSString *userVisibleString(NSURL *URL) 1109 1135 { … … 1176 1202 } 1177 1203 1178 result = [result precomposedStringWithCanonicalMapping]; 1204 auto wtfString = String(result.get()); 1205 auto normalized = toNormalizationFormC(wtfString); 1206 result = static_cast<NSString *>(normalized); 1179 1207 return CFBridgingRelease(createStringWithEscapedUnsafeCharacters((__bridge CFStringRef)result.get())); 1180 1208 }
Note: See TracChangeset
for help on using the changeset viewer.