while (index < limit) {
UChar32 c = text.char32At(index);
// parse \s* if (cpat == 126/*~*/) { if (PatternProps::isWhiteSpace(c)) {
index += U16_LENGTH(c); continue;
} else { if (++ipat == pat.length()) { return index; // success; c unparsed
} // fall thru; process c again with next cpat
}
}
// parse literal elseif (c == cpat) {
index += U16_LENGTH(c);
ipat += U16_LENGTH(cpat); if (ipat == pat.length()) { return index; // success; c parsed
} // fall thru; get next cpat
}
// match failure of literal else { return -1;
}
cpat = pat.char32At(ipat);
}
return -1; // text ended before end of pat
}
int32_t ICU_Utility::parseAsciiInteger(const UnicodeString& str, int32_t& pos) {
int32_t result = 0;
char16_t c; while (pos < str.length() && (c = str.charAt(pos)) >= u'0' && c <= u'9') {
result = result * 10 + (c - u'0');
pos++;
} return result;
}
/** *Appendacharactertoarulethatisbeingbuiltup.Toflush *thequoteBuftorule,makeonefinalcallwithisLiteral==true. *Ifthereisnofinalcharacter,passin(UChar32)-1asc. *@paramrulethestringtoappendthecharacterto *@paramcthecharactertoappend,or(UChar32)-1ifnone. *@paramisLiteraliftrue,thenthegivencharactershouldnotbe *quotedorescaped.Usuallythismeansitisasyntacticelement *suchas>or$ *@paramescapeUnprintableiftrue,thenunprintablecharacters *shouldbeescapedusing\uxxxxor\Uxxxxxxxx.Theseescapeswill *appearoutsideofquotes. *@paramquoteBufabufferwhichisusedtobuildupquoted *substrings.Thecallershouldinitiallysupplyanemptybuffer, *andthereaftershouldnotmodifythebuffer.Thebuffershouldbe *clearedoutby,attheend,callingthismethodwithaliteral *character.
*/ void ICU_Utility::appendToRule(UnicodeString& rule,
UChar32 c,
UBool isLiteral,
UBool escapeUnprintable,
UnicodeString& quoteBuf) { // If we are escaping unprintables, then escape them outside // quotes. \u and \U are not recognized within quotes. The same // logic applies to literals, but literals are never escaped. if (isLiteral ||
(escapeUnprintable && ICU_Utility::isUnprintable(c))) { if (quoteBuf.length() > 0) { // We prefer backslash APOSTROPHE to double APOSTROPHE // (more readable, less similar to ") so if there are // double APOSTROPHEs at the ends, we pull them outside // of the quote.
// If the first thing in the quoteBuf is APOSTROPHE // (doubled) then pull it out. while (quoteBuf.length() >= 2 &&
quoteBuf.charAt(0) == APOSTROPHE &&
quoteBuf.charAt(1) == APOSTROPHE) {
rule.append(BACKSLASH).append(APOSTROPHE);
quoteBuf.remove(0, 2);
} // If the last thing in the quoteBuf is APOSTROPHE // (doubled) then remove and count it and add it after.
int32_t trailingCount = 0; while (quoteBuf.length() >= 2 &&
quoteBuf.charAt(quoteBuf.length()-2) == APOSTROPHE &&
quoteBuf.charAt(quoteBuf.length()-1) == APOSTROPHE) {
quoteBuf.truncate(quoteBuf.length()-2);
++trailingCount;
} if (quoteBuf.length() > 0) {
rule.append(APOSTROPHE);
rule.append(quoteBuf);
rule.append(APOSTROPHE);
quoteBuf.truncate(0);
} while (trailingCount-- > 0) {
rule.append(BACKSLASH).append(APOSTROPHE);
}
} if (c != static_cast<UChar32>(-1)) { /* Since spaces are ignored during parsing, they are *emittedonlyforreadability.Weemitonehere *onlyifthereisn'talreadyoneattheendofthe *rule.
*/ if (c == SPACE) {
int32_t len = rule.length(); if (len > 0 && rule.charAt(len-1) != c) {
rule.append(c);
}
} elseif (!escapeUnprintable || !ICU_Utility::escapeUnprintable(rule, c)) {
rule.append(c);
}
}
}
// Escape ' and '\' and don't begin a quote just for them elseif (quoteBuf.length() == 0 &&
(c == APOSTROPHE || c == BACKSLASH)) {
rule.append(BACKSLASH);
rule.append(c);
}
// Specials (printable ascii that isn't [0-9a-zA-Z]) and // whitespace need quoting. Also append stuff to quotes if we are // building up a quoted substring already. elseif (quoteBuf.length() > 0 ||
(c >= 0x0021 && c <= 0x007E &&
!((c >= 0x0030/*'0'*/ && c <= 0x0039/*'9'*/) ||
(c >= 0x0041/*'A'*/ && c <= 0x005A/*'Z'*/) ||
(c >= 0x0061/*'a'*/ && c <= 0x007A/*'z'*/))) ||
PatternProps::isWhiteSpace(c)) {
quoteBuf.append(c); // Double ' within a quote if (c == APOSTROPHE) {
quoteBuf.append(c);
}
}
// Otherwise just append else {
rule.append(c);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.