本文整理汇总了C++中CString::Escape_n方法的典型用法代码示例。如果您正苦于以下问题:C++ CString::Escape_n方法的具体用法?C++ CString::Escape_n怎么用?C++ CString::Escape_n使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CString
的用法示例。
在下文中一共展示了CString::Escape_n方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PrintErrorPage
bool CHTTPSock::PrintErrorPage(unsigned int uStatusId,
const CString& sStatusMsg,
const CString& sMessage) {
if (SentHeader()) {
DEBUG("PrintErrorPage(): Header was already sent");
return false;
}
CString sPage =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
"<!DOCTYPE html>\r\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" "
"xml:lang=\"en\">\r\n"
"<head>\r\n"
"<meta charset=\"UTF-8\"/>\r\n"
"<title>" +
CString(uStatusId) + " " + sStatusMsg.Escape_n(CString::EHTML) +
"</title>\r\n"
"</head>\r\n"
"<body>\r\n"
"<h1>" +
sStatusMsg.Escape_n(CString::EHTML) +
"</h1>\r\n"
"<p>" +
sMessage.Escape_n(CString::EHTML) +
"</p>\r\n"
"<hr/>\r\n"
"<p>" +
CZNC::GetTag(false, /* bHTML = */ true) +
"</p>\r\n"
"</body>\r\n"
"</html>\r\n";
PrintHeader(sPage.length(), "text/html; charset=utf-8", uStatusId,
sStatusMsg);
Write(sPage);
Close(Csock::CLT_AFTERWRITE);
return true;
}
示例2: Redirect
bool CHTTPSock::Redirect(const CString& sURL) {
if (SentHeader()) {
DEBUG("Redirect() - Header was already sent");
return false;
} else if(!sURL.StartsWith("/")) {
// HTTP/1.1 only admits absolute URIs for the Location header.
DEBUG("Redirect to relative URI [" + sURL + "] is not allowed.");
return false;
} else {
CString location = m_sURIPrefix + sURL;
DEBUG("- Redirect to [" << location << "] with prefix [" + m_sURIPrefix + "]");
AddHeader("Location", location);
PrintErrorPage(302, "Found", "The document has moved <a href=\"" + location.Escape_n(CString::EHTML) + "\">here</a>.");
return true;
}
}
示例3: ConvertCharset
bool ConvertCharset(const VCString& vsFrom, const CString& sTo, CString& sData)
{
CString sDataCopy(sData);
if(!m_bForce)
{
// check whether sData already is encoded with the right charset:
iconv_t icTest = iconv_open(sTo.c_str(), sTo.c_str());
if(icTest != (iconv_t)-1)
{
size_t uTest = GetConversionLength(icTest, sData);
iconv_close(icTest);
if(uTest != (size_t)-1 && uTest != (size_t)-2)
{
DEBUG("charset: [" + sData.Escape_n(CString::EURL) + "] is valid [" + sTo + "] already.");
return true;
}
}
}
bool bConverted = false;
// try all possible source charsets:
for(VCString::const_iterator itf = vsFrom.begin(); itf != vsFrom.end(); ++itf)
{
if(ConvertCharset(*itf, sTo, sDataCopy))
{
// conversion successful!
sData = sDataCopy;
bConverted = true;
break;
}
else
{
// reset string and try the next charset:
sDataCopy = sData;
}
}
return bConverted;
}
示例4: testString
static int testString(const CString& in, const CString& url,
const CString& html, const CString& sql) {
CString out;
int errors = 0;
// Encode, then decode again and check we still got the same string
out = in.Escape_n(CString::EASCII, CString::EURL);
errors += testEqual(out, url, "EURL encode");
out = out.Escape_n(CString::EURL, CString::EASCII);
errors += testEqual(out, in, "EURL decode");
out = in.Escape_n(CString::EASCII, CString::EHTML);
errors += testEqual(out, html, "EHTML encode");
out = out.Escape_n(CString::EHTML, CString::EASCII);
errors += testEqual(out, in, "EHTML decode");
out = in.Escape_n(CString::EASCII, CString::ESQL);
errors += testEqual(out, sql, "ESQL encode");
out = out.Escape_n(CString::ESQL, CString::EASCII);
errors += testEqual(out, in, "ESQL decode");
return errors;
}
示例5: urlencode
/**
* Shorthand for encoding a string for a URL.
*
* @param str String to be encoded
* @return Encoded string
*/
CString urlencode(const CString& str)
{
return str.Escape_n(CString::EASCII, CString::EURL);
}
示例6: PrintTo
// GTest uses this function to output objects
void PrintTo(const CString& s, std::ostream* o) {
*o << '"' << s.Escape_n(CString::EASCII, CString::EDEBUG) << '"';
}
示例7: Print
//.........这里部分代码省略.........
for (MCString::iterator it = msRow.begin(); it != msRow.end(); ++it) {
NewRow[it->first] = it->second;
}
}
} else if (sAction.Equals("SET")) {
CString sName = sArgs.Token(0);
CString sValue = sArgs.Token(1, true);
(*this)[sName] = sValue;
} else if (sAction.Equals("JOIN")) {
VCString vsArgs;
//sArgs.Split(" ", vsArgs, false, "\"", "\"");
sArgs.QuoteSplit(vsArgs);
if (vsArgs.size() > 1) {
CString sDelim = vsArgs[0];
bool bFoundOne = false;
CString::EEscape eEscape = CString::EASCII;
for (unsigned int a = 1; a < vsArgs.size(); a++) {
const CString& sArg = vsArgs[a];
if (sArg.Equals("ESC=", false, 4)) {
eEscape = CString::ToEscape(sArg.LeftChomp_n(4));
} else {
CString sValue = GetValue(sArg);
if (!sValue.empty()) {
if (bFoundOne) {
sOutput += sDelim;
}
sOutput += sValue.Escape_n(eEscape);
bFoundOne = true;
}
}
}
}
} else if (sAction.Equals("SETBLOCK")) {
sSetBlockVar = sArgs;
bInSetBlock = true;
} else if (sAction.Equals("EXPAND")) {
sOutput += ExpandFile(sArgs, true);
} else if (sAction.Equals("VAR")) {
sOutput += GetValue(sArgs);
} else if (sAction.Equals("LT")) {
sOutput += "<?";
} else if (sAction.Equals("GT")) {
sOutput += "?>";
} else if (sAction.Equals("CONTINUE")) {
CTemplateLoopContext* pContext = GetCurLoopContext();
if (pContext) {
uSkip++;
bLoopCont = true;
break;
} else {
DEBUG("[" + sFileName + ":" + CString(uCurPos - iPos2 -4) + "] <? CONTINUE ?> must be used inside of a loop!");
}
} else if (sAction.Equals("BREAK")) {
// break from loop
CTemplateLoopContext* pContext = GetCurLoopContext();
if (pContext) {
示例8: StripHTML
static CString StripHTML(const CString& sFrom)
{
CString sResult = sFrom;
// remove tags:
CString::size_type pos = sResult.find('<');
while(pos != CString::npos)
{
CString::size_type endPos = sResult.find('>', pos);
if(endPos != CString::npos)
{
sResult.erase(pos, endPos - pos + 1);
pos = sResult.find('<', pos);
}
else
{
sResult.erase(pos);
break;
}
}
// remove stupid legay HTML entities:
pos = sResult.find('&');
while(pos != CString::npos)
{
CString::size_type endPos = sResult.find(';', pos);
if(endPos != CString::npos)
{
bool found = false;
for(unsigned int c = 0; c < 256; c++)
{
if(g_szHTMLescapes[c] && !strncasecmp(g_szHTMLescapes[c], (char*)(sResult.c_str() + pos), endPos - pos + 1))
{
sResult.erase(pos, endPos - pos + 1);
sResult.insert(pos, 1, (char)c);
found = true;
break;
}
}
if(!found && sResult[pos + 1] != '#')
sResult.erase(pos, endPos - pos + 1);
pos = sResult.find('&', pos + 1);
}
else
break;
}
// remove numerical and XML entities:
sResult = sResult.Escape_n(CString::EHTML, CString::EASCII);
// because entitiy decoding is being done in two steps,
// this screws up in certain situations, e.g. &gt;
// produces '>' instead of '>' ... but whatever.
// normalize whitespace:
RE("\\s+").GlobalReplace(" ", &sResult);
sResult.Trim();
return sResult;
}