StringC PosixStorageManager::extractDir(const StringC &str) const { for (size_t i = str.size(); i > 0; i--) if (str[i - 1] == '/') return StringC(str.data(), i); // include slash for root case return StringC(); }
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); }
StringC PosixStorageManager::extractDir(const StringC &str) const { for (size_t i = str.size(); i > 0; i--) if (str[i - 1] == '/' || str[i - 1] == '\\' || (i == 2 && str[i - 1] == ':')) return StringC(str.data(), i); // include separator return StringC(); }
StringC PosixStorageManager::combineDir(const StringC &dir, const StringC &base) const { StringC result(dir); if (dir.size() > 0 && dir[dir.size() - 1] != '/') result += '/'; result += base; return result; }
Boolean FSIParser::matchKey(const StringC &str, const char *s) { if (strlen(s) != str.size()) return false; for (size_t i = 0; i < str.size(); i++) if (idCharset_.execToDesc(toupper(s[i])) != str[i] && idCharset_.execToDesc(tolower(s[i])) != str[i]) return false; return true; }
void unparseSoi(const StringC &soi, const CharsetInfo *idCharset, const CharsetInfo &resultCharset, StringC &result, Boolean &needSmcrd) { if (!idCharset) { for (size_t i = 0; i < soi.size(); i++) { char buf[32]; sprintf(buf, "&#%lu;", (unsigned long)soi[i]); result += resultCharset.execToDesc(buf); } return; } for (size_t i = 0; i < soi.size(); i++) { UnivChar univ; WideChar to; ISet<WideChar> toSet; if (!idCharset->descToUniv(soi[i], univ) || univ >= 127 || univ < 32 || univ == 36 // $ || univ == 96 // ` #ifndef MSDOS_FILENAMES || univ == 92 // backslash #endif || univ == 94 // ^ || resultCharset.univToDesc(univ, to, toSet) != 1) { needSmcrd = 1; char buf[32]; sprintf(buf, "^%lu;", (unsigned long)soi[i]); result += resultCharset.execToDesc(buf); } else { switch (univ) { case 34: // double quote case 35: // # case 39: // apostrophe case 60: // < { char buf[32]; sprintf(buf, "&#%lu;", (unsigned long)to); result += resultCharset.execToDesc(buf); } break; default: result += Char(to); break; } } } }
StringC PosixStorageManager::combineDir(const StringC &dir, const StringC &base) const { StringC result(dir); if (dir.size() > 0) { Char lastChar = dir[dir.size() - 1]; if (lastChar != '/' && lastChar != '\\' && !(dir.size() == 2 && lastChar == ':')) result += '\\'; } result += base; return result; }
Boolean EntityManagerImpl::matchKey(const StringC &type, const char *s, const CharsetInfo &docCharset) { if (strlen(s) != type.size()) return false; for (size_t i = 0; i < type.size(); i++) if (docCharset.execToDesc(toupper(s[i])) != type[i] && docCharset.execToDesc(tolower(s[i])) != type[i]) return false; return true; }
Boolean PosixStorageManager::transformNeutral(StringC &str, Boolean, Messenger &) const { for (size_t i = 0; i < str.size(); i++) if (str[i] == '/') str[i] = '\\'; return 1; }
void ParsedSystemId::unparse(const CharsetInfo &resultCharset, StringC &result) const { size_t len = size(); result.resize(0); size_t i; for (i = 0; i < maps.size(); i++) { if (maps[i].type == ParsedSystemIdMap::catalogDocument) result += resultCharset.execToDesc("<CATALOG>"); else if (maps[i].type == ParsedSystemIdMap::catalogPublic) { result += resultCharset.execToDesc("<CATALOG PUBLIC=\""); result += maps[i].publicId; result += resultCharset.execToDesc("\">"); } } for (i = 0; i < len; i++) { const StorageObjectSpec &sos = (*this)[i]; result += resultCharset.execToDesc('<'); result += resultCharset.execToDesc(sos.storageManager->type()); if (sos.notrack) result += resultCharset.execToDesc(" NOTRACK"); if (!sos.search) result += resultCharset.execToDesc(" NOSEARCH"); if (!sos.storageManager->requiresCr() && sos.records != StorageObjectSpec::find) { result += resultCharset.execToDesc(' '); result += resultCharset.execToDesc(FSIParser::recordsName(sos.records)); } if (sos.codingSystemName) { if (!sos.zapEof) result += resultCharset.execToDesc(" NOZAPEOF"); result += resultCharset.execToDesc(" BCTF="); result += resultCharset.execToDesc(sos.codingSystemName); } Boolean needSmcrd = 0; if (sos.baseId.size() != 0) { result += resultCharset.execToDesc(" SOIBASE='"); unparseSoi(sos.baseId, sos.storageManager->idCharset(), resultCharset, result, needSmcrd); result += resultCharset.execToDesc('\''); } StringC tem; unparseSoi(sos.specId, sos.storageManager->idCharset(), resultCharset, tem, needSmcrd); if (needSmcrd) result += resultCharset.execToDesc(" SMCRD='^'"); result += resultCharset.execToDesc('>'); result += tem; } }
Boolean PosixStorageManager::transformNeutral(StringC &str, Boolean fold, Messenger &) const { if (fold) for (size_t i = 0; i < str.size(); i++) { Char c = str[i]; if (c <= (unsigned char)-1) str[i] = tolower(str[i]); } return 1; }
void Text::insertChars(const StringC &s, const Location &loc) { chars_.insert(0, s); items_.resize(items_.size() + 1); for (size_t i = items_.size() - 1; i > 0; i--) { items_[i] = items_[i - 1]; items_[i].index += s.size(); } items_[0].loc = loc; items_[0].type = TextItem::data; items_[0].index = 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 CharsetRegistry::findCharset(const PublicId &id, const CharsetInfo &charset, UnivCharsetDesc &desc) { PublicId::OwnerType ownerType; if (!id.getOwnerType(ownerType) || ownerType != PublicId::ISO) return 0; StringC sequence; if (!id.getDesignatingSequence(sequence)) return 0; // Canonicalize the escape sequence by mapping esc -> ESC, // removing leading zeros from escape sequences, and removing // initial spaces. StringC s; size_t i; for (i = 0; i < sequence.size(); i++) { Char c = sequence[i]; if (c == charset.execToDesc('e')) s += charset.execToDesc('E'); else if (c == charset.execToDesc('s')) s += charset.execToDesc('S'); else if (c == charset.execToDesc('c')) s += charset.execToDesc('C'); else if (charset.digitWeight(c) >= 0 && s.size() > 0 && s[s.size() - 1] == charset.execToDesc('0') && (s.size() == 1 || charset.digitWeight(s[s.size() - 2]) >= 0)) s[s.size() - 1] = c; else if (c != charset.execToDesc(' ') || s.size() > 0) s += c; } for (i = 0; i < SIZEOF(table); i++) if (s == charset.execToDesc(table[i].sequence)) { desc.set(table[i].ranges, table[i].nRanges); return 1; } 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; }
Boolean PosixStorageManager::isAbsolute(const StringC &file) const { return file.size() > 0 && file[0] == '/'; }
Boolean PosixStorageManager::isAbsolute(const StringC &s) const { if (s.size() == 0) return 0; return s[0] == '/' || s[0] == '\\' || (s.size() > 1 && s[1] == ':'); }
void AllowedParamsMessageArg::append(MessageBuilder &builder) const { Syntax::DelimGeneral delims[3]; int nDelims = 0; if (allow_.mdc()) delims[nDelims++] = Syntax::dMDC; if (allow_.dso()) delims[nDelims++] = Syntax::dDSO; switch (allow_.mainMode()) { case mdMinusMode: delims[nDelims++] = Syntax::dMINUS; break; case mdPeroMode: delims[nDelims++] = Syntax::dPERO; break; default: break; } Boolean first = 1; int i; for (i = 0; i < nDelims; i++) { if (!first) builder.appendFragment(ParserMessages::listSep); else first = 0; const StringC &delim = syntax_->delimGeneral(delims[i]); builder.appendFragment(ParserMessages::delimStart); builder.appendChars(delim.data(), delim.size()); #if 0 builder.appendFragment(ParserMessages::delimEnd); #endif } const MessageFragment *fragment[5]; int nFragments = 0; if (allow_.inclusions()) fragment[nFragments++] = &ParserMessages::inclusions; if (allow_.exclusions()) fragment[nFragments++] = &ParserMessages::exclusions; switch (allow_.literal()) { case Param::minimumLiteral: fragment[nFragments++] = &ParserMessages::minimumLiteral; break; case Param::attributeValueLiteral: case Param::tokenizedAttributeValueLiteral: fragment[nFragments++] = &ParserMessages::attributeValueLiteral; break; case Param::systemIdentifier: fragment[nFragments++] = &ParserMessages::systemIdentifier; break; case Param::paramLiteral: fragment[nFragments++] = &ParserMessages::parameterLiteral; break; } switch (allow_.nameStart()) { case Param::name: case Param::entityName: case Param::paramEntityName: fragment[nFragments++] = &ParserMessages::name; break; case Param::attributeValue: fragment[nFragments++] = &ParserMessages::attributeValue; break; } if (allow_.digit() == Param::number) fragment[nFragments++] = &ParserMessages::number; for (i = 0; i < nFragments; i++) { if (!first) builder.appendFragment(ParserMessages::listSep); else first = 0; builder.appendFragment(*fragment[i]); } if (allow_.rni() || allow_.nameStart() == Param::reservedName) { for (int i = 0; i < Syntax::nNames; i++) { if (allow_.reservedName(Syntax::ReservedName(i))) { if (!first) builder.appendFragment(ParserMessages::listSep); else first = 0; StringC str; if (allow_.rni()) str = syntax_->delimGeneral(Syntax::dRNI); str += syntax_->reservedName(Syntax::ReservedName(i)); builder.appendChars(str.data(), str.size()); } } } }
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; }
void StrOutputCharStream::extractString(StringC &str) { str.assign(buf_, ptr_ - buf_); sync(0); }