Exemplo n.º 1
0
void rbControlInputMidiParserInitialize(RBControlInputMidiParser * pParser,
    RBConfiguration const * pConfig)
{
    pParser->state = RBCIMPS_CLEAR;
    for(size_t i = 0; i < LENGTHOF(pParser->controls.controllers); ++i) {
        pParser->controls.controllers[i] = 0.0f;
    }
    for(size_t i = 0; i < LENGTHOF(pParser->controls.triggers); ++i) {
        pParser->controls.triggers[i] = false;
    }
    // Brightness control defaults to full on -- hax
    pParser->controls.controllers[0] = 1.0f;
    pParser->controls.debugDisplayReset = true;
    pParser->controls.debugDisplayMode =
        ((pConfig->mode < 0) || (pConfig->mode >= RBDM_COUNT)) ? 0 :
            pConfig->mode;
}
Exemplo n.º 2
0
void MeasureUnit::initTime(const char *timeId) {
    int32_t result = binarySearch(gTypes, 0, LENGTHOF(gTypes)-1, "duration"); // Apple mod
    U_ASSERT(result != -1);
    fTypeId = result;
    result = binarySearch(gSubTypes, gOffsets[fTypeId], gOffsets[fTypeId + 1], timeId);
    U_ASSERT(result != -1);
    fSubTypeId = result - gOffsets[fTypeId]; 
}
Exemplo n.º 3
0
UPerfFunction* ConverterPerformanceTest::TestWinANSI_UTF8_FromUnicode(){
    UErrorCode status = U_ZERO_ERROR;
    UPerfFunction* pf = new WinANSIFromUnicodePerfFunction("utf-8",utf8_uniSource, LENGTHOF(utf8_uniSource), status);
    if(U_FAILURE(status)){
        return NULL;
    }
    return pf;
}
Exemplo n.º 4
0
UPerfFunction*  ConverterPerformanceTest::TestICU_UTF8_ToUnicode(){
    UErrorCode status = U_ZERO_ERROR;
    UPerfFunction* pf = new ICUToUnicodePerfFunction("utf-8",(char*)utf8_encSource, LENGTHOF(utf8_encSource), status);
    if(U_FAILURE(status)){
        return NULL;
    }
    return pf;
}
QuantityFormatter::QuantityFormatter(const QuantityFormatter &other) {
    for (int32_t i = 0; i < LENGTHOF(formatters); ++i) {
        if (other.formatters[i] == NULL) {
            formatters[i] = NULL;
        } else {
            formatters[i] = new SimplePatternFormatter(*other.formatters[i]);
        }
    }
}
static int32_t getPluralIndex(const char *pluralForm) {
    int32_t len = LENGTHOF(gPluralForms);
    for (int32_t i = 0; i < len; ++i) {
        if (uprv_strcmp(pluralForm, gPluralForms[i]) == 0) {
            return i;
        }
    }
    return -1;
}
Exemplo n.º 7
0
void TestBinaryValues() {
    /*
     * Unicode 5.1 explicitly defines binary property value aliases.
     * Verify that they are all recognized.
     */
    static const char *const falseValues[]={ "N", "No", "F", "False" };
    static const char *const trueValues[]={ "Y", "Yes", "T", "True" };
    int32_t i;
    for(i=0; i<LENGTHOF(falseValues); ++i) {
        if(FALSE!=u_getPropertyValueEnum(UCHAR_ALPHABETIC, falseValues[i])) {
            log_data_err("u_getPropertyValueEnum(UCHAR_ALPHABETIC, \"%s\")!=FALSE (Are you missing data?)\n", falseValues[i]);
        }
    }
    for(i=0; i<LENGTHOF(trueValues); ++i) {
        if(TRUE!=u_getPropertyValueEnum(UCHAR_ALPHABETIC, trueValues[i])) {
            log_data_err("u_getPropertyValueEnum(UCHAR_ALPHABETIC, \"%s\")!=TRUE (Are you missing data?)\n", trueValues[i]);
        }
    }
}
Exemplo n.º 8
0
void UnicodeTest::TestBinaryValues() {
    /*
     * Unicode 5.1 explicitly defines binary property value aliases.
     * Verify that they are all recognized.
     */
    UErrorCode errorCode=U_ZERO_ERROR;
    UnicodeSet alpha(UNICODE_STRING_SIMPLE("[:Alphabetic:]"), errorCode);
    if(U_FAILURE(errorCode)) {
        dataerrln("UnicodeSet([:Alphabetic:]) failed - %s", u_errorName(errorCode));
        return;
    }

    static const char *const falseValues[]={ "N", "No", "F", "False" };
    static const char *const trueValues[]={ "Y", "Yes", "T", "True" };
    int32_t i;
    for(i=0; i<LENGTHOF(falseValues); ++i) {
        UnicodeString pattern=UNICODE_STRING_SIMPLE("[:Alphabetic=:]");
        pattern.insert(pattern.length()-2, UnicodeString(falseValues[i], -1, US_INV));
        errorCode=U_ZERO_ERROR;
        UnicodeSet set(pattern, errorCode);
        if(U_FAILURE(errorCode)) {
            errln("UnicodeSet([:Alphabetic=%s:]) failed - %s\n", falseValues[i], u_errorName(errorCode));
            continue;
        }
        set.complement();
        if(set!=alpha) {
            errln("UnicodeSet([:Alphabetic=%s:]).complement()!=UnicodeSet([:Alphabetic:])\n", falseValues[i]);
        }
    }
    for(i=0; i<LENGTHOF(trueValues); ++i) {
        UnicodeString pattern=UNICODE_STRING_SIMPLE("[:Alphabetic=:]");
        pattern.insert(pattern.length()-2, UnicodeString(trueValues[i], -1, US_INV));
        errorCode=U_ZERO_ERROR;
        UnicodeSet set(pattern, errorCode);
        if(U_FAILURE(errorCode)) {
            errln("UnicodeSet([:Alphabetic=%s:]) failed - %s\n", trueValues[i], u_errorName(errorCode));
            continue;
        }
        if(set!=alpha) {
            errln("UnicodeSet([:Alphabetic=%s:])!=UnicodeSet([:Alphabetic:])\n", trueValues[i]);
        }
    }
}
Exemplo n.º 9
0
static struct binary_info *binary_find(const char *name) {
	struct binary_info *binary;
	const char *current_name;
	unsigned i;
	char path[PATH_MAX + 1], *path_end;

