/* Read and return the next token from the stream. If the token is of typeeString,fillinthetokenparameterwiththetoken.Ifthe tokeniseError,thenthestatusparameterwillcontainthe specificerror.ThiswillbeeItemNotFoundattheendoffile, indicatingthatalltokenshavebeenreturned.Thismethodwill neverreturneStringtwiceinarow;instead,multipleadjacent stringtokenswillbemergedintoone,withnointervening
space. */
U_CFUNC enum ETokenType
getNextToken(UCHARBUF* buf, struct UString *token,
uint32_t *linenumber, /* out: linenumber of token */ struct UString *comment,
UErrorCode *status) { enum ETokenType result;
UChar32 c;
if (U_FAILURE(*status)) { return TOK_ERROR;
}
/* Skip whitespace */
c = getNextChar(buf, true, comment, status);
if (U_FAILURE(*status)) { return TOK_ERROR;
}
*linenumber = lineCount;
switch(c) { case BADBOM: return TOK_ERROR; case OPENBRACE: return TOK_OPEN_BRACE; case CLOSEBRACE: return TOK_CLOSE_BRACE; case COMMA: return TOK_COMMA; case U_EOF: return TOK_EOF; case COLON: return TOK_COLON;
default:
result = getStringToken(buf, c, token, status);
}
*linenumber = lineCount; return result;
}
/* Copy a string token into the given UnicodeString. Upon entry, we havealreadyreadthefirstcharacterofthestringtoken,whichis notawhitespacecharacter(butmaybeaQUOTEorESCAPE).This functionreadsallsubsequentcharactersthatbelongwiththis string,andcopythemintothetokenparameter.Theother important,andslightlyconvolutedpurposeofthisfunctionisto mergeadjacentstrings.Itlooksforwardabit,andifthenext noncomment,nonwhitespaceitemisastring,itreadsitinas well.Iftwoadjacentstringsarequoted,theyaremergedwithout interveningspace.OtherwiseasingleSPACEcharacteris
inserted. */ staticenum ETokenType getStringToken(UCHARBUF* buf,
UChar32 initialChar, struct UString *token,
UErrorCode *status) {
UBool lastStringWasQuoted;
UChar32 c;
UChar target[3] = { '\0' };
UChar *pTarget = target; int len=0;
UBool isFollowingCharEscaped=false;
UBool isNLUnescaped = false;
UChar32 prevC=0;
/* We are guaranteed on entry that initialChar is not a whitespace character.IfweareattheEOF,orhavesomeotherproblem,it doesn'tmatter;westillwanttovalidlyreturntheinitialChar
(if nothing else) as a string token. */
/* DO skip whitespace */
c = getNextChar(buf, true, NULL, status);
if (U_FAILURE(*status)) { return TOK_STRING;
}
if (c == OPENBRACE || c == CLOSEBRACE || c == COMMA || c == COLON) {
ucbuf_ungetc(c, buf); return TOK_STRING;
}
}
}
/* Retrieve the next character. If skipwhite is
true, whitespace is skipped as well. */ static UChar32 getNextChar(UCHARBUF* buf,
UBool skipwhite, struct UString *token,
UErrorCode *status) {
UChar32 c, c2;
if (U_FAILURE(*status)) { return U_EOF;
}
for (;;) {
c = ucbuf_getc(buf,status);
if (c == U_EOF) { return U_EOF;
}
if (skipwhite && isWhitespace(c)) { continue;
}
/* This also handles the get() failing case */ if (c != SLASH) { return c;
}
do {
c = ucbuf_getc(buf,status); /* add the char to token */ if(token!=NULL){
ustr_u32cat(token, c, status);
}
} while (!isNewline(c) && c != U_EOF && *status == U_ZERO_ERROR);
}
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.