void FSIParser::uncharref(StringC &str) { size_t j = 0; size_t i = 0; while (i < str.size()) { int digit; if (matchChar(str[i], '&') && i + 2 < str.size() && matchChar(str[i + 1], '#') && convertDigit(str[i + 2], digit)) { unsigned long val = digit; i += 3; while (i < str.size() && convertDigit(str[i], digit)) { val = val*10 + digit; i++; } str[j++] = val; if (i < str.size() && matchChar(str[i], ';')) i++; } else str[j++] = str[i++]; } str.resize(j); }
Boolean FSIParser::isS(Xchar c) { return (matchChar(c, ' ') || matchChar(c, '\r') || matchChar(c, '\n') || matchChar(c, ' ')); }
bool isMatch(string s, int i, string p, int j) { if (j == p.size()) return i == s.size(); if (j + 1 < p.size() && p[j + 1] == '*') { bool ans = false; while (!(ans = isMatch(s, i, p, j + 2)) && matchChar(s, i, p, j)) ++i; return ans; } else { return matchChar(s, i, p, j) && isMatch(s, i + 1, p, j + 1); } }
RegExp *strToRE( SubStr s ) { RegExp *re; s.len -= 2; s.str += 1; if( s.len == 0 ) return( RegExp_new_NullOp() ); re = matchChar( unescape( &s ) ); while( s.len > 0 ) re = RegExp_new_CatOp( re, matchChar( unescape( &s ) ) ); return( re ); }
char AnyOption::parsePOSIX ( char * arg ) { for ( unsigned int i = 0; i < strlen(arg); i ++ ) { char ch = arg[i]; if ( matchChar(ch) ) { /* keep matching flags till an option */ /*if last char argv[++i] is the value */ if ( i == strlen(arg) - 1 ) { return ch; } else { /* else the rest of arg is the value */ i ++; /* skip any '=' and ' ' */ while ( arg[i] == whitespace || arg[i] == equalsign ) i ++; setValue(ch, arg + i); return '0'; } } } printVerbose("Unknown command argument option : "); printVerbose(arg); printVerbose(); printAutoUsage(); return '0'; }
void FSIParser::convertMinimumLiteral(const StringC &from, StringC &to) { // Do just enough to ensure it can be reparsed. to.resize(0); for (size_t i = 0; i < from.size(); i++) { Char c = from[i]; if (matchChar(c, '"') || matchChar(c, '#')) mgr_.message(EntityManagerMessages::fsiLookupChar, NumberMessageArg(c)); else if (matchChar(c, ' ')) { if (to.size() && to[to.size() - 1] != c) to += c; } else to += c; } if (to.size() && matchChar(to[to.size() - 1], ' ')) to.resize(to.size() - 1); }
Boolean FSIParser::convertDigit(Xchar c, int &weight) { static const char digits[] = "0123456789"; for (int i = 0; digits[i] != '\0'; i++) if (matchChar(c, digits[i])) { weight = i; return 1; } return 0; }
int matchChar(char *subStr, char *text){ if('\0' == *subStr){ return 1; } if('\0' == *text){ return 0; } if(*subStr == *text){ return matchChar(++subStr, ++text); } return 0; }
int match(char *subStr, char *text){ int matchPlace = 1; do{ if(RECURSION && matchChar(subStr, text)){ return matchPlace; } else if(!RECURSION && matchCharUseLoop(subStr, text)){ return matchPlace; } matchPlace++; }while(*text++ != '\0'); return 0; }
Boolean FSIParser::convertId(StringC &id, Xchar smcrd, const StorageManager *sm) { const CharsetInfo *smCharset = sm->idCharset(); StringC newId; size_t i = 0; while (i < id.size()) { UnivChar univ; WideChar wide; ISet<WideChar> wideSet; int digit; if (Xchar(id[i]) == smcrd && i + 1 < id.size() && convertDigit(id[i + 1], digit)) { i += 2; Char val = digit; while (i < id.size() && convertDigit(id[i], digit)) { val = val*10 + digit; i++; } newId += val; if (i < id.size() && matchChar(id[i], ';')) i++; } else if (smCharset) { if (!idCharset_.descToUniv(id[i++], univ)) return 0; if (univ == UnivCharsetDesc::rs) ; else if (univ == UnivCharsetDesc::re && sm->reString()) newId += *sm->reString(); else if (smCharset->univToDesc(univ, wide, wideSet) != 1 || wide > charMax) return 0; // FIXME give error else newId += Char(wide); } else newId += id[i++]; } newId.swap(id); return 1; }
inline bool isChar(TToken &tk) { return matchChar(tk); }
inline bool isLiteral(TToken &tk) { return matchNumber(tk)||matchBool(tk)|| matchChar(tk)|| matchString(tk); }
Boolean FSIParser::parseAttribute(StringC &token, Boolean &gotValue, StringC &value) { Xchar c = get(); while (isS(c)) c = get(); if (c == -1) { return 0; } token.resize(0); if (matchChar(c, '>')) return 1; if (matchChar(c, '"') || matchChar(c, '\'') || matchChar(c, '=')) return 0; for (;;) { token += c; c = get(); if (c == -1) return 0; if (isS(c)) break; if (matchChar(c, '>') || matchChar(c, '=')) break; } while (isS(c)) c = get(); if (c == -1) return 0; if (!matchChar(c, '=')) { unget(); gotValue = 0; return 1; } gotValue = 1; value.resize(0); c = get(); while (isS(c)) c = get(); if (matchChar(c, '>') || matchChar(c, '=')) return 0; if (matchChar(c, '"') || matchChar(c, '\'')) { Char lit = c; for (;;) { Xchar c = get(); if (c == lit) break; if (c == -1) return 0; if (matchChar(c, '\n')) ; else if (matchChar(c, '\r') || matchChar(c, '\t')) value += idCharset_.execToDesc(' '); else value += c; } uncharref(value); } else { for (;;) { value += c; c = get(); if (c == -1) return 0; if (isS(c)) break; if (matchChar(c, '>') || matchChar(c, '=')) { unget(); break; } } } return 1; }
Boolean FSIParser::parse(ParsedSystemId &parsedSysid) { size_t startIndex = strIndex_; if (!matchChar(get(), '<')) return handleInformal(startIndex, parsedSysid); StringC key; for (;;) { Xchar c = get(); if (c == -1) return handleInformal(startIndex, parsedSysid); if (isS(c) || matchChar(c, '>')) break; key += Char(c); } unget(); if (matchKey(key, "CATALOG")) { if (!setCatalogAttributes(parsedSysid)) return 0; return parse(parsedSysid); } Boolean neutral; StorageManager *sm = lookupStorageType(key, neutral); if (!sm) return handleInformal(startIndex, parsedSysid); for (;;) { parsedSysid.resize(parsedSysid.size() + 1); StorageObjectSpec &sos = parsedSysid.back(); sos.storageManager = sm; Xchar smcrd; Boolean fold; if (!setAttributes(sos, neutral, smcrd, fold)) return 0; sm = 0; StringC id; Boolean hadData = 0; for (;;) { Xchar c = get(); if (c == -1) break; if (matchChar(c, '<')) { hadData = 1; Char stago = c; key.resize(0); for (;;) { c = get(); if (c == -1) { id += stago; id += key; break; } if (isS(c) || matchChar(c, '>')) { unget(); sm = lookupStorageType(key, neutral); if (!sm) { id += stago; id += key; } break; } key += c; } if (sm) break; } else if (!((!hadData && matchChar(c, '\r')) // ignored RE || matchChar(c, '\n') )) { // ignored RS hadData = 1; id += c; } } if (id.size() > 0 && matchChar(id[id.size() - 1], '\r')) id.resize(id.size() - 1); uncharref(id); id.swap(sos.specId); if (!convertId(sos.specId, smcrd, sos.storageManager)) return 0; if (neutral) { if (!sos.storageManager->transformNeutral(sos.specId, fold, mgr_)) return 0; } if (sos.storageManager->resolveRelative(sos.baseId, sos.specId, sos.search)) sos.baseId.resize(0); if (!sm) break; } return 1; }
int RegularExpression::match(Context* const context, const Op* const operations , int offset, const short direction) { const Op* tmpOp = operations; bool ignoreCase = isSet(fOptions, IGNORE_CASE); while (true) { if (tmpOp == 0) break; if (offset > context->fLimit || offset < context->fStart) return -1; switch(tmpOp->getOpType()) { case Op::O_CHAR: if (!matchChar(context, tmpOp->getData(), offset, direction, ignoreCase)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_DOT: if (!matchDot(context, offset, direction)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_RANGE: case Op::O_NRANGE: if (!matchRange(context, tmpOp, offset, direction, ignoreCase)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_ANCHOR: if (!matchAnchor(context, tmpOp->getData(), offset)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_BACKREFERENCE: if (!matchBackReference(context, tmpOp->getData(), offset, direction, ignoreCase)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_STRING: if (!matchString(context, tmpOp->getLiteral(), offset, direction, ignoreCase)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_CLOSURE: { XMLInt32 id = tmpOp->getData(); if (id >= 0) { int prevOffset = context->fOffsets[id]; if (prevOffset < 0 || prevOffset != offset) { context->fOffsets[id] = offset; } else { context->fOffsets[id] = -1; tmpOp = tmpOp->getNextOp(); break; } } int ret = match(context, tmpOp->getChild(), offset, direction); if (id >= 0) { context->fOffsets[id] = -1; } if (ret >= 0) return ret; tmpOp = tmpOp->getNextOp(); } break; case Op::O_QUESTION: { int ret = match(context, tmpOp->getChild(), offset, direction); if (ret >= 0) return ret; tmpOp = tmpOp->getNextOp(); } break; case Op::O_NONGREEDYCLOSURE: case Op::O_NONGREEDYQUESTION: { int ret = match(context,tmpOp->getNextOp(),offset,direction); if (ret >= 0) return ret; tmpOp = tmpOp->getChild(); } break; case Op::O_UNION: { return matchUnion(context, tmpOp, offset, direction); } case Op::O_CAPTURE: if (context->fMatch != 0 && tmpOp->getData() != 0) return matchCapture(context, tmpOp, offset, direction); tmpOp = tmpOp->getNextOp(); break; case Op::O_LOOKAHEAD: if (0 > match(context, tmpOp->getChild(), offset, 1)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_NEGATIVELOOKAHEAD: if (0 <= match(context, tmpOp->getChild(), offset, 1)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_LOOKBEHIND: if (0 > match(context, tmpOp->getChild(), offset, -1)) return - 1; tmpOp = tmpOp->getNextOp(); break; case Op::O_NEGATIVELOOKBEHIND: if (0 <= match(context, tmpOp->getChild(), offset, -1)) return -1; tmpOp = tmpOp->getNextOp(); break; case Op::O_INDEPENDENT: case Op::O_MODIFIER: { int ret = (tmpOp->getOpType() == Op::O_INDEPENDENT) ? match(context, tmpOp->getChild(), offset, direction) : matchModifier(context, tmpOp, offset, direction); if (ret < 0) return ret; offset = ret; tmpOp = tmpOp->getNextOp(); } break; case Op::O_CONDITION: if (tmpOp->getRefNo() >= fNoGroups) return -1; if (matchCondition(context, tmpOp, offset, direction)) tmpOp = tmpOp->getYesFlow(); else if (tmpOp->getNoFlow() != 0) tmpOp = tmpOp->getNoFlow(); else tmpOp = tmpOp->getNextOp(); break; } } return offset; }
/**************************************************************************** NAME hfpHandleIndicatorList DESCRIPTION Generic indicator list handler, if we don't get a dictionary look up match we'll end up in here so we need to parse the string manually as it is too complicated for the parser. AT INDICATION +CIND RETURNS void */ void hfpHandleIndicatorList(Task link_ptr, const struct hfpHandleIndicatorList *ind) { hfp_link_data* link = (hfp_link_data*)link_ptr; hfp_indicators ind_indexes = { 0, 0, 0, 0, 0, 0, 0 }; uint16 index = 0; ptr indicator = ind->str.data; uint16 length = ind->str.length; ptr indicators_end = indicator + length; ptr next_indicator; /* Skip any leading whitespace */ indicator = hfpSkipSpace(indicator, indicators_end); /* Make sure we reset the count of extra indicators */ link->ag_supported_indicators.num_extra_indicator_idxs = 0; /* While we can find another '(' ... */ while((next_indicator = matchChar(indicator, indicators_end, '(')) != 0) { /* Increment index for this indicator */ index++; /* Set indicator to the start of the indicator name */ indicator = matchChar(hfpSkipSpace(next_indicator, indicators_end), indicators_end, '"'); /* Make sure the string matches but also make sure that only that string matches e.g. for "call" we don't want "call_tmp" to match. Store the indicator index. */ if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "service", 7)) { ind_indexes.service = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "callsetup", 9)) { if(ind_indexes.call_setup) ind_indexes.extra_call_setup = index; else ind_indexes.call_setup = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "call_setup", 10)) { if(ind_indexes.call_setup) ind_indexes.extra_call_setup = index; else ind_indexes.call_setup = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "call\"", 5)) { ind_indexes.call = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "signal", 6)) { ind_indexes.signal_strength = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "roam", 4)) { ind_indexes.roaming_status = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "battchg", 7)) { ind_indexes.battery_charge = index; } else if (!UtilCompare((const uint16 *) indicator, (const uint16 *) "callheld", 8)) { ind_indexes.call_hold_status = index; } /* This is to work out the extra indicators we must tell the app about */ if (theHfp->extra_indicators) hfpHandleExtraIndicatorsList(link, indicator, indicators_end, index, length); /* skip , ( ... ) ) */ indicator = hfpSkipPastChar(indicator, indicators_end, ')'); indicator = hfpSkipPastChar(indicator, indicators_end, ')'); /* Skip separating comma if present. */ next_indicator = hfpSkipSpace(matchChar(indicator, indicators_end, ','), indicators_end); if(next_indicator) indicator = next_indicator; } /* Store the total number of indicators listed */ link->ag_supported_indicators.num_indicators = index; /* To work with old AGs don't check callsetup indicator. */ if (ind_indexes.service && ind_indexes.call) { /* Update local indicator index values */ link->ag_supported_indicators.indicator_idxs = ind_indexes; } }