	assert(name);

	/* name is required */
	if (!*name) {
		fprintf(stderr, "warning: binary unspecified in sample\n");
		return NULL;
	}

	/* do we already know this binary? */
	binary = binary_hashtab_get(name);
	if (binary) return binary;

	/* search for it */
	dprintf("searching for binary \"%.*s\" in \"%s\"\n",
		PROC_NAME_LEN, name, src_path);
	for (i = 0; i < LENGTHOF(default_binaries); i++) {
		snprintf(path, sizeof(path), "%s/%s", src_path,
			default_binaries[i]);
		current_name = binary_name(path);
		assert(current_name);
		if (*current_name) {
			/* paths not ending in slash: use if name matches */
			if (strncmp(name, current_name,
				PROC_NAME_LEN) != 0) {
				continue;
			}
		} else {
			/* paths ending in slash: look in subdir named after
			 * binary
			 */
			path_end = path + strlen(path);
			snprintf(path_end, sizeof(path) - (path_end - path),
				"%.*s/%.*s", PROC_NAME_LEN, name,
				PROC_NAME_LEN, name);
		}

		/* use access to find out whether the binary exists and is
		 * readable
		 */
		dprintf("checking whether \"%s\" exists\n", path);
		if (access(path, R_OK) < 0) continue;

		/* ok, this seems to be the one */
		return binary_add(strdup_checked(path));
	}

