For use in projects, do not use functions in C ++ for calling.
// Testcreatesrandkey. cpp: Defines the entry point for the console application.
//
# Include "stdafx. h"
# Include <windows. h>
# Include <string>
# Include <iostream>
Using namespace std;
Void XmlEncode (const string & strSrc, string & strDest)
{
For (int I = 0; I <strSrc. length (); I ++)
{
Char c = strSrc [I];
Switch (c)
{
Case '&':
StrDest. append ("& amp ;");
Break;
Case '<':
StrDest. append ("& lt ;");
Break;
Case '> ':
StrDest. append ("& gt ;");
Break;
Case '"':
StrDest. append ("& quot ;");
Break;
Case '/'':
StrDest. append ("& apos ;");
Break;
Default:
{
Char p [2];
P [0] = c;
P [1] = 0;
StrDest. append (p );
Break;
}
}
}
}
Void XmlDecode (const string & strSrc, string & strDest)
{
For (int I = 0; I <strSrc. length (); I ++)
{
Char c = strSrc [I];
Switch (c)
{
Case '&':
{
If (strSrc [I + 1] = 'l') & (strSrc [I + 2]) = 'T' & (strSrc [I + 3]) = ';')
{
StrDest. append ("<");
I + = 3;
}
Else if (strSrc [I + 1] = 'G') & (strSrc [I + 2]) = 'T' & (strSrc [I + 3]) = ';')
{
StrDest. append ("> ");
I + = 3;
}
Else if (strsrc [I + 1] = 'A') & (strsrc [I + 2]) = 'M' & (strsrc [I + 3]) = 'P' & (strsrc [I + 4]) = ';')
{
Strdest. append ("&");
I + = 4;
}
Else if (strsrc [I + 1] = 'q' & strsrc [I + 2] = 'U' & strsrc [I + 3] = 'O' & strsrc [I + 4] = 'T' & strsrc [I + 5] = '; ')
{
Strdest. append ("/"");
I + = 5;
}
Else if (strSrc [I + 1] = 'A' & strSrc [I + 2] = 'P' & strSrc [I + 3] = 'O' & strSrc [I + 4] = 's' & strSrc [I + 5] = '; ')
{
StrDest. append ("'");
I + = 5;
}
Break;
}
Default:
{
Char p [2];
P [0] = c;
P [1] = 0;
StrDest. append (p );
Break;
}
}
}
}
Int main (INT argc, char * argv [])
{
/*
String strtest;
For (INT I = 0; I <128; I ++)
{
// Sleep (1 );
Char P [2];
P [0] = static_cast <unsigned char> (I );
P [1] = 0;
Strtest = strtest + P;
Cout <strtest. c_str () <Endl;
}
*/
String strtest = "t // _ Q. T. Gj * <;. ro ^-} jy7 ";
String strencode;
Cout <strtest. c_str () <Endl;
Xmlencode (strtest, strencode );
Cout <strencode. c_str () <Endl;
Strencode = strtest;
String strsrc;
XmlDecode (strEncode, strSrc );
Cout <strSrc. c_str () <endl;
Cout <strSrc. length () <endl;
Return 0;
}