83 buf << hex << setw(2) << setfill('0') << static_cast<unsigned int>(val);
95 tmp_str[0] =
static_cast<char>(val);
97 return string(tmp_str);
104 buf << oct << setw(3) << setfill(
'0')
105 <<
static_cast<unsigned int>(val);
118 DBG(cerr <<
"unoctstring: " << val << endl);
121 tmp_str[0] =
static_cast<char>(val);
123 return string(tmp_str);
151 id2www(
string in,
const string &allowable)
153 string::size_type i = 0;
154 DBG(cerr<<
"Input string: [" << in <<
"]" << endl);
155 while ((i = in.find_first_not_of(allowable, i)) != string::npos) {
156 DBG(cerr<<
"Found escapee: [" << in[i] <<
"]");
157 in.replace(i, 1,
"%" +
hexstring(in[i]));
158 DBGN(cerr<<
" now the string is: " << in << endl);
178 return id2www(in, allowable);
218 www2id(
const string &in,
const string &escape,
const string &except)
220 string::size_type i = 0;
222 while ((i = res.find_first_of(escape, i)) != string::npos) {
223 if (except.find(res.substr(i, 3)) != string::npos) {
227 res.replace(i, 3,
unhexstring(res.substr(i + 1, 2)));
238 case '>':
return ">";
239 case '<':
return "<";
240 case '&':
return "&";
241 case '\'':
return "'";
242 case '\"':
return """;
244 throw InternalErr(__FILE__, __LINE__,
"Unrecognized character.");
255 istringstream ss(octal_digits);
259 ds << hex << setw(2) << setfill(
'0') << val;
270 id2xml(
string in,
const string ¬_allowed)
272 string::size_type i = 0;
274 while ((i = in.find_first_of(not_allowed, i)) != string::npos) {
275 in.replace(i, 1, entity(in[i]));
290 string octal_escape =
"\\\\";
292 string::size_type length = in.length();
293 while ((i = in.find(octal_escape, i)) != string::npos) {
295 string::size_type j = i + 2;
298 string octal_digits = in.substr(j, 3);
300 string hex_escape = string(
"&#x");
302 hex_escape.append(
string(
";"));
305 in.replace(i, 5, hex_escape);
322 string::size_type i = 0;
324 while ((i = in.find(
">", i)) != string::npos)
325 in.replace(i, 4,
">");
328 while ((i = in.find(
"<", i)) != string::npos)
329 in.replace(i, 4,
"<");
332 while ((i = in.find(
"&", i)) != string::npos)
333 in.replace(i, 5,
"&");
336 while ((i = in.find(
"'", i)) != string::npos)
337 in.replace(i, 6,
"'");
340 while ((i = in.find(
""", i)) != string::npos)
341 in.replace(i, 6,
"\"");
354 string::size_type pos;
355 while ((pos = s.find(
'%')) != string::npos)
356 s.replace(pos, 3,
"_");
368 const string printable =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;<,>.?/'\"";
369 const string ESC =
"\\";
370 const string DOUBLE_ESC = ESC + ESC;
371 const string QUOTE =
"\"";
372 const string ESCQUOTE = ESC + QUOTE;
375 string::size_type ind = 0;
376 while ((ind = s.find_first_not_of(printable, ind)) != s.npos)
377 s.replace(ind, 1, ESC +
octstring(s[ind]));
381 while ((ind = s.find(ESC, ind)) != s.npos) {
382 s.replace(ind, 1, DOUBLE_ESC);
383 ind += DOUBLE_ESC.length();
388 while ((ind = s.find(QUOTE, ind)) != s.npos) {
389 s.replace(ind, 1, ESCQUOTE);
390 ind += ESCQUOTE.length();
407 Regex octal(
"\\\\[0-3][0-7][0-7]");
408 Regex esc_quote(
"\\\\\"");
409 Regex esc_esc(
"\\\\\\\\");
410 const string ESC =
"\\";
411 const string QUOTE =
"\"";
415 DBG(cerr <<
"0XX" << s <<
"XXX" << endl);
417 index = esc_esc.search(s.c_str(), s.length(), matchlen, 0);
418 while (index < s.length()) {
419 DBG(cerr <<
"1aXX" << s <<
"XXX index: " << index << endl);
420 s.replace(index, 2, ESC);
421 DBG(cerr <<
"1bXX" << s <<
"XXX index: " << index << endl);
422 index = esc_esc.search(s.c_str(), s.length(), matchlen, 0);
426 index = esc_quote.search(s.c_str(), s.length(), matchlen, 0);
427 while (index < s.length()) {
428 s.replace(index, 2, QUOTE);
429 DBG(cerr <<
"2XX" << s <<
"XXX index: " << index << endl);
430 index = esc_quote.search(s.c_str(), s.length(), matchlen, 0);
434 index = octal.search(s.c_str(), s.length(), matchlen, 0);
435 while (index < s.length()) {
436 s.replace(index, 4,
unoctstring(s.substr(index + 1, 3)));
437 DBG(cerr <<
"3XX" << s <<
"XXX index: " << index << endl);
438 index = octal.search(s.c_str(), s.length(), matchlen, 0);
441 DBG(cerr <<
"4XX" << s <<
"XXX" << endl);
449 if (*msg.begin() !=
'"')
450 msg.insert(msg.begin(),
'"');
451 if (*(msg.end() - 1) !=
'"')
455 string::iterator miter;
456 for (miter = msg.begin() + 1; miter != msg.end() - 1; miter++)
457 if (*miter ==
'"' && *(miter - 1) !=
'\\')
458 miter = msg.insert(miter,
'\\');
470 string::size_type idx = 0;
471 while((idx = source.find(
'\"', idx)) != string::npos) {
472 source.replace(idx, 1,
"\\\"");
487 string::size_type idx = 0;
488 while((idx = source.find(
"\\\"", idx)) != string::npos) {
489 source.replace(idx, 2,
"\"");
string id2www_ce(string in, const string &allowable)
string id2xml(string in, const string ¬_allowed)
string escape_double_quotes(string source)
string octal_to_hex(const string &octal_digits)
string unoctstring(string s)
string munge_error_message(string msg)
string www2id(const string &in, const string &escape, const string &except)
string esc2underscore(string s)
string unhexstring(string s)
string hexstring(unsigned char val)
string octstring(unsigned char val)
string unescattr(string s)
string id2www(string in, const string &allowable)
string unescape_double_quotes(string source)