U_CAPI UChar* U_EXPORT2 u_strtok_r(UChar *src, const UChar *delim, UChar **saveState) { UChar *tokSource; UChar *nextToken; uint32_t nonDelimIdx; /* If saveState is NULL, the user messed up. */ if (src != NULL) { tokSource = src; *saveState = src; /* Set to "src" in case there are no delimiters */ } else if (*saveState) { tokSource = *saveState; } else { /* src == NULL && *saveState == NULL */ /* This shouldn't happen. We already finished tokenizing. */ return NULL; } /* Skip initial delimiters */ nonDelimIdx = u_strspn(tokSource, delim); tokSource = &tokSource[nonDelimIdx]; if (*tokSource) { nextToken = u_strpbrk(tokSource, delim); if (nextToken != NULL) { /* Create a token */ *(nextToken++) = 0; *saveState = nextToken; return tokSource; } else if (*saveState) { /* Return the last token */ *saveState = NULL; return tokSource; } } else { /* No tokens were found. Only delimiters were left. */ *saveState = NULL; } return NULL; }
void Tag::parseNumeric() { if (tag.size() >= 256) { return; } UChar tkey[256]; UChar top[256]; UChar txval[256]; UChar spn[] = { '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0 }; tkey[0] = 0; top[0] = 0; txval[0] = 0; if (u_sscanf(tag.c_str(), "%*[<]%[^<>=:!]%[<>=:!]%[-MAXIN0-9]%*[>]", &tkey, &top, &txval) == 3 && top[0] && txval[0]) { int32_t tval = 0; int32_t r = u_strspn(txval, spn); if (txval[0] == 'M' && txval[1] == 'A' && txval[2] == 'X' && txval[3] == 0) { tval = std::numeric_limits<int32_t>::max(); } else if (txval[0] == 'M' && txval[1] == 'I' && txval[2] == 'N' && txval[3] == 0) { tval = std::numeric_limits<int32_t>::min(); } else if (txval[r] || u_sscanf(txval, "%d", &tval) != 1) { return; } if (top[0] == '<') { comparison_op = OP_LESSTHAN; } else if (top[0] == '>') { comparison_op = OP_GREATERTHAN; } else if (top[0] == '=' || top[0] == ':') { comparison_op = OP_EQUALS; } else if (top[0] == '!') { comparison_op = OP_NOTEQUALS; } if (top[1]) { if (top[1] == '=' || top[1] == ':') { if (comparison_op == OP_GREATERTHAN) { comparison_op = OP_GREATEREQUALS; } else if (comparison_op == OP_LESSTHAN) { comparison_op = OP_LESSEQUALS; } else if (comparison_op == OP_NOTEQUALS) { comparison_op = OP_NOTEQUALS; } } else if (top[1] == '>') { if (comparison_op == OP_EQUALS) { comparison_op = OP_GREATEREQUALS; } else if (comparison_op == OP_LESSTHAN) { comparison_op = OP_NOTEQUALS; } } else if (top[1] == '<') { if (comparison_op == OP_EQUALS) { comparison_op = OP_LESSEQUALS; } else if (comparison_op == OP_GREATERTHAN) { comparison_op = OP_NOTEQUALS; } } } comparison_val = tval; comparison_hash = hash_value(tkey); type |= T_NUMERICAL; } }