tiny_string XMLBase::removeWhitespace(tiny_string val) { bool bwhite = true; uint32_t start = 0; CharIterator it = val.begin(); CharIterator itend = val.begin(); while (it != val.end()) { if (!g_unichar_isspace(*it)) { itend=it; itend++; bwhite = false; } else if (bwhite) start++; it++; } if (bwhite) return ""; return val.substr(start,itend); }
bool Array::isValidQName(const tiny_string& name, const tiny_string& ns, unsigned int& index) { if(ns!="") return false; assert_and_throw(!name.empty()); index=0; //First we try to convert the string name to an index, at the first non-digit //we bail out for(auto i=name.begin(); i!=name.end(); ++i) { if(!i.isdigit()) return false; index*=10; index+=i.digit_value(); } return true; }
bool Array::isIntegerWithoutLeadingZeros(const tiny_string& value) { if (value.empty()) return false; else if (value == "0") return true; bool first = true; for (CharIterator it=value.begin(); it!=value.end(); ++it) { if (!it.isdigit() || (first && *it == '0')) return false; first = false; } return true; }
const tiny_string XMLBase::encodeToXML(const tiny_string value, bool bIsAttribute) { tiny_string res; auto it = value.begin(); while (it != value.end()) { switch (*it) { case '<': res += "<"; break; case '>': res += bIsAttribute ? ">" : ">"; break; case '&': res += "&"; break; case '\"': res += bIsAttribute ? """ : "\""; break; case '\r': res += bIsAttribute ? "
" : "\r"; break; case '\n': res += bIsAttribute ? "
" : "\n"; break; case '\t': res += bIsAttribute ? "	" : "\t"; break; default: res += *it; break; } it++; } return res; }