aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/html/escape
diff options
context:
space:
mode:
authorstanly <stanly@yandex-team.ru>2022-02-10 16:46:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:49 +0300
commitcde218e65dfef5ce03a48d641fd8f7913cf17b2d (patch)
treed3349caea4095825a55b5ba24fe758067b29ce6f /library/cpp/html/escape
parent9f813499b4ef585cb3c2bb93de93ef003daf4fc4 (diff)
downloadydb-cde218e65dfef5ce03a48d641fd8f7913cf17b2d.tar.gz
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/html/escape')
-rw-r--r--library/cpp/html/escape/escape.cpp42
-rw-r--r--library/cpp/html/escape/escape.h10
-rw-r--r--library/cpp/html/escape/ut/escape_ut.cpp24
-rw-r--r--library/cpp/html/escape/ut/ya.make24
-rw-r--r--library/cpp/html/escape/ya.make16
5 files changed, 58 insertions, 58 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("&quot;")},
{'&', true, TStringBuf("&amp;")},
{'<', true, TStringBuf("&lt;")},
{'>', true, TStringBuf("&gt;")},
};
-
+
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);
}
-
-}
+
+}
diff --git a/library/cpp/html/escape/escape.h b/library/cpp/html/escape/escape.h
index 1c45fc5193..cb9b0c860c 100644
--- a/library/cpp/html/escape/escape.h
+++ b/library/cpp/html/escape/escape.h
@@ -1,9 +1,9 @@
-#pragma once
-
+#pragma once
+
#include <util/generic/string.h>
-
-namespace NHtml {
+
+namespace NHtml {
TString EscapeAttributeValue(const TString& value);
TString EscapeText(const TString& value);
-
+
}
diff --git a/library/cpp/html/escape/ut/escape_ut.cpp b/library/cpp/html/escape/ut/escape_ut.cpp
index cd7b955138..436f3b6a28 100644
--- a/library/cpp/html/escape/ut/escape_ut.cpp
+++ b/library/cpp/html/escape/ut/escape_ut.cpp
@@ -1,16 +1,16 @@
#include <library/cpp/html/escape/escape.h>
#include <library/cpp/testing/unittest/registar.h>
-
-using namespace NHtml;
-
+
+using namespace NHtml;
+
Y_UNIT_TEST_SUITE(TEscapeHtml) {
Y_UNIT_TEST(Escape) {
- UNIT_ASSERT_EQUAL(EscapeText("in & out"), "in &amp; out");
- UNIT_ASSERT_EQUAL(EscapeText("&&"), "&amp;&amp;");
- UNIT_ASSERT_EQUAL(EscapeText("&amp;"), "&amp;amp;");
-
- UNIT_ASSERT_EQUAL(EscapeText("<script>"), "&lt;script&gt;");
-
- UNIT_ASSERT_EQUAL(EscapeText("text"), "text");
- }
-}
+ UNIT_ASSERT_EQUAL(EscapeText("in & out"), "in &amp; out");
+ UNIT_ASSERT_EQUAL(EscapeText("&&"), "&amp;&amp;");
+ UNIT_ASSERT_EQUAL(EscapeText("&amp;"), "&amp;amp;");
+
+ UNIT_ASSERT_EQUAL(EscapeText("<script>"), "&lt;script&gt;");
+
+ UNIT_ASSERT_EQUAL(EscapeText("text"), "text");
+ }
+}
diff --git a/library/cpp/html/escape/ut/ya.make b/library/cpp/html/escape/ut/ya.make
index 27d3a3d65a..4a0e12388d 100644
--- a/library/cpp/html/escape/ut/ya.make
+++ b/library/cpp/html/escape/ut/ya.make
@@ -1,13 +1,13 @@
-UNITTEST()
-
-OWNER(stanly)
-
-SRCS(
- escape_ut.cpp
-)
-
-PEERDIR(
+UNITTEST()
+
+OWNER(stanly)
+
+SRCS(
+ escape_ut.cpp
+)
+
+PEERDIR(
library/cpp/html/escape
-)
-
-END()
+)
+
+END()
diff --git a/library/cpp/html/escape/ya.make b/library/cpp/html/escape/ya.make
index 93a31e33d6..980481dfae 100644
--- a/library/cpp/html/escape/ya.make
+++ b/library/cpp/html/escape/ya.make
@@ -1,9 +1,9 @@
-LIBRARY()
+LIBRARY()
-OWNER(stanly)
-
-SRCS(
- escape.cpp
-)
-
-END()
+OWNER(stanly)
+
+SRCS(
+ escape.cpp
+)
+
+END()