aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/string_utils/quote/quote.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/string_utils/quote/quote.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils/quote/quote.cpp')
-rw-r--r--library/cpp/string_utils/quote/quote.cpp178
1 files changed, 89 insertions, 89 deletions
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp
index e523350b80..02bcfaa6e1 100644
--- a/library/cpp/string_utils/quote/quote.cpp
+++ b/library/cpp/string_utils/quote/quote.cpp
@@ -1,18 +1,18 @@
-#include "quote.h"
-
-#include <util/memory/tempbuf.h>
+#include "quote.h"
+
+#include <util/memory/tempbuf.h>
#include <util/string/ascii.h>
#include <util/string/cstriter.h>
-#include <cctype>
-
+#include <cctype>
+
/* note: (x & 0xdf) makes x upper case */
-#define GETXC \
- do { \
- c *= 16; \
- c += (x[0] >= 'A' ? ((x[0] & 0xdf) - 'A') + 10 : (x[0] - '0')); \
- ++x; \
- } while (0)
+#define GETXC \
+ do { \
+ c *= 16; \
+ c += (x[0] >= 'A' ? ((x[0] & 0xdf) - 'A') + 10 : (x[0] - '0')); \
+ ++x; \
+ } while (0)
#define GETSBXC \
do { \
@@ -25,18 +25,18 @@
namespace {
class TFromHexZeroTerm {
public:
- static inline char x2c(const char*& x) {
- if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
+ static inline char x2c(const char*& x) {
+ if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
return '%';
ui8 c = 0;
- GETXC;
- GETXC;
+ GETXC;
+ GETXC;
return c;
}
- static inline char x2c(TStringBuf& x) {
- if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
+ static inline char x2c(TStringBuf& x) {
+ if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
return '%';
ui8 c = 0;
@@ -53,7 +53,7 @@ namespace {
{
}
- inline char x2c(const char*& x) {
+ inline char x2c(const char*& x) {
if (x + 2 > End)
return '%';
return TFromHexZeroTerm::x2c(x);
@@ -64,80 +64,80 @@ namespace {
};
}
-static inline char d2x(unsigned x) {
- return (char)((x < 10) ? ('0' + x) : ('A' + x - 10));
+static inline char d2x(unsigned x) {
+ return (char)((x < 10) ? ('0' + x) : ('A' + x - 10));
}
static inline const char* FixZero(const char* s) noexcept {
- return s ? s : "";
-}
-
+ return s ? s : "";
+}
+
// we escape:
-// '\"', '|', '(', ')',
+// '\"', '|', '(', ')',
// '%', '&', '+', ',',
-// '#', '<', '=', '>',
+// '#', '<', '=', '>',
// '[', '\\',']', '?',
// ':', '{', '}',
// all below ' ' (0x20) and above '~' (0x7E).
// ' ' converted to '+'
static const bool chars_to_url_escape[256] = {
- // 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //0
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //1
- 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, //2
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, //3
-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //4
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, //5
- 1, 0, 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, //8
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //9
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //A
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //B
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //C
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //D
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //E
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //F
};
-template <class It1, class It2, class It3>
-static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = chars_to_url_escape) {
- while (from != end) {
+template <class It1, class It2, class It3>
+static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = chars_to_url_escape) {
+ while (from != end) {
if (escape_map[(unsigned char)*from]) {
*to++ = '%';
- *to++ = d2x((unsigned char)*from >> 4);
- *to++ = d2x((unsigned char)*from & 0xF);
+ *to++ = d2x((unsigned char)*from >> 4);
+ *to++ = d2x((unsigned char)*from & 0xF);
} else {
*to++ = (*from == ' ' ? '+' : *from);
}
-
+
++from;
}
-
+
*to = 0;
-
+
return to;
}
template <class It1, class It2, class It3, class FromHex>
static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) {
- (void)fromHex;
-
+ (void)fromHex;
+
while (from != end) {
switch (*from) {
- case '%':
+ case '%':
++from;
- *to++ = fromHex.x2c(from);
- break;
- case '+':
- *to++ = ' ';
+ *to++ = fromHex.x2c(from);
+ break;
+ case '+':
+ *to++ = ' ';
++from;
- break;
- default:
- *to++ = *from++;
+ break;
+ default:
+ *to++ = *from++;
}
}
*to = 0;
@@ -147,18 +147,18 @@ static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) {
// CGIEscape returns pointer to the end of the result string
// so as it could be possible to populate single long buffer
// with several calls to CGIEscape in a row.
-char* CGIEscape(char* to, const char* from) {
- return Escape(to, FixZero(from), TCStringEndIterator());
-}
-
-char* CGIEscape(char* to, const char* from, size_t len) {
- return Escape(to, from, from + len);
+char* CGIEscape(char* to, const char* from) {
+ return Escape(to, FixZero(from), TCStringEndIterator());
}
+char* CGIEscape(char* to, const char* from, size_t len) {
+ return Escape(to, from, from + len);
+}
+
void CGIEscape(TString& url) {
TTempBuf tempBuf(CgiEscapeBufLen(url.size()));
- char* to = tempBuf.Data();
-
+ char* to = tempBuf.Data();
+
url.AssignNoAlias(to, CGIEscape(to, url.data(), url.size()));
}
@@ -178,7 +178,7 @@ TString& AppendCgiEscaped(const TStringBuf value, TString& to) {
// More general version of CGIEscape. The optional safe parameter specifies
// additional characters that should not be quoted — its default value is '/'.
-
+
// Also returns pointer to the end of result string.
template <class It1, class It2, class It3>
@@ -210,14 +210,14 @@ char* Quote(char* to, const TStringBuf s, const char* safe) {
void Quote(TString& url, const char* safe) {
TTempBuf tempBuf(CgiEscapeBufLen(url.size()));
char* to = tempBuf.Data();
-
+
url.AssignNoAlias(to, Quote(to, url, safe));
}
-char* CGIUnescape(char* to, const char* from) {
+char* CGIUnescape(char* to, const char* from) {
return Unescape(to, FixZero(from), TCStringEndIterator(), TFromHexZeroTerm());
}
-
+
char* CGIUnescape(char* to, const char* from, size_t len) {
return Unescape(to, from, from + len, TFromHexLenLimited(from + len));
}
@@ -250,10 +250,10 @@ char* UrlUnescape(char* to, TStringBuf from) {
ch = TFromHexZeroTerm::x2c(from);
*to++ = ch;
}
-
+
*to = 0;
-
- return to;
+
+ return to;
}
void UrlUnescape(TString& url) {
@@ -277,29 +277,29 @@ TString UrlUnescapeRet(const TStringBuf from) {
}
char* UrlEscape(char* to, const char* from, bool forceEscape) {
- from = FixZero(from);
-
- while (*from) {
+ from = FixZero(from);
+
+ while (*from) {
const bool escapePercent = (*from == '%') &&
(forceEscape || !((*(from + 1) && IsAsciiHex(*(from + 1)) && *(from + 2) && IsAsciiHex(*(from + 2)))));
if (escapePercent || (unsigned char)*from <= ' ' || (unsigned char)*from > '~') {
- *to++ = '%';
- *to++ = d2x((unsigned char)*from >> 4);
- *to++ = d2x((unsigned char)*from & 0xF);
- } else
+ *to++ = '%';
+ *to++ = d2x((unsigned char)*from >> 4);
+ *to++ = d2x((unsigned char)*from & 0xF);
+ } else
*to++ = *from;
++from;
}
-
+
*to = 0;
-
- return to;
+
+ return to;
}
void UrlEscape(TString& url, bool forceEscape) {
TTempBuf tempBuf(CgiEscapeBufLen(url.size()));
- char* to = tempBuf.Data();
+ char* to = tempBuf.Data();
url.AssignNoAlias(to, UrlEscape(to, url.data(), forceEscape));
}