#include "unicode/utypes.h"
#include "unicode/unistr.h"
#include "unicode/uscript.h"
#include "unicode/utf16.h"
#include "ustr_imp.h"
#include "cmemory.h"
namespace {
const int32_t UNKNOWN = 1 << 21;
const int32_t EXCLUSION = 2 << 21;
const int32_t LIMITED_USE = 3 << 21;
const int32_t RECOMMENDED = 5 << 21;
const int32_t RTL = 1 << 24;
const int32_t LB_LETTERS = 1 << 25;
const int32_t CASED = 1 << 26;
const int32_t SCRIPT_PROPS[] = {
0x0040 | RECOMMENDED, 0x0308 | RECOMMENDED, 0x0628 | RECOMMENDED | RTL, 0x0531 | RECOMMENDED | CASED, 0x0995 | RECOMMENDED, 0x3105 | RECOMMENDED | LB_LETTERS, 0x13C4 | LIMITED_USE | CASED, 0x03E2 | EXCLUSION | CASED, 0x042F | RECOMMENDED | CASED, 0x10414 | EXCLUSION | CASED, 0x0905 | RECOMMENDED, 0x12A0 | RECOMMENDED, 0x10D3 | RECOMMENDED, 0x10330 | EXCLUSION, 0x03A9 | RECOMMENDED | CASED, 0x0A95 | RECOMMENDED, 0x0A15 | RECOMMENDED, 0x5B57 | RECOMMENDED | LB_LETTERS, 0xAC00 | RECOMMENDED, 0x05D0 | RECOMMENDED | RTL, 0x304B | RECOMMENDED | LB_LETTERS, 0x0C95 | RECOMMENDED, 0x30AB | RECOMMENDED | LB_LETTERS, 0x1780 | RECOMMENDED | LB_LETTERS, 0x0EA5 | RECOMMENDED | LB_LETTERS, 0x004C | RECOMMENDED | CASED, 0x0D15 | RECOMMENDED, 0x1826 | EXCLUSION, 0x1000 | RECOMMENDED | LB_LETTERS, 0x168F | EXCLUSION, 0x10300 | EXCLUSION, 0x0B15 | RECOMMENDED, 0x16A0 | EXCLUSION, 0x0D85 | RECOMMENDED, 0x0710 | LIMITED_USE | RTL, 0x0B95 | RECOMMENDED, 0x0C15 | RECOMMENDED, 0x078C | RECOMMENDED | RTL, 0x0E17 | RECOMMENDED | LB_LETTERS, 0x0F40 | RECOMMENDED, 0x14C0 | LIMITED_USE, 0xA288 | LIMITED_USE | LB_LETTERS, 0x1703 | EXCLUSION, 0x1723 | EXCLUSION, 0x1743 | EXCLUSION, 0x1763 | EXCLUSION, 0x280E | UNKNOWN, 0x10800 | EXCLUSION | RTL, 0x1900 | LIMITED_USE, 0x10000 | EXCLUSION, 0x10480 | EXCLUSION, 0x10450 | EXCLUSION, 0x1950 | LIMITED_USE | LB_LETTERS, 0x10380 | EXCLUSION, 0,
0x1A00 | EXCLUSION, 0x2C00 | EXCLUSION | CASED, 0x10A00 | EXCLUSION | RTL, 0xA800 | LIMITED_USE, 0x1980 | LIMITED_USE | LB_LETTERS, 0x2D30 | LIMITED_USE, 0x103A0 | EXCLUSION, 0x1B05 | LIMITED_USE, 0x1BC0 | LIMITED_USE, 0,
0x11005 | EXCLUSION, 0xAA00 | LIMITED_USE, 0,
0,
0,
0,
0x13153 | EXCLUSION, 0,
0x5B57 | RECOMMENDED | LB_LETTERS, 0x5B57 | RECOMMENDED | LB_LETTERS, 0x16B1C | EXCLUSION, 0x10CA1 | EXCLUSION | RTL | CASED, 0,
0xA984 | LIMITED_USE, 0xA90A | LIMITED_USE, 0,
0,
0x1C00 | LIMITED_USE, 0x10647 | EXCLUSION, 0x0840 | LIMITED_USE | RTL, 0,
0x10980 | EXCLUSION | RTL, 0x07CA | LIMITED_USE | RTL, 0x10C00 | EXCLUSION | RTL, 0x1036B | EXCLUSION, 0xA840 | EXCLUSION, 0x10900 | EXCLUSION | RTL, 0x16F00 | LIMITED_USE, 0,
0,
0,
0,
0,
0,
0xA549 | LIMITED_USE, 0,
0x12000 | EXCLUSION, 0,
0xFDD0 | UNKNOWN, 0x102A0 | EXCLUSION, 0x304B | RECOMMENDED | LB_LETTERS, 0x1A20 | LIMITED_USE | LB_LETTERS, 0x10280 | EXCLUSION, 0x10920 | EXCLUSION | RTL, 0x1C5A | LIMITED_USE, 0xA930 | EXCLUSION, 0xA882 | LIMITED_USE, 0x1D850 | EXCLUSION, 0x1B83 | LIMITED_USE, 0,
0xABC0 | LIMITED_USE, 0x10840 | EXCLUSION | RTL, 0x10B00 | EXCLUSION | RTL, 0x11103 | LIMITED_USE, 0xAC00 | RECOMMENDED, 0x11083 | EXCLUSION, 0x10AD8 | EXCLUSION | RTL, 0x10B60 | EXCLUSION | RTL, 0x10B8F | EXCLUSION | RTL, 0,
0x10B40 | EXCLUSION | RTL, 0x0800 | EXCLUSION | RTL, 0xAA80 | LIMITED_USE | LB_LETTERS, 0,
0,
0xA6A0 | LIMITED_USE, 0xA4D0 | LIMITED_USE, 0,
0x10A60 | EXCLUSION | RTL, 0x16AE6 | EXCLUSION, 0x1BC20 | EXCLUSION, 0x10500 | EXCLUSION, 0x11315 | EXCLUSION, 0,
0,
0x1E802 | EXCLUSION | RTL, 0x109A0 | EXCLUSION | RTL, 0x10A95 | EXCLUSION | RTL, 0x10896 | EXCLUSION | RTL, 0x10873 | EXCLUSION | RTL, 0x112BE | EXCLUSION, 0x118B4 | EXCLUSION | CASED, 0,
0,
0x16A4F | EXCLUSION, 0x1B1C4 | EXCLUSION | LB_LETTERS, 0x11183 | EXCLUSION, 0x110D0 | EXCLUSION, 0x11680 | EXCLUSION, 0x18229 | EXCLUSION | LB_LETTERS, 0,
0x14400 | EXCLUSION, 0x11208 | EXCLUSION, 0x11484 | EXCLUSION, 0x10537 | EXCLUSION, 0x11152 | EXCLUSION, 0x11717 | EXCLUSION | LB_LETTERS, 0x108F4 | EXCLUSION | RTL, 0x1160E | EXCLUSION, 0x1128F | EXCLUSION, 0x11AC0 | EXCLUSION, 0x1158E | EXCLUSION, 0x1E909 | LIMITED_USE | RTL | CASED, 0x11C0E | EXCLUSION, 0x11C72 | EXCLUSION, 0x11412 | LIMITED_USE, 0x104B5 | LIMITED_USE | CASED, 0x5B57 | RECOMMENDED | LB_LETTERS, 0x1112 | RECOMMENDED, 0,
0x11D10 | EXCLUSION, 0x11A5C | EXCLUSION, 0x11A0B | EXCLUSION, 0x1180B | EXCLUSION, 0x11D71 | LIMITED_USE, 0x11EE5 | EXCLUSION, 0x16E40 | EXCLUSION | CASED, 0x10D12 | LIMITED_USE | RTL, 0x10F42 | EXCLUSION | RTL, 0x10F19 | EXCLUSION | RTL, 0x10FF1 | EXCLUSION | RTL, 0x1E108 | LIMITED_USE, 0x119CE | EXCLUSION, 0x1E2E1 | LIMITED_USE, };
int32_t getScriptProps(UScriptCode script) {
if (0 <= script && script < UPRV_LENGTHOF(SCRIPT_PROPS)) {
return SCRIPT_PROPS[script];
} else {
return 0;
}
}
}
U_CAPI int32_t U_EXPORT2
uscript_getSampleString(UScriptCode script, UChar *dest, int32_t capacity, UErrorCode *pErrorCode) {
if(U_FAILURE(*pErrorCode)) { return 0; }
if(capacity < 0 || (capacity > 0 && dest == NULL)) {
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
int32_t sampleChar = getScriptProps(script) & 0x1fffff;
int32_t length;
if(sampleChar == 0) {
length = 0;
} else {
length = U16_LENGTH(sampleChar);
if(length <= capacity) {
int32_t i = 0;
U16_APPEND_UNSAFE(dest, i, sampleChar);
}
}
return u_terminateUChars(dest, capacity, length, pErrorCode);
}
U_COMMON_API icu::UnicodeString U_EXPORT2
uscript_getSampleUnicodeString(UScriptCode script) {
icu::UnicodeString sample;
int32_t sampleChar = getScriptProps(script) & 0x1fffff;
if(sampleChar != 0) {
sample.append(sampleChar);
}
return sample;
}
U_CAPI UScriptUsage U_EXPORT2
uscript_getUsage(UScriptCode script) {
return (UScriptUsage)((getScriptProps(script) >> 21) & 7);
}
U_CAPI UBool U_EXPORT2
uscript_isRightToLeft(UScriptCode script) {
return (getScriptProps(script) & RTL) != 0;
}
U_CAPI UBool U_EXPORT2
uscript_breaksBetweenLetters(UScriptCode script) {
return (getScriptProps(script) & LB_LETTERS) != 0;
}
U_CAPI UBool U_EXPORT2
uscript_isCased(UScriptCode script) {
return (getScriptProps(script) & CASED) != 0;
}