]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/letest/letsutil.cpp
2 *******************************************************************************
4 * Copyright (C) 1999-2008, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: letsutil.cpp
10 * created on: 04/25/2006
11 * created by: Eric R. Mader
14 #include "unicode/utypes.h"
15 #include "unicode/unistr.h"
16 #include "unicode/ubidi.h"
18 #include "layout/LETypes.h"
19 #include "layout/LEScripts.h"
20 #include "layout/LayoutEngine.h"
21 #include "layout/LELanguages.h"
23 #include "OpenTypeLayoutEngine.h"
30 char *getCString(const UnicodeString
*uString
)
32 if (uString
== NULL
) {
36 le_int32 uLength
= uString
->length();
37 le_int32 cLength
= uString
->extract(0, uLength
, NULL
, 0, US_INV
);
38 char *cString
= NEW_ARRAY(char, cLength
+ 1);
40 uString
->extract(0, uLength
, cString
, cLength
, US_INV
);
41 cString
[cLength
] = '\0';
46 char *getCString(const LEUnicode16
*uChars
)
52 const UnicodeString
ustring(uChars
);
54 return getCString(&ustring
);
57 char *getUTF8String(const UnicodeString
*uString
)
59 if (uString
== NULL
) {
63 le_int32 uLength
= uString
->length();
64 le_int32 cLength
= uString
->extract(0, uLength
, NULL
, 0, "UTF-8");
65 char *cString
= NEW_ARRAY(char, cLength
+ 1);
67 uString
->extract(0, uLength
, cString
, cLength
, "UTF-8");
69 cString
[cLength
] = '\0';
74 void freeCString(char *cString
)
76 DELETE_ARRAY(cString
);
79 le_bool
getRTL(const UnicodeString
&text
)
82 UErrorCode status
= U_ZERO_ERROR
;
83 le_int32 charCount
= text
.length();
85 UBiDi
*ubidi
= ubidi_openSized(charCount
, 0, &status
);
87 ubidi_setPara(ubidi
, text
.getBuffer(), charCount
, UBIDI_DEFAULT_LTR
, NULL
, &status
);
89 // TODO: Should check that there's only a single logical run...
90 ubidi_getLogicalRun(ubidi
, 0, &limit
, &level
);
97 le_int32
getLanguageCode(const char *lang
)
99 if (strlen(lang
) != 3) {
103 LETag langTag
= (LETag
) ((lang
[0] << 24) + (lang
[1] << 16) + (lang
[2] << 8) + 0x20);
105 for (le_int32 i
= 0; i
< languageCodeCount
; i
+= 1) {
106 if (langTag
== OpenTypeLayoutEngine::languageTags
[i
]) {