]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/letest/letsutil.cpp
   2  ******************************************************************************* 
   4  *   Copyright (C) 1999-2014, 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" 
  24 #include "OpenTypeLayoutEngine.h" 
  32 char *getCString(const UnicodeString 
*uString
) 
  34     if (uString 
== NULL
) { 
  38     le_int32 uLength 
= uString
->length(); 
  39     le_int32 cLength 
= uString
->extract(0, uLength
, NULL
, 0, US_INV
); 
  40     char *cString 
= NEW_ARRAY(char, cLength 
+ 1); 
  42     uString
->extract(0, uLength
, cString
, cLength
, US_INV
); 
  43     cString
[cLength
] = '\0'; 
  48 char *getCString(const LEUnicode16 
*uChars
) 
  54     const UnicodeString 
ustring(uChars
); 
  56     return getCString(&ustring
); 
  59 char *getUTF8String(const UnicodeString 
*uString
) 
  61     if (uString 
== NULL
) { 
  65     le_int32 uLength 
= uString
->length(); 
  66     le_int32 cLength 
= uString
->extract(0, uLength
, NULL
, 0, "UTF-8"); 
  67     char *cString 
= NEW_ARRAY(char, cLength 
+ 1); 
  69     uString
->extract(0, uLength
, cString
, cLength
, "UTF-8"); 
  71     cString
[cLength
] = '\0'; 
  76 void freeCString(char *cString
) 
  78     DELETE_ARRAY(cString
); 
  81 le_bool 
getRTL(const UnicodeString 
&text
) 
  84     UErrorCode status 
= U_ZERO_ERROR
; 
  85     le_int32 charCount 
= text
.length(); 
  87     UBiDi 
*ubidi 
= ubidi_openSized(charCount
, 0, &status
); 
  89     ubidi_setPara(ubidi
, text
.getBuffer(), charCount
, UBIDI_DEFAULT_LTR
, NULL
, &status
); 
  91     // TODO: Should check that there's only a single logical run... 
  92     ubidi_getLogicalRun(ubidi
, 0, &limit
, &level
); 
  99 le_int32 
getLanguageCode(const char *lang
) 
 101     if (strlen(lang
) != 3) { 
 105     LETag langTag 
= (LETag
) ((lang
[0] << 24) + (lang
[1] << 16) + (lang
[2] << 8) + 0x20); 
 107 #ifndef USING_ICULEHB 
 108     for (le_int32 i 
= 0; i 
< languageCodeCount
; i 
+= 1) { 
 109         if (langTag 
== OpenTypeLayoutEngine::languageTags
[i
]) {