220www2id(
const string &in,
const string &escape,
const string &except)
222 string::size_type i = 0;
224 while ((i = res.find_first_of(escape, i)) != string::npos) {
225 if (except.find(res.substr(i, 3)) != string::npos) {
229 res.replace(i, 3, unhexstring(res.substr(i + 1, 2)));
272id2xml(
string in,
const string ¬_allowed)
274 string::size_type i = 0;
276 while ((i = in.find_first_of(not_allowed, i)) != string::npos) {
277 in.replace(i, 1, entity(in[i]));
292 string octal_escape =
"\\\\";
294 string::size_type length = in.length();
295 while ((i = in.find(octal_escape, i)) != string::npos) {
297 string::size_type j = i + 2;
300 string octal_digits = in.substr(j, 3);
302 string hex_escape = string(
"&#x");
303 hex_escape.append(octal_to_hex(octal_digits));
304 hex_escape.append(
string(
";"));
307 in.replace(i, 5, hex_escape);
370 const string printable =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;<,>.?/'\"";
371 const string ESC =
"\\";
372 const string DOUBLE_ESC = ESC + ESC;
373 const string QUOTE =
"\"";
374 const string ESCQUOTE = ESC + QUOTE;
377 string::size_type ind = 0;
378 while ((ind = s.find(ESC, ind)) != s.npos) {
379 s.replace(ind, 1, DOUBLE_ESC);
380 ind += DOUBLE_ESC.length();
385 while ((ind = s.find_first_not_of(printable, ind)) != s.npos)
386 s.replace(ind, 1, ESC + octstring(s[ind]));
390 while ((ind = s.find(QUOTE, ind)) != s.npos) {
391 s.replace(ind, 1, ESCQUOTE);
392 ind += ESCQUOTE.length();
409 const Regex octal(
"\\\\[0-3][0-7][0-7]");
410 const Regex esc_quote(
"\\\\\"");
411 const Regex esc_esc(
"\\\\\\\\");
412 const string ESC =
"\\";
413 const string QUOTE =
"\"";
417 DBG(cerr <<
"0XX" << s <<
"XXX" << endl);
419 index = esc_esc.search(s.c_str(), s.length(), matchlen, 0);
420 while (index < s.length()) {
421 DBG(cerr <<
"1aXX" << s <<
"XXX index: " << index << endl);
422 s.replace(index, 2, ESC);
423 DBG(cerr <<
"1bXX" << s <<
"XXX index: " << index << endl);
424 index = esc_esc.search(s.c_str(), s.length(), matchlen, 0);
428 index = esc_quote.search(s.c_str(), s.length(), matchlen, 0);
429 while (index < s.length()) {
430 s.replace(index, 2, QUOTE);
431 DBG(cerr <<
"2XX" << s <<
"XXX index: " << index << endl);
432 index = esc_quote.search(s.c_str(), s.length(), matchlen, 0);
436 index = octal.search(s.c_str(), s.length(), matchlen, 0);
437 while (index < s.length()) {
438 s.replace(index, 4, unoctstring(s.substr(index + 1, 3)));
439 DBG(cerr <<
"3XX" << s <<
"XXX index: " << index << endl);
440 index = octal.search(s.c_str(), s.length(), matchlen, 0);
443 DBG(cerr <<
"4XX" << s <<
"XXX" << endl);