From cde218e65dfef5ce03a48d641fd8f7913cf17b2d Mon Sep 17 00:00:00 2001 From: stanly Date: Thu, 10 Feb 2022 16:46:49 +0300 Subject: Restoring authorship annotation for . Commit 1 of 2. --- library/cpp/html/escape/escape.cpp | 42 ++++++++++++++++---------------- library/cpp/html/escape/escape.h | 10 ++++---- library/cpp/html/escape/ut/escape_ut.cpp | 24 +++++++++--------- library/cpp/html/escape/ut/ya.make | 24 +++++++++--------- library/cpp/html/escape/ya.make | 16 ++++++------ 5 files changed, 58 insertions(+), 58 deletions(-) (limited to 'library/cpp/html') diff --git a/library/cpp/html/escape/escape.cpp b/library/cpp/html/escape/escape.cpp index 5b8ed60f045..f6fc8dbb208 100644 --- a/library/cpp/html/escape/escape.cpp +++ b/library/cpp/html/escape/escape.cpp @@ -1,23 +1,23 @@ -#include "escape.h" - -#include -#include - -namespace NHtml { +#include "escape.h" + +#include +#include + +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); } - -} + +} diff --git a/library/cpp/html/escape/escape.h b/library/cpp/html/escape/escape.h index 1c45fc51933..cb9b0c860c4 100644 --- a/library/cpp/html/escape/escape.h +++ b/library/cpp/html/escape/escape.h @@ -1,9 +1,9 @@ -#pragma once - +#pragma once + #include - -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 cd7b9551385..436f3b6a283 100644 --- a/library/cpp/html/escape/ut/escape_ut.cpp +++ b/library/cpp/html/escape/ut/escape_ut.cpp @@ -1,16 +1,16 @@ #include #include - -using namespace NHtml; - + +using namespace NHtml; + Y_UNIT_TEST_SUITE(TEscapeHtml) { Y_UNIT_TEST(Escape) { - UNIT_ASSERT_EQUAL(EscapeText("in & out"), "in & out"); - UNIT_ASSERT_EQUAL(EscapeText("&&"), "&&"); - UNIT_ASSERT_EQUAL(EscapeText("&"), "&amp;"); - - UNIT_ASSERT_EQUAL(EscapeText("