	/* not found */
	return NULL;
}
Exemplo n.º 10
0
static void
parseDB(const char *filename, UErrorCode *pErrorCode) {
    /* default Bidi classes for unassigned code points */
    static const UChar32 defaultBidi[][3]={ /* { start, end, class } */
        /* R: U+0590..U+05FF, U+07C0..U+08FF, U+FB1D..U+FB4F, U+10800..U+10FFF */
        { 0x0590, 0x05FF, U_RIGHT_TO_LEFT },
        { 0x07C0, 0x08FF, U_RIGHT_TO_LEFT },
        { 0xFB1D, 0xFB4F, U_RIGHT_TO_LEFT },
        { 0x10800, 0x10FFF, U_RIGHT_TO_LEFT },

        /* AL: U+0600..U+07BF, U+FB50..U+FDCF, U+FDF0..U+FDFF, U+FE70..U+FEFE */
        { 0x0600, 0x07BF, U_RIGHT_TO_LEFT_ARABIC },
        { 0xFB50, 0xFDCF, U_RIGHT_TO_LEFT_ARABIC },
        { 0xFDF0, 0xFDFF, U_RIGHT_TO_LEFT_ARABIC },
        { 0xFE70, 0xFEFE, U_RIGHT_TO_LEFT_ARABIC }

        /* L otherwise */
    };

    char *fields[15][2];
    UChar32 start, end;
    int32_t i;

    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
        return;
    }

    /*
     * Set default Bidi classes for unassigned code points.
     * See the documentation for Bidi_Class in UCD.html in the Unicode data.
     * http://www.unicode.org/Public/
     *
     * Starting with Unicode 5.0, DerivedBidiClass.txt should (re)set
     * the Bidi_Class values for all code points including unassigned ones
     * and including L values for these.
     * This code becomes unnecesary but harmless. Leave it for now in case
     * someone uses genbidi on pre-Unicode 5.0 data.
     */
    for(i=0; i<LENGTHOF(defaultBidi); ++i) {
        start=defaultBidi[i][0];
        end=defaultBidi[i][1];
        upvec_setValue(pv, start, end, 0, (uint32_t)defaultBidi[i][2], UBIDI_CLASS_MASK, pErrorCode);
        if(U_FAILURE(*pErrorCode)) {
            fprintf(stderr, "genbidi error: unable to set default bidi class for U+%04lx..U+%04lx, code: %s\n",
                            (long)start, (long)end, u_errorName(*pErrorCode));
            exit(*pErrorCode);
        }
    }

    u_parseDelimitedFile(filename, ';', fields, 15, unicodeDataLineFn, NULL, pErrorCode);

    if(U_FAILURE(*pErrorCode)) {
        return;
    }
}
Exemplo n.º 11
0
static void TestSetCharUnsafe() {
    static const uint8_t input[]
        = {0x61, 0xe4, 0xba, 0x8c, 0x7f, 0x2e, 0x62, 0xc5, 0x7f, 0x61, 0x80, 0x80, 0xe0, 0x80, 0x80, 0x00 };
    static const int16_t start_unsafe[]
        = {0,    1,    1,    1,    4,    5,    6,    7,    8,    9,    9,    9,    12,   12,   12,   15 };
    static const int16_t limit_unsafe[]
        = {0,    1,    4,    4,    4,    5,    6,    7,    9,    9,    10,   10,   10,   15,   15,   15,   16 };

    uint32_t i=0;
    int32_t offset=0, setOffset=0;
    for(offset=0; offset<=LENGTHOF(input); offset++){
        if (offset<LENGTHOF(input)){
            setOffset=offset;
            UTF8_SET_CHAR_START_UNSAFE(input, setOffset);
            if(setOffset != start_unsafe[i]){
                log_err("ERROR: UTF8_SET_CHAR_START_UNSAFE failed for offset=%ld. Expected:%ld Got:%ld\n", offset, start_unsafe[i], setOffset);
            }

            setOffset=offset;
            U8_SET_CP_START_UNSAFE(input, setOffset);
            if(setOffset != start_unsafe[i]){
                log_err("ERROR: U8_SET_CP_START_UNSAFE failed for offset=%ld. Expected:%ld Got:%ld\n", offset, start_unsafe[i], setOffset);
            }
        }

        if (offset != 0) { /* Can't have it go off the end of the array */
            setOffset=offset;
            UTF8_SET_CHAR_LIMIT_UNSAFE(input, setOffset);
            if(setOffset != limit_unsafe[i]){
                log_err("ERROR: UTF8_SET_CHAR_LIMIT_UNSAFE failed for offset=%ld. Expected:%ld Got:%ld\n", offset, limit_unsafe[i], setOffset);
            }

            setOffset=offset;
            U8_SET_CP_LIMIT_UNSAFE(input, setOffset);
            if(setOffset != limit_unsafe[i]){
                log_err("ERROR: U8_SET_CP_LIMIT_UNSAFE failed for offset=%ld. Expected:%ld Got:%ld\n", offset, limit_unsafe[i], setOffset);
            }
        }

        i++;
    }
}
Exemplo n.º 12
0
void CMfmLog::Log(int nLevel, CPort* pPort, LPCWSTR szFormat, ...)
{
	if (m_hLogFile != INVALID_HANDLE_VALUE &&
		m_nLogLevel >= nLevel)
	{
		WCHAR szBuf1[MAXLOGLINE];
		WCHAR szBuf2[MAXLOGLINE];
		va_list args;

		va_start(args, szFormat);

		vswprintf_s(szBuf1, LENGTHOF(szBuf1), szFormat, args);

		va_end(args);

		swprintf_s(szBuf2, LENGTHOF(szBuf2), L"%s: %s", pPort->PortName(), szBuf1);

		Log(nLevel, szBuf2);
	}
}
Exemplo n.º 13
0
static void U_CALLCONV
nameAliasesLineFn(void *context,
       char *fields[][2], int32_t fieldCount,
       UErrorCode *pErrorCode) {
    char *name;
    int16_t length=0;
    static uint32_t prevCode=0;
    uint32_t code=0;

    if(U_FAILURE(*pErrorCode)) {
        return;
    }
    /* get the character code */
    code=uprv_strtoul(fields[0][0], NULL, 16);

    /* get the character name */
    name=fields[1][0];
    length=getName(&name, fields[1][1]);
    if(length==0 || length>=sizeof(cpNameAliases[cpNameAliasesTop].nameAlias)) {
        fprintf(stderr, "gennames: error - name alias %s empty or too long for code point U+%04lx\n",
                name, (unsigned long)code);
        *pErrorCode=U_PARSE_ERROR;
        exit(U_PARSE_ERROR);
    }

    /* check for non-character code points */
    if(!U_IS_UNICODE_CHAR(code)) {
        fprintf(stderr, "gennames: error - name alias for non-character code point U+%04lx\n",
                (unsigned long)code);
        *pErrorCode=U_PARSE_ERROR;
        exit(U_PARSE_ERROR);
    }

    /* check that the code points (code) are in ascending order */
    if(code<=prevCode && code>0) {
        fprintf(stderr, "gennames: error - NameAliases entries out of order, U+%04lx after U+%04lx\n",
                (unsigned long)code, (unsigned long)prevCode);
        *pErrorCode=U_PARSE_ERROR;
        exit(U_PARSE_ERROR);
    }
    prevCode=code;

    if(cpNameAliasesTop>=LENGTHOF(cpNameAliases)) {
        fprintf(stderr, "gennames: error - too many name aliases\n");
        *pErrorCode=U_PARSE_ERROR;
        exit(U_PARSE_ERROR);
    }
    cpNameAliases[cpNameAliasesTop].code=code;
    uprv_memcpy(cpNameAliases[cpNameAliasesTop].nameAlias, name, length);
    cpNameAliases[cpNameAliasesTop].nameAlias[length]=0;
    ++cpNameAliasesTop;

    parseName(name, length);
}
Exemplo n.º 14
0
NormalizerPerformanceTest::NormalizerPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status)
: UPerfTest(argc,argv,status), options(0) {
    NFDBuffer = NULL;
    NFCBuffer = NULL;
    NFDBufferLen = 0;
    NFCBufferLen = 0;
    NFDFileLines = NULL;
    NFCFileLines = NULL;

    if(status== U_ILLEGAL_ARGUMENT_ERROR){
       fprintf(stderr,gUsageString, "normperf");
       return;
    }

    if(U_FAILURE(status)){
        fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status));
        return;
    }

    _remainingArgc = u_parseArgs(_remainingArgc, (char **)argv, (int32_t)(LENGTHOF(cmdLineOptions)), cmdLineOptions);
    if(cmdLineOptions[0].doesOccur && cmdLineOptions[0].value!=NULL) {
        options=(int32_t)strtol(cmdLineOptions[0].value, NULL, 16);
    }

    if(line_mode){
        ULine* filelines = getLines(status);
        if(U_FAILURE(status)){
            fprintf(stderr, "FAILED to read lines from file and create UPerfTest object. Error: %s\n", u_errorName(status));
            return;
        }
        NFDFileLines = new ULine[numLines];
        NFCFileLines = new ULine[numLines];
    
        for(int32_t i=0;i<numLines;i++){
            normalizeInput(&NFDFileLines[i],filelines[i].name,filelines[i].len,UNORM_NFD, options);
            normalizeInput(&NFCFileLines[i],filelines[i].name,filelines[i].len,UNORM_NFC, options);

        }
    }else if(bulk_mode){
        int32_t srcLen = 0;
        const UChar* src = getBuffer(srcLen,status);
        NFDBufferLen = 0;
        NFCBufferLen = 0;

        if(U_FAILURE(status)){
            fprintf(stderr, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status));
            return;
        }
         
        NFDBuffer = normalizeInput(NFDBufferLen,src,srcLen,UNORM_NFD, options);
        NFCBuffer = normalizeInput(NFCBufferLen,src,srcLen,UNORM_NFC, options);
    }
    
}
Exemplo n.º 15
0
static void TestSetChar() {
    static const uint8_t input[]
        = {0x61, 0xe4, 0xba, 0x8c, 0x7f, 0xfe, 0x62, 0xc5, 0x7f, 0x61, 0x80, 0x80, 0xe0, 0x00 };
    static const int16_t start_safe[]
        = {0,    1,    1,    1,    4,    5,    6,    7,    8,    9,    10,   11,   12,   13,  14 };
    static const int16_t limit_safe[]
        = {0,    1,    4,    4,    4,    5,    6,    7,    8,    9,    10,   11,   12,   13,  14 };

    uint32_t i=0;
    int32_t offset=0, setOffset=0;
    for(offset=0; offset<=LENGTHOF(input); offset++){
        if (offset<LENGTHOF(input)){
            setOffset=offset;
            UTF8_SET_CHAR_START_SAFE(input, 0, setOffset);
            if(setOffset != start_safe[i]){
                log_err("ERROR: UTF8_SET_CHAR_START_SAFE failed for offset=%ld. Expected:%ld Got:%ld\n", offset, start_safe[i], setOffset);
            }

            setOffset=offset;
            U8_SET_CP_START(input, 0, setOffset);
            if(setOffset != start_safe[i]){
                log_err("ERROR: U8_SET_CP_START failed for offset=%ld. Expected:%ld Got:%ld\n", offset, start_safe[i], setOffset);
            }
        }

        setOffset=offset;
        UTF8_SET_CHAR_LIMIT_SAFE(input,0, setOffset, sizeof(input));
        if(setOffset != limit_safe[i]){
            log_err("ERROR: UTF8_SET_CHAR_LIMIT_SAFE failed for offset=%ld. Expected:%ld Got:%ld\n", offset, limit_safe[i], setOffset);
        }

        setOffset=offset;
        U8_SET_CP_LIMIT(input,0, setOffset, sizeof(input));
        if(setOffset != limit_safe[i]){
            log_err("ERROR: U8_SET_CP_LIMIT failed for offset=%ld. Expected:%ld Got:%ld\n", offset, limit_safe[i], setOffset);
        }

        i++;
    }
}
Exemplo n.º 16
0
int32_t ScriptSet::countMembers() const {
    // This bit counter is good for sparse numbers of '1's, which is
    //  very much the case that we will usually have.
    int32_t count = 0;
    for (uint32_t i=0; i<LENGTHOF(bits); i++) {
        uint32_t x = bits[i];
        while (x > 0) {
            count++;
            x &= (x - 1);    // and off the least significant one bit.
        }
    }
    return count;
}
void UCharsTrieTest::TestValuesForState() {
    // Check that saveState() and resetToState() interact properly
    // with next() and current().
    static const StringAndValue data[]={
        { "a", -1 },
        { "ab", -2 },
        { "abc", -3 },
        { "abcd", -4 },
        { "abcde", -5 },
        { "abcdef", -6 }
    };
    checkData(data, LENGTHOF(data));
}
Exemplo n.º 18
0
int32_t MeasureUnit::getAvailable(
        MeasureUnit *dest,
        int32_t destCapacity,
        UErrorCode &errorCode) {
    if (U_FAILURE(errorCode)) {
        return 0;
    }
    if (destCapacity < LENGTHOF(gSubTypes)) {
        errorCode = U_BUFFER_OVERFLOW_ERROR;
        return LENGTHOF(gSubTypes);
    }
    int32_t idx = 0;
    for (int32_t typeIdx = 0; typeIdx < LENGTHOF(gTypes); ++typeIdx) {
        int32_t len = gOffsets[typeIdx + 1] - gOffsets[typeIdx];
        for (int32_t subTypeIdx = 0; subTypeIdx < len; ++subTypeIdx) {
            dest[idx].setTo(typeIdx, subTypeIdx);
            ++idx;
        }
    }
    U_ASSERT(idx == LENGTHOF(gSubTypes));
    return LENGTHOF(gSubTypes);
}
UnicodeString& SimplePatternFormatter::format(
        const UnicodeString &arg0,
        UnicodeString &appendTo,
        UErrorCode &status) const {
    const UnicodeString *params[] = {&arg0};
    return format(
            params,
            LENGTHOF(params),
            appendTo,
            NULL,
            0,
            status);
}
Exemplo n.º 20
0
UnicodeTest::UnicodeTest()
{
    UErrorCode errorCode=U_ZERO_ERROR;
    unknownPropertyNames=new U_NAMESPACE_QUALIFIER Hashtable(errorCode);
    if(U_FAILURE(errorCode)) {
        delete unknownPropertyNames;
        unknownPropertyNames=NULL;
    }
    // Ignore some property names altogether.
    for(int32_t i=0; i<LENGTHOF(ignorePropNames); ++i) {
        unknownPropertyNames->puti(UnicodeString(ignorePropNames[i], -1, US_INV), 1, errorCode);
    }
}
void AlphabeticIndexTest::TestChineseZhuyin() {
    UErrorCode status = U_ZERO_ERROR;
    char loc[100];
    uloc_forLanguageTag("zh-u-co-zhuyin", loc, LENGTHOF(loc), NULL, &status);
    AlphabeticIndex index(loc, status);
    LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status));
    TEST_CHECK_STATUS; 
    assertEquals("getBucketCount()", 38, immIndex->getBucketCount());
    assertEquals("label 1", UnicodeString((UChar)0x3105), immIndex->getBucket(1)->getLabel());
    assertEquals("label 2", UnicodeString((UChar)0x3106), immIndex->getBucket(2)->getLabel());
    assertEquals("label 3", UnicodeString((UChar)0x3107), immIndex->getBucket(3)->getLabel());
    assertEquals("label 4", UnicodeString((UChar)0x3108), immIndex->getBucket(4)->getLabel());
    assertEquals("label 5", UnicodeString((UChar)0x3109), immIndex->getBucket(5)->getLabel());
}
Exemplo n.º 22
0
U_NAMESPACE_BEGIN

#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))

//----------------------------------------------------------------------------
//
//  ScriptSet implementation
//
//----------------------------------------------------------------------------
ScriptSet::ScriptSet() {
    for (uint32_t i=0; i<LENGTHOF(bits); i++) {
        bits[i] = 0;
    }
}
void UCharsTrieTest::TestFirstForCodePoint() {
    static const StringAndValue data[]={
        { "a", 1 },
        { "a\\ud800", 2 },
        { "a\\U00010000", 3 },
        { "\\ud840", 4 },
        { "\\U00020000\\udbff", 5 },
        { "\\U00020000\\U0010ffff", 6 },
        { "\\U00020000\\U0010ffffz", 7 },
        { "\\U00050000xy", 8 },
        { "\\U00050000xyz", 9 }
    };
    checkData(data, LENGTHOF(data));
}
void UCharsTrieTest::TestLongSequence() {
    static const StringAndValue data[]={
        { "a", -1 },
        // sequence of linear-match nodes
        { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -2 },
        // more than 256 units
        { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -3 }
    };
    checkData(data, LENGTHOF(data));
}
Exemplo n.º 25
0
StringEnumeration* MeasureUnit::getAvailableTypes(UErrorCode &errorCode) {
    UEnumeration *uenum = uenum_openCharStringsEnumeration(
            gTypes, LENGTHOF(gTypes), &errorCode);
    if (U_FAILURE(errorCode)) {
        uenum_close(uenum);
        return NULL;
    }
    StringEnumeration *result = new UStringEnumeration(uenum);
    if (result == NULL) {
        errorCode = U_MEMORY_ALLOCATION_ERROR;
        uenum_close(uenum);
        return NULL;
    }
    return result;
}
// populatePrefixSuffix Adds a specific prefix-suffix pair to result for a
// given variant and log10 value.
// variant is 'zero', 'one', 'two', 'few', 'many', or 'other'.
// formatStr is the format string from which the prefix and suffix are
// extracted. It is usually of form 'Pefix 000 suffix'.
// populatePrefixSuffix returns the number of 0's found in formatStr
// before the decimal point.
// In the special case that formatStr contains only spaces for prefix
// and suffix, populatePrefixSuffix returns log10Value + 1.
static int32_t populatePrefixSuffix(
    const char* variant, int32_t log10Value, const UnicodeString& formatStr, UHashtable* result, UErrorCode& status) {
  if (U_FAILURE(status)) {
    return 0;
  }
  int32_t firstIdx = formatStr.indexOf(kZero, LENGTHOF(kZero), 0);
  // We must have 0's in format string.
  if (firstIdx == -1) {
    status = U_INTERNAL_PROGRAM_ERROR;
    return 0;
  }
  int32_t lastIdx = formatStr.lastIndexOf(kZero, LENGTHOF(kZero), firstIdx);
  CDFUnit* unit = createCDFUnit(variant, log10Value, result, status);
  if (U_FAILURE(status)) {
    return 0;
  }
  // Everything up to first 0 is the prefix
  unit->prefix = formatStr.tempSubString(0, firstIdx);
  fixGraves(unit->prefix);
  // Everything beyond the last 0 is the suffix
  unit->suffix = formatStr.tempSubString(lastIdx + 1);
  fixGraves(unit->suffix);

  // If there is effectively no prefix or suffix, ignore the actual number of
  // 0's and act as if the number of 0's matches the size of the number.
  if (onlySpaces(unit->prefix) && onlySpaces(unit->suffix)) {
    return log10Value + 1;
  }

  // Calculate number of zeros before decimal point
  int32_t idx = firstIdx + 1;
  while (idx <= lastIdx && formatStr.charAt(idx) == u_0) {
    ++idx;
  }
  return (idx - firstIdx);
}
Exemplo n.º 27
0
static void TestUnicode32Norm() {
    /*
     * test Unicode 3.2 normalization, before Public Review Issue #29
     * see cnormtst.c TestComposition()
     */
    static const UChar strings[][8]={
        { 0x1100, 0x0300, 0x1161, 0x0327 },
        { 0x0b47, 0x0300, 0x0b3e, 0x0327 }
    };

    UChar ascii[20], unicode[20];
    int32_t i, length;
    UErrorCode errorCode;

    for(i=0; i<LENGTHOF(strings); ++i) {
        errorCode=U_ZERO_ERROR;
        length=uidna_toASCII(strings[i], -1, ascii, LENGTHOF(ascii), 0, NULL, &errorCode);
        length=uidna_toUnicode(ascii, length, unicode, LENGTHOF(unicode), 0, NULL, &errorCode);
        if(errorCode!=U_IDNA_VERIFICATION_ERROR) {
            log_err("string %d yields %s instead of U_IDNA_VERIFICATION_ERROR\n",
                i, u_errorName(errorCode));
        }
    }
}
QuantityFormatter &QuantityFormatter::operator=(
        const QuantityFormatter& other) {
    if (this == &other) {
        return *this;
    }
    for (int32_t i = 0; i < LENGTHOF(formatters); ++i) {
        delete formatters[i];
        if (other.formatters[i] == NULL) {
            formatters[i] = NULL;
        } else {
            formatters[i] = new SimplePatternFormatter(*other.formatters[i]);
        }
    }
    return *this;
}
void AlphabeticIndexTest::TestJapaneseKanji() {
    UErrorCode status = U_ZERO_ERROR;
    AlphabeticIndex index(Locale::getJapanese(), status);
    LocalPointer<AlphabeticIndex::ImmutableIndex> immIndex(index.buildImmutableIndex(status));
    TEST_CHECK_STATUS;
    // There are no index characters for Kanji in the Japanese standard collator.
    // They should all go into the overflow bucket.
    static const UChar32 kanji[] = { 0x4E9C, 0x95C7, 0x4E00, 0x58F1 };
    int32_t overflowIndex = immIndex->getBucketCount() - 1;
    for(int32_t i = 0; i < LENGTHOF(kanji); ++i) {
        char msg[40];
        sprintf(msg, "kanji[%d]=U+%04lX in overflow bucket", (int)i, (long)kanji[i]);
        assertEquals(msg, overflowIndex, immIndex->getBucketIndex(UnicodeString(kanji[i]), status));
        TEST_CHECK_STATUS;
    }
}
Exemplo n.º 30
0
void HandViewer::DisplayDistanceFromSensor()
{
	std::stringstream ss;
	unsigned counter = 1;

	const PointListHandler& handler = handTracker.GetPointListHandler();

	for(PointListHandler::ConstIterator it = handler.begin(); it != handler.end(); ++it)
	{
		const PointList &pointList = it.GetPointList();
		XnPoint3D lastPoint = pointList.GetLastPoint();
		
		std::string str = "Hand ";
		ss << counter;
		str = str + ss.str();
		ss.str("");
		
		ss << " distance from the sensor: ";
		str = str + ss.str();
		ss.str("");
		
		if(lastPoint.Z < HAND_CLOSE)
		{
			ss << 0;
			device.SetLedColour(LED_GREEN);
		}
		else
		{
			ss << lastPoint.Z - HAND_CLOSE;
			device.SetLedColour(LED_ORANGE);	
		}
		str = str + ss.str();
		ss.str("");
	
		XnUInt32 nColor = it.GetKey() % LENGTHOF(COLOURS);
		glColor4f(COLOURS[nColor][0], COLOURS[nColor][1], COLOURS[nColor][2], 1.0f);
		glRasterPos2f(40, counter*30);
		for(int i=0;i<str.length();i++)
		{
			glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,str[i]);
		}
		
		counter++;
	}
	

}