static void TestBreakIteratorRuleError() { /* * TestBreakIteratorRuleError - Try to create a BI from rules with syntax errors, * check that the error is reported correctly. */ char rules[] = " # This is a rule comment on line 1\n" "[:L:]; # this rule is OK.\n" "abcdefg); # Error, mismatched parens\n"; UChar *uRules; void *freeHook = NULL; UErrorCode status = U_ZERO_ERROR; UParseError parseErr; UBreakIterator *bi; uRules = toUChar(rules, &freeHook); bi = ubrk_openRules(uRules, -1, /* The rules */ NULL, -1, /* The text to be iterated over. */ &parseErr, &status); if (U_SUCCESS(status)) { log_err("FAIL: construction of break iterator succeeded when it should have failed.\n"); ubrk_close(bi); } else { if (parseErr.line != 3 || parseErr.offset != 8) { log_data_err("FAIL: incorrect error position reported. Got line %d, char %d, expected line 3, char 7 (Are you missing data?)\n", parseErr.line, parseErr.offset); } } freeToUCharStrings(&freeHook); }
/* * TestBreakIteratorRules - Verify that a break iterator can be created from * a set of source rules. */ static void TestBreakIteratorRules() { /* Rules will keep together any run of letters not including 'a', OR * keep together 'abc', but only when followed by 'def', OTHERWISE * just return one char at a time. */ char rules[] = "abc{666}/def;\n [\\p{L} - [a]]* {2}; . {1};"; /* 0123456789012345678 */ char data[] = "abcdex abcdefgh-def"; /* the test data string */ char breaks[] = "** ** * ** *"; /* * the expected break positions */ char tags[] = "01 21 6 21 2"; /* expected tag values at break positions */ int32_t tagMap[] = {0, 1, 2, 3, 4, 5, 666}; UChar *uData; void *freeHook = NULL; UErrorCode status = U_ZERO_ERROR; int32_t pos; int i; UBreakIterator *bi = testOpenRules(rules); if (bi == NULL) {return;} uData = toUChar(data, &freeHook); ubrk_setText(bi, uData, -1, &status); pos = ubrk_first(bi); for (i=0; i<sizeof(breaks); i++) { if (pos == i && breaks[i] != '*') { log_err("FAIL: unexpected break at position %d found\n", pos); break; } if (pos != i && breaks[i] == '*') { log_err("FAIL: expected break at position %d not found.\n", i); break; } if (pos == i) { int32_t tag, expectedTag; tag = ubrk_getRuleStatus(bi); expectedTag = tagMap[tags[i]&0xf]; if (tag != expectedTag) { log_err("FAIL: incorrect tag value. Position = %d; expected tag %d, got %d", pos, expectedTag, tag); break; } pos = ubrk_next(bi); } } freeToUCharStrings(&freeHook); ubrk_close(bi); }
/* // Open a break iterator from char * rules. Take care of conversion // of the rules and error checking. */ static UBreakIterator * testOpenRules(char *rules) { UErrorCode status = U_ZERO_ERROR; UChar *ruleSourceU = NULL; void *strCleanUp = NULL; UParseError parseErr; UBreakIterator *bi; ruleSourceU = toUChar(rules, &strCleanUp); bi = ubrk_openRules(ruleSourceU, -1, /* The rules */ NULL, -1, /* The text to be iterated over. */ &parseErr, &status); if (U_FAILURE(status)) { log_data_err("FAIL: ubrk_openRules: ICU Error \"%s\" (Are you missing data?)\n", u_errorName(status)); bi = 0; }; freeToUCharStrings(&strCleanUp); return bi; }
void ColourValue::writeRGB (unsigned char *& buffer) { *buffer++ = toUChar (r); *buffer++ = toUChar (g); *buffer++ = toUChar (b); }
static inline UChar min8S ( Char xx, Char yy ) { return toUChar((xx < yy) ? xx : yy); }
static inline UChar max8S ( Char xx, Char yy ) { return toUChar((xx > yy) ? xx : yy); }