]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/letest/letsutil.cpp
1726b4e5770c3683f8a16f069b621960dbc37428
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1999-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: letsutil.cpp
12 * created on: 04/25/2006
13 * created by: Eric R. Mader
16 #include "unicode/utypes.h"
17 #include "unicode/unistr.h"
18 #include "unicode/ubidi.h"
20 #include "layout/LETypes.h"
21 #include "layout/LEScripts.h"
22 #include "layout/LayoutEngine.h"
23 #include "layout/LELanguages.h"
26 #include "OpenTypeLayoutEngine.h"
34 char *getCString(const UnicodeString
*uString
)
36 if (uString
== NULL
) {
40 le_int32 uLength
= uString
->length();
41 le_int32 cLength
= uString
->extract(0, uLength
, NULL
, 0, US_INV
);
42 char *cString
= NEW_ARRAY(char, cLength
+ 1);
44 uString
->extract(0, uLength
, cString
, cLength
, US_INV
);
45 cString
[cLength
] = '\0';
50 char *getCString(const LEUnicode16
*uChars
)
56 const UnicodeString
ustring(uChars
);
58 return getCString(&ustring
);
61 char *getUTF8String(const UnicodeString
*uString
)
63 if (uString
== NULL
) {
67 le_int32 uLength
= uString
->length();
68 le_int32 cLength
= uString
->extract(0, uLength
, NULL
, 0, "UTF-8");
69 char *cString
= NEW_ARRAY(char, cLength
+ 1);
71 uString
->extract(0, uLength
, cString
, cLength
, "UTF-8");
73 cString
[cLength
] = '\0';
78 void freeCString(char *cString
)
80 DELETE_ARRAY(cString
);
83 le_bool
getRTL(const UnicodeString
&text
)
86 UErrorCode status
= U_ZERO_ERROR
;
87 le_int32 charCount
= text
.length();
89 UBiDi
*ubidi
= ubidi_openSized(charCount
, 0, &status
);
91 ubidi_setPara(ubidi
, text
.getBuffer(), charCount
, UBIDI_DEFAULT_LTR
, NULL
, &status
);
93 // TODO: Should check that there's only a single logical run...
94 ubidi_getLogicalRun(ubidi
, 0, &limit
, &level
);
101 le_int32
getLanguageCode(const char *lang
)
103 if (strlen(lang
) != 3) {
107 LETag langTag
= (LETag
) ((lang
[0] << 24) + (lang
[1] << 16) + (lang
[2] << 8) + 0x20);
109 #ifndef USING_ICULEHB
110 for (le_int32 i
= 0; i
< languageCodeCount
; i
+= 1) {
111 if (langTag
== OpenTypeLayoutEngine::languageTags
[i
]) {
116 if (!strcmp(lang
, "JAN")) return janLanguageCode
;
117 if (!strcmp(lang
, "KOR")) return korLanguageCode
;
118 if (!strcmp(lang
, "ZHT")) return zhtLanguageCode
;
119 if (!strcmp(lang
, "ZHS")) return zhsLanguageCode
;
120 if (!strcmp(lang
, "HIN")) return hinLanguageCode
;
121 if (!strcmp(lang
, "MAR")) return marLanguageCode
;
122 if (!strcmp(lang
, "ROM")) return romLanguageCode
;