void RBBIAPITest::doTest(UnicodeString& testString, int32_t start, int32_t gotoffset, int32_t expectedOffset, const char* expectedString){ UnicodeString selected; UnicodeString expected=CharsToUnicodeString(expectedString); if(gotoffset != expectedOffset) errln((UnicodeString)"ERROR:****returned #" + gotoffset + (UnicodeString)" instead of #" + expectedOffset); if(start <= gotoffset){ testString.extractBetween(start, gotoffset, selected); } else{ testString.extractBetween(gotoffset, start, selected); } if(selected.compare(expected) != 0) errln(prettify((UnicodeString)"ERROR:****selected \"" + selected + "\" instead of \"" + expected + "\"")); else logln(prettify("****selected \"" + selected + "\"")); }
/** * Parse an ID into pieces. Take IDs of the form T, T/V, S-T, * S-T/V, or S/V-T. If the source is missing, return a source of * ANY. * @param id the id string, in any of several forms * @return an array of 4 strings: source, target, variant, and * isSourcePresent. If the source is not present, ANY will be * given as the source, and isSourcePresent will be NULL. Otherwise * isSourcePresent will be non-NULL. The target may be empty if the * id is not well-formed. The variant may be empty. */ void TransliteratorIDParser::IDtoSTV(const UnicodeString & id, UnicodeString & source, UnicodeString & target, UnicodeString & variant, UBool & isSourcePresent) { source = ANY; target.truncate(0); variant.truncate(0); int32_t sep = id.indexOf(TARGET_SEP); int32_t var = id.indexOf(VARIANT_SEP); if (var < 0) { var = id.length(); } isSourcePresent = FALSE; if (sep < 0) { // Form: T/V or T (or /V) id.extractBetween(0, var, target); id.extractBetween(var, id.length(), variant); } else if (sep < var) { // Form: S-T/V or S-T (or -T/V or -T) if (sep > 0) { id.extractBetween(0, sep, source); isSourcePresent = TRUE; } id.extractBetween(++sep, var, target); id.extractBetween(var, id.length(), variant); } else { // Form: (S/V-T or /V-T) if (var > 0) { id.extractBetween(0, var, source); isSourcePresent = TRUE; } id.extractBetween(var, sep++, variant); id.extractBetween(sep, id.length(), target); } if (variant.length() > 0) { variant.remove(0, 1); } }
StringMatcher::StringMatcher(const UnicodeString& theString, int32_t start, int32_t limit, int32_t segmentNum, const TransliterationRuleData& theData) : data(&theData), segmentNumber(segmentNum), matchStart(-1), matchLimit(-1) { theString.extractBetween(start, limit, pattern); }
void TransliteratorAPITest::displayOutput(const UnicodeString& got, const UnicodeString& expected, UnicodeString& log, UTransPosition& index){ // Show the start index '{' and the cursor '|' UnicodeString a, b, c, d, e; got.extractBetween(0, index.contextStart, a); got.extractBetween(index.contextStart, index.start, b); got.extractBetween(index.start, index.limit, c); got.extractBetween(index.limit, index.contextLimit, d); got.extractBetween(index.contextLimit, got.length(), e); log.append(a). append((UChar)0x7b/*{*/). append(b). append((UChar)0x7c/*|*/). append(c). append((UChar)0x7c). append(d). append((UChar)0x7d/*}*/). append(e); if (got == expected) logln("OK:" + prettify(log)); else errln("FAIL: " + prettify(log) + ", expected " + prettify(expected)); }
// // RBBISymbolTable::parseReference This function from the abstract symbol table interface // looks for a $variable name in the source text. // It does not look it up, only scans for it. // It is used by the UnicodeSet parser. // // This implementation is lifted pretty much verbatim // from the rules based transliterator implementation. // I didn't see an obvious way of sharing it. // UnicodeString RBBISymbolTable::parseReference(const UnicodeString& text, ParsePosition& pos, int32_t limit) const { int32_t start = pos.getIndex(); int32_t i = start; UnicodeString result; while (i < limit) { UChar c = text.charAt(i); if ((i==start && !u_isIDStart(c)) || !u_isIDPart(c)) { break; } ++i; } if (i == start) { // No valid name chars return result; // Indicate failure with empty string } pos.setIndex(i); text.extractBetween(start, i, result); return result; }
void extractBetween(int32_t start, int32_t limit, UnicodeString& result) const { chars.extractBetween(start, limit, result); }
/** * @bug 4052408 */ void DateFormatRegressionTest::Test4052408(void) { DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::SHORT, DateFormat::SHORT, Locale::getUS()); if (fmt == NULL) { dataerrln("Error calling DateFormat::createDateTimeInstance"); return; } UDate dt = date(97, UCAL_MAY, 3, 8, 55); UnicodeString str; str = fmt->format(dt, str); logln(str); if(str != "5/3/97 8:55 AM") errln("Fail: Test broken; Want 5/3/97 8:55 AM Got " + str); UnicodeString expected[] = { (UnicodeString) "", //"ERA_FIELD", (UnicodeString) "97", //"YEAR_FIELD", (UnicodeString) "5", //"MONTH_FIELD", (UnicodeString) "3", //"DATE_FIELD", (UnicodeString) "", //"HOUR_OF_DAY1_FIELD", (UnicodeString) "", //"HOUR_OF_DAY0_FIELD", (UnicodeString) "55", //"MINUTE_FIELD", (UnicodeString) "", //"SECOND_FIELD", (UnicodeString) "", //"MILLISECOND_FIELD", (UnicodeString) "", //"DAY_OF_WEEK_FIELD", (UnicodeString) "", //"DAY_OF_YEAR_FIELD", (UnicodeString) "", //"DAY_OF_WEEK_IN_MONTH_FIELD", (UnicodeString) "", //"WEEK_OF_YEAR_FIELD", (UnicodeString) "", //"WEEK_OF_MONTH_FIELD", (UnicodeString) "AM", //"AM_PM_FIELD", (UnicodeString) "8", //"HOUR1_FIELD", (UnicodeString) "", //"HOUR0_FIELD", (UnicodeString) "" //"TIMEZONE_FIELD" }; //Hashtable expected;// = new Hashtable(); //expected.put(new LongKey(DateFormat.MONTH_FIELD), "5"); //expected.put(new LongKey(DateFormat.DATE_FIELD), "3"); //expected.put(new LongKey(DateFormat.YEAR_FIELD), "97"); //expected.put(new LongKey(DateFormat.HOUR1_FIELD), "8"); //expected.put(new LongKey(DateFormat.MINUTE_FIELD), "55"); //expected.put(new LongKey(DateFormat.AM_PM_FIELD), "AM"); //StringBuffer buf = new StringBuffer(); UnicodeString fieldNames[] = { (UnicodeString) "ERA_FIELD", (UnicodeString) "YEAR_FIELD", (UnicodeString) "MONTH_FIELD", (UnicodeString) "DATE_FIELD", (UnicodeString) "HOUR_OF_DAY1_FIELD", (UnicodeString) "HOUR_OF_DAY0_FIELD", (UnicodeString) "MINUTE_FIELD", (UnicodeString) "SECOND_FIELD", (UnicodeString) "MILLISECOND_FIELD", (UnicodeString) "DAY_OF_WEEK_FIELD", (UnicodeString) "DAY_OF_YEAR_FIELD", (UnicodeString) "DAY_OF_WEEK_IN_MONTH_FIELD", (UnicodeString) "WEEK_OF_YEAR_FIELD", (UnicodeString) "WEEK_OF_MONTH_FIELD", (UnicodeString) "AM_PM_FIELD", (UnicodeString) "HOUR1_FIELD", (UnicodeString) "HOUR0_FIELD", (UnicodeString) "TIMEZONE_FIELD" }; UBool pass = TRUE; for(int i = 0; i <= 17; ++i) { FieldPosition pos(i); UnicodeString buf; fmt->format(dt, buf, pos); //char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()]; UnicodeString dst; buf.extractBetween(pos.getBeginIndex(), pos.getEndIndex(), dst); UnicodeString str(dst); logln((UnicodeString)"" + i + (UnicodeString)": " + fieldNames[i] + (UnicodeString)", \"" + str + (UnicodeString)"\", " + pos.getBeginIndex() + (UnicodeString)", " + pos.getEndIndex()); UnicodeString exp = expected[i]; if((exp.length() == 0 && str.length() == 0) || str == exp) logln(" ok"); else { errln(UnicodeString(" expected ") + exp); pass = FALSE; } } if( ! pass) errln("Fail: FieldPosition not set right by DateFormat"); delete fmt; }