blob: e2f0fe7931717ca927e8065396d94647ab50a0c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "ACEXML/common/XML_Util.h"
static const ACEXML_Char ESCAPED_AMP[] = ACE_TEXT("&");
static const ACEXML_Char ESCAPED_LESS[] = ACE_TEXT("<");
static const ACEXML_Char ESCAPED_GREATER[] = ACE_TEXT(">");
static const ACEXML_Char ESCAPED_APOS[] = ACE_TEXT("'");
static const ACEXML_Char ESCAPED_QUOTE[] = ACE_TEXT(""");
#define CSTRLEN(x) ((sizeof(x) / sizeof(ACEXML_Char)) - 1)
ACEXML_String ACEXML_escape_string(const ACEXML_String& str)
{
ACEXML_String ret(str.length ());
ACEXML_escape_string(str, ret);
return ret;
}
void ACEXML_escape_string(const ACEXML_String& in, ACEXML_String& out)
{
size_t len = in.length ();
out.clear();
for (size_t stridx = 0; stridx < len; ++stridx)
{
switch (in[stridx]) {
case '&':
out.append(ESCAPED_AMP, CSTRLEN(ESCAPED_AMP));
break;
case '<':
out.append(ESCAPED_LESS, CSTRLEN(ESCAPED_LESS));
break;
case '>':
out.append(ESCAPED_GREATER, CSTRLEN(ESCAPED_GREATER));
break;
case '\'':
out.append(ESCAPED_APOS, CSTRLEN(ESCAPED_APOS));
break;
case '\"':
out.append(ESCAPED_QUOTE, CSTRLEN(ESCAPED_QUOTE));
break;
default:
out += in[stridx];
}
}
}
|