Permalink
Browse files

Merge commit 'refs/pull/356/head' of github.com:znc/znc

  • Loading branch information...
DarthGandalf committed May 18, 2013
2 parents c3f421b + 0c37fb1 commit 9d23158aab1b380ca90447c756e8a68662f358cd
Showing with 37 additions and 2 deletions.
  1. +3 −1 include/znc/ZNCDebug.h
  2. +2 −1 include/znc/ZNCString.h
  3. +32 −0 src/ZNCString.cpp
View
@@ -30,7 +30,9 @@
*/
#define DEBUG(f) do { \
if (CDebug::Debug()) { \
- std::cout << CDebug::GetTimestamp() << f << std::endl; \
+ std::stringstream sDebug;\
+ sDebug << f;\
+ std::cout << CDebug::GetTimestamp() << CString(sDebug.str()).Escape_n(CString::EDEBUG) << std::endl; \
} \
} while (0)
View
@@ -62,7 +62,8 @@ class CString : public std::string {
EURL,
EHTML,
ESQL,
- ENAMEDFMT
+ ENAMEDFMT,
+ EDEBUG
} EEscape;
explicit CString(bool b) : std::string(b ? "true" : "false") {}
View
@@ -164,6 +164,8 @@ CString::EEscape CString::ToEscape(const CString& sEsc) {
return ESQL;
} else if (sEsc.Equals("NAMEDFMT")) {
return ENAMEDFMT;
+ } else if (sEsc.Equals("DEBUG")) {
+ return EDEBUG;
}
return EASCII;
@@ -280,6 +282,26 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
}
break;
+ case EDEBUG:
+ if (*p == '\\' && (a +3) < iLength && *(p +1) == 'x' && isxdigit(*(p +2)) && isxdigit(*(p +3))) {
+ p += 2;
+ if (isdigit(*p)) {
+ ch = (unsigned char)((*p - '0') << 4);
+ } else {
+ ch = (unsigned char)((tolower(*p) - 'a' +10) << 4);
+ }
+
+ p++;
+ if (isdigit(*p)) {
+ ch |= (unsigned char)(*p - '0');
+ } else {
+ ch |= (unsigned char)(tolower(*p) - 'a' +10);
+ }
+
+ a += 3;
+ } else {
+ ch = *p;
+ }
}
switch (eTo) {
@@ -326,6 +348,16 @@ CString CString::Escape_n(EEscape eFrom, EEscape eTo) const {
} else if (ch == '}') { sRet += '\\'; sRet += '}';
} else { sRet += ch; }
+ break;
+ case EDEBUG:
+ if (ch < 0x20 || ch == 0x7F) {
+ sRet += "\\x";
+ sRet += szHex[ch >> 4];
+ sRet += szHex[ch & 0xf];
+ } else {
+ sRet += ch;
+ }
+
break;
}
}

0 comments on commit 9d23158

Please sign in to comment.