this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreServices: UnicodeUtilities fixes

+26 -11
+26 -11
src/CoreServices/UnicodeUtilities.cpp
··· 23 23 #include <unicode/sortkey.h> 24 24 #include <string> 25 25 #include <cstring> 26 + #include <endian.h> 26 27 #include "MacErrors.h" 28 + #include "util/log.h" 29 + 30 + // UniChar uses platform endianness, whereas ICU expects BE by default 31 + #if __BYTE_ORDER == __BIG_ENDIAN 32 + # define UNICHAR_ENCODING "UTF-16BE" 33 + #elif __BYTE_ORDER == __LITTLE_ENDIAN 34 + # define UNICHAR_ENCODING "UTF-16LE" 35 + #else 36 + # error Cannot determine endianness! 37 + #endif 27 38 28 39 namespace Darling 29 40 { ··· 48 59 49 60 OSStatus UCCreateCollator(LocaleRef locale, LocaleOperationVariant opVariant, uint32_t options, CollatorRef* collator) 50 61 { 51 - UErrorCode code; 52 - Collator* c = Collator::createInstance(Darling::getLocaleString(locale), code); 62 + UErrorCode code = U_ZERO_ERROR; 63 + const char* localeStr = Darling::getLocaleString(locale); 64 + Collator* c = Collator::createInstance(localeStr, code); 53 65 54 66 *collator = c; 55 67 56 68 if (!c) 57 69 return paramErr; 58 70 71 + code = U_ZERO_ERROR; 59 72 c->setAttribute(UCOL_STRENGTH, optsToColAttr(options), code); 60 73 return noErr; 61 74 } ··· 65 78 if (!text || !actualKeySize || !collationKey || !collator) 66 79 return paramErr; 67 80 68 - UnicodeString str1((const char*) text, textlen*2, "UTF-16"); 81 + UnicodeString str1((const char*) text, textlen*2, UNICHAR_ENCODING); 69 82 Collator* c = static_cast<Collator*>(collator); 70 83 CollationKey key; 71 - UErrorCode code; 84 + UErrorCode code = U_ZERO_ERROR; 72 85 int32_t count; 73 86 const uint8_t* data; 74 87 ··· 97 110 CollationKey ckey1((const uint8_t*)key1, key1len); 98 111 CollationKey ckey2((const uint8_t*)key2, key2len); 99 112 UCollationResult result; 100 - UErrorCode code; 113 + UErrorCode code = U_ZERO_ERROR; 101 114 102 115 result = ckey1.compareTo(ckey2, code); 103 116 ··· 127 140 if (!text1 || !text2 || !collator) 128 141 return paramErr; 129 142 130 - UnicodeString str1((const char*) text1, text1len*2, "UTF-16"); 131 - UnicodeString str2((const char*) text2, text2len*2, "UTF-16"); 143 + UnicodeString str1((const char*) text1, text1len*2, UNICHAR_ENCODING); 144 + UnicodeString str2((const char*) text2, text2len*2, UNICHAR_ENCODING); 132 145 Collator* c = static_cast<Collator*>(collator); 133 146 UCollationResult result; 134 - UErrorCode code; 147 + UErrorCode code = U_ZERO_ERROR; 135 148 136 149 result = c->compare(str1, str2, code); 137 150 ··· 139 152 return -1; 140 153 141 154 if (equiv != nullptr) 142 - *equiv = result == UCOL_EQUAL; 155 + *equiv = (result == UCOL_EQUAL); 143 156 144 157 if (order != nullptr) 145 158 { ··· 163 176 164 177 OSStatus UCCompareTextDefault(uint32_t options, const UniChar* text1, unsigned long text1len, const UniChar* text2, unsigned long text2len, Boolean* equiv, int32_t* order) 165 178 { 166 - UErrorCode code; 179 + UErrorCode code = U_ZERO_ERROR; 167 180 Collator* col = Collator::createInstance(code); 168 181 OSStatus rv; 169 182 183 + code = U_ZERO_ERROR; 170 184 col->setAttribute(UCOL_STRENGTH, optsToColAttr(options), code); 171 185 rv = UCCompareText(col, text1, text1len, text2, text2len, equiv, order); 172 186 ··· 176 190 177 191 OSStatus UCCompareTextNoLocale(uint32_t options, const UniChar* text1, unsigned long text1len, const UniChar* text2, unsigned long text2len, Boolean* equiv, int32_t* order) 178 192 { 179 - UErrorCode code; 193 + UErrorCode code = U_ZERO_ERROR; 180 194 Collator* col = Collator::createInstance(Locale::getRoot(), code); // is getRoot correct? 181 195 OSStatus rv; 182 196 197 + code = U_ZERO_ERROR; 183 198 col->setAttribute(UCOL_STRENGTH, optsToColAttr(options), code); 184 199 rv = UCCompareText(col, text1, text1len, text2, text2len, equiv, order); 185 200