diff options
author | stanly <stanly@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | cde218e65dfef5ce03a48d641fd8f7913cf17b2d (patch) | |
tree | d3349caea4095825a55b5ba24fe758067b29ce6f /library/cpp/html/escape/escape.cpp | |
parent | 9f813499b4ef585cb3c2bb93de93ef003daf4fc4 (diff) | |
download | ydb-cde218e65dfef5ce03a48d641fd8f7913cf17b2d.tar.gz |
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/html/escape/escape.cpp')
-rw-r--r-- | library/cpp/html/escape/escape.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/library/cpp/html/escape/escape.cpp b/library/cpp/html/escape/escape.cpp index 5b8ed60f04..f6fc8dbb20 100644 --- a/library/cpp/html/escape/escape.cpp +++ b/library/cpp/html/escape/escape.cpp @@ -1,23 +1,23 @@ -#include "escape.h" - -#include <util/generic/array_size.h> -#include <util/generic/strbuf.h> - -namespace NHtml { +#include "escape.h" + +#include <util/generic/array_size.h> +#include <util/generic/strbuf.h> + +namespace NHtml { namespace { struct TReplace { char Char; bool ForText; TStringBuf Entity; }; - + TReplace Escapable[] = { {'"', false, TStringBuf(""")}, {'&', true, TStringBuf("&")}, {'<', true, TStringBuf("<")}, {'>', true, TStringBuf(">")}, }; - + TString EscapeImpl(const TString& value, bool isText) { auto ci = value.begin(); // Looking for escapable characters. @@ -27,17 +27,17 @@ namespace NHtml { goto escape; } } - } - + } + // There is no escapable characters, so return original value. return value; - + escape: TString tmp = TString(value.begin(), ci); - + for (; ci != value.end(); ++ci) { size_t i = (isText ? 1 : 0); - + for (; i < Y_ARRAY_SIZE(Escapable); ++i) { if (*ci == Escapable[i].Char) { tmp += Escapable[i].Entity; @@ -48,19 +48,19 @@ namespace NHtml { if (i == Y_ARRAY_SIZE(Escapable)) { tmp += *ci; } - } + } return tmp; - } - - } - + } + + } + TString EscapeAttributeValue(const TString& value) { return EscapeImpl(value, false); } - + TString EscapeText(const TString& value) { return EscapeImpl(value, true); } - -} + +} |