std::string parentNamespace(const std::string& name) { std::string error; if (!validate(name, error)) { throw InvalidNameException(error); } if (!name.compare("")) return ""; if (!name.compare("/")) return "/"; std::string stripped_name; // rstrip trailing slash if (name.find_last_of('/') == name.size()-1) stripped_name = name.substr(0, name.size() -2); else stripped_name = name; //pull everything up to the last / size_t last_pos = stripped_name.find_last_of('/'); if (last_pos == std::string::npos) { return ""; } else if (last_pos == 0) return "/"; return stripped_name.substr(0, last_pos); }
/********************************************************************************************** * * ReadQualifiedName * * QualifiedName = Name ? ":" ? Name ; * * Name = NameStartCharacter ( NameCharacter )* ; * * NameStartCharacter = "_" | [A-Z] | [a-z] ; * * NameCharacter = NameStartCharacter | "-" | "." | [0-9] ; * *********************************************************************************************/ QualifiedName XMLParser::ReadQualifiedName () { static const int name_charachters [] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; bool first = true; bool valid = true; std::string specifier; std::string name; do { if (valid && current == ':') { if (specifier == "") { specifier = output.toString (); output.Reset (); } else { valid = false; } } else if (current == '\x20' || current == '\x9' || current == '\xD' || current == '\xA') { Position end = position; if (!valid) throw InvalidNameException (); if (first ) throw UnexpectedTokenException (); return QualifiedName (specifier, name); } else if ('\0' <= current && current < '\x7f' && name_characters [(int) current] == 1) { if ((first && '9' < current) || !first) { first = false; output.AppendIgnoreCase (current); } else { valid = false; } } else { valid = false; continue; } } while (ReadCharacter ()); return UnexpectedEndException (); }
std::string resolve(const std::string& ns, const std::string& name, bool _remap) { std::string error; if (!validate(name, error)) { throw InvalidNameException(error); } if (name.empty()) { if (ns.empty()) { return "/"; } if (ns[0] == '/') { return ns; } return append("/", ns); } std::string copy = name; if (copy[0] == '~') { copy = append(this_node::getName(), copy.substr(1)); } if (copy[0] != '/') { copy = append("/", append(ns, copy)); } copy = clean(copy); if (_remap) { copy = remap(copy); } return copy; }
void CookieManager::prepareName(std::string &name) { for (const char * str = name.c_str(); *str; str++) if (!((*str >= 'a' && *str <= 'z') || (*str >= 'A' && *str <= 'Z') || (*str >= '0' && *str <= '9') || *str == '_')) throw InvalidNameException(name); }