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);
214 www2id(
const string &in,
const string &escape,
const string &except)
216 string::size_type i = 0;
218 while ((i = res.find_first_of(escape, i)) != string::npos) {
219 if (except.find(res.substr(i, 3)) != string::npos) {
223 res.replace(i, 3,
unhexstring(res.substr(i + 1, 2)));
234 case '>':
return ">";
235 case '<':
return "<";
236 case '&':
return "&";
237 case '\'':
return "'";
238 case '\"':
return """;
240 throw InternalErr(__FILE__, __LINE__,
"Unrecognized character.");
251 istringstream ss(octal_digits);
255 ds << hex << setw(2) << setfill(
'0') << val;
266 id2xml(
string in,
const string ¬_allowed)
268 string::size_type i = 0;
270 while ((i = in.find_first_of(not_allowed, i)) != string::npos) {
271 in.replace(i, 1, entity(in[i]));
286 string octal_escape =
"\\\\";
288 string::size_type length = in.length();
289 while ((i = in.find(octal_escape, i)) != string::npos) {
291 string::size_type j = i + 2;
294 string octal_digits = in.substr(j, 3);
296 string hex_escape = string(
"&#x");
298 hex_escape.append(
string(
";"));
301 in.replace(i, 5, hex_escape);
318 string::size_type i = 0;
320 while ((i = in.find(
">", i)) != string::npos)
321 in.replace(i, 4,
">");
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, 5,
"&");
332 while ((i = in.find(
"'", i)) != string::npos)
333 in.replace(i, 6,
"'");
336 while ((i = in.find(
""", i)) != string::npos)
337 in.replace(i, 6,
"\"");
350 string::size_type pos;
351 while ((pos = s.find(
'%')) != string::npos)
352 s.replace(pos, 3,
"_");
364 const string printable =
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={[}]|\\:;<,>.?/'\"";
365 const string ESC =
"\\";
366 const string DOUBLE_ESC = ESC + ESC;
367 const string QUOTE =
"\"";
368 const string ESCQUOTE = ESC + QUOTE;
371 string::size_type ind = 0;
372 while ((ind = s.find_first_not_of(printable, ind)) != s.npos)
373 s.replace(ind, 1, ESC +
octstring(s[ind]));
377 while ((ind = s.find(ESC, ind)) != s.npos) {
378 s.replace(ind, 1, DOUBLE_ESC);
379 ind += DOUBLE_ESC.length();
384 while ((ind = s.find(QUOTE, ind)) != s.npos) {
385 s.replace(ind, 1, ESCQUOTE);
386 ind += ESCQUOTE.length();
403 Regex octal(
"\\\\[0-3][0-7][0-7]");
404 Regex esc_quote(
"\\\\\"");
405 Regex esc_esc(
"\\\\\\\\");
406 const string ESC =
"\\";
407 const string QUOTE =
"\"";
411 DBG(cerr <<
"0XX" << s <<
"XXX" << endl);
413 index = esc_esc.search(s.c_str(), s.length(), matchlen, 0);
414 while (index < s.length()) {
415 DBG(cerr <<
"1aXX" << s <<
"XXX index: " << index << endl);
416 s.replace(index, 2, ESC);
417 DBG(cerr <<
"1bXX" << s <<
"XXX index: " << index << endl);
418 index = esc_esc.search(s.c_str(), s.length(), matchlen, 0);
422 index = esc_quote.search(s.c_str(), s.length(), matchlen, 0);
423 while (index < s.length()) {
424 s.replace(index, 2, QUOTE);
425 DBG(cerr <<
"2XX" << s <<
"XXX index: " << index << endl);
426 index = esc_quote.search(s.c_str(), s.length(), matchlen, 0);
430 index = octal.search(s.c_str(), s.length(), matchlen, 0);
431 while (index < s.length()) {
432 s.replace(index, 4,
unoctstring(s.substr(index + 1, 3)));
433 DBG(cerr <<
"3XX" << s <<
"XXX index: " << index << endl);
434 index = octal.search(s.c_str(), s.length(), matchlen, 0);
437 DBG(cerr <<
"4XX" << s <<
"XXX" << endl);
445 if (*msg.begin() !=
'"')
446 msg.insert(msg.begin(),
'"');
447 if (*(msg.end() - 1) !=
'"')
451 string::iterator miter;
452 for (miter = msg.begin() + 1; miter != msg.end() - 1; miter++)
453 if (*miter ==
'"' && *(miter - 1) !=
'\\')
454 miter = msg.insert(miter,
'\\');
466 string::size_type idx = 0;
467 while((idx = source.find(
'\"', idx)) != string::npos) {
468 source.replace(idx, 1,
"\\\"");
483 string::size_type idx = 0;
484 while((idx = source.find(
"\\\"", idx)) != string::npos) {
485 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)
A class for software fault reporting.
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)