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

Side by Side Diff: source/common/loclikely.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 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 | « source/common/locid.cpp ('k') | source/common/locmap.c » ('j') | 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 ******************************************************************************* 2 *******************************************************************************
3 * 3 *
4 * Copyright (C) 1997-2012, International Business Machines 4 * Copyright (C) 1997-2014, International Business Machines
5 * Corporation and others. All Rights Reserved. 5 * Corporation and others. All Rights Reserved.
6 * 6 *
7 ******************************************************************************* 7 *******************************************************************************
8 * file name: loclikely.cpp 8 * file name: loclikely.cpp
9 * encoding: US-ASCII 9 * encoding: US-ASCII
10 * tab size: 8 (not used) 10 * tab size: 8 (not used)
11 * indentation:4 11 * indentation:4
12 * 12 *
13 * created on: 2010feb25 13 * created on: 2010feb25
14 * created by: Markus W. Scherer 14 * created by: Markus W. Scherer
15 * 15 *
16 * Code for likely and minimized locale subtags, separated out from other .cpp files 16 * Code for likely and minimized locale subtags, separated out from other .cpp files
17 * that then do not depend on resource bundle code and likely-subtags data. 17 * that then do not depend on resource bundle code and likely-subtags data.
18 */ 18 */
19 19
20 #include "unicode/utypes.h" 20 #include "unicode/utypes.h"
21 #include "unicode/locid.h"
21 #include "unicode/putil.h" 22 #include "unicode/putil.h"
22 #include "unicode/uloc.h" 23 #include "unicode/uloc.h"
23 #include "unicode/ures.h" 24 #include "unicode/ures.h"
25 #include "unicode/uscript.h"
24 #include "cmemory.h" 26 #include "cmemory.h"
25 #include "cstring.h" 27 #include "cstring.h"
26 #include "ulocimp.h" 28 #include "ulocimp.h"
27 #include "ustr_imp.h" 29 #include "ustr_imp.h"
28 30
29 /** 31 /**
30 * This function looks for the localeID in the likelySubtags resource. 32 * This function looks for the localeID in the likelySubtags resource.
31 * 33 *
32 * @param localeID The tag to find. 34 * @param localeID The tag to find.
33 * @param buffer A buffer to hold the matching entry 35 * @param buffer A buffer to hold the matching entry
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 return -1; 1268 return -1;
1267 } 1269 }
1268 else { 1270 else {
1269 return _uloc_minimizeSubtags( 1271 return _uloc_minimizeSubtags(
1270 localeBuffer, 1272 localeBuffer,
1271 minimizedLocaleID, 1273 minimizedLocaleID,
1272 minimizedLocaleIDCapacity, 1274 minimizedLocaleIDCapacity,
1273 err); 1275 err);
1274 } 1276 }
1275 } 1277 }
1278
1279 // Pairs of (language subtag, + or -) for finding out fast if common languages
1280 // are LTR (minus) or RTL (plus).
1281 static const char* LANG_DIR_STRING =
1282 "root-en-es-pt-zh-ja-ko-de-fr-it-ar+he+fa+ru-nl-pl-th-tr-";
1283
1284 // Implemented here because this calls uloc_addLikelySubtags().
1285 U_CAPI UBool U_EXPORT2
1286 uloc_isRightToLeft(const char *locale) {
1287 UErrorCode errorCode = U_ZERO_ERROR;
1288 char script[8];
1289 int32_t scriptLength = uloc_getScript(locale, script, UPRV_LENGTHOF(script), &errorCode);
1290 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING ||
1291 scriptLength == 0) {
1292 // Fastpath: We know the likely scripts and their writing direction
1293 // for some common languages.
1294 errorCode = U_ZERO_ERROR;
1295 char lang[8];
1296 int32_t langLength = uloc_getLanguage(locale, lang, UPRV_LENGTHOF(lang), &errorCode);
1297 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING ||
1298 langLength == 0) {
1299 return FALSE;
1300 }
1301 const char* langPtr = uprv_strstr(LANG_DIR_STRING, lang);
1302 if (langPtr != NULL) {
1303 switch (langPtr[langLength]) {
1304 case '-': return FALSE;
1305 case '+': return TRUE;
1306 default: break; // partial match of a longer code
1307 }
1308 }
1309 // Otherwise, find the likely script.
1310 errorCode = U_ZERO_ERROR;
1311 char likely[ULOC_FULLNAME_CAPACITY];
1312 (void)uloc_addLikelySubtags(locale, likely, UPRV_LENGTHOF(likely), &erro rCode);
1313 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING ) {
1314 return FALSE;
1315 }
1316 scriptLength = uloc_getScript(likely, script, UPRV_LENGTHOF(script), &er rorCode);
1317 if (U_FAILURE(errorCode) || errorCode == U_STRING_NOT_TERMINATED_WARNING ||
1318 scriptLength == 0) {
1319 return FALSE;
1320 }
1321 }
1322 UScriptCode scriptCode = (UScriptCode)u_getPropertyValueEnum(UCHAR_SCRIPT, s cript);
1323 return uscript_isRightToLeft(scriptCode);
1324 }
1325
1326 U_NAMESPACE_BEGIN
1327
1328 UBool
1329 Locale::isRightToLeft() const {
1330 return uloc_isRightToLeft(getBaseName());
1331 }
1332
1333 U_NAMESPACE_END
OLDNEW
« no previous file with comments | « source/common/locid.cpp ('k') | source/common/locmap.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698