diff options
| author | Ruslan Kovalev <[email protected]> | 2022-02-10 16:46:44 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:44 +0300 | 
| commit | 59e19371de37995fcb36beb16cd6ec030af960bc (patch) | |
| tree | fa68e36093ebff8b805462e9e6d331fe9d348214 /library/cpp/string_utils | |
| parent | 89db6fe2fe2c32d2a832ddfeb04e8d078e301084 (diff) | |
Restoring authorship annotation for Ruslan Kovalev <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/string_utils')
| -rw-r--r-- | library/cpp/string_utils/base64/base64.h | 2 | ||||
| -rw-r--r-- | library/cpp/string_utils/base64/fuzz/uneven/main.cpp | 20 | ||||
| -rw-r--r-- | library/cpp/string_utils/base64/fuzz/uneven/ya.make | 30 | ||||
| -rw-r--r-- | library/cpp/string_utils/base64/fuzz/ya.make | 2 | ||||
| -rw-r--r-- | library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h | 2 | ||||
| -rw-r--r-- | library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h | 76 | ||||
| -rw-r--r-- | library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp | 76 | ||||
| -rw-r--r-- | library/cpp/string_utils/url/url.cpp | 8 | ||||
| -rw-r--r-- | library/cpp/string_utils/url/url.h | 4 | ||||
| -rw-r--r-- | library/cpp/string_utils/url/url_ut.cpp | 8 | 
10 files changed, 114 insertions, 114 deletions
| diff --git a/library/cpp/string_utils/base64/base64.h b/library/cpp/string_utils/base64/base64.h index f778a6425aa..ba7e90b144a 100644 --- a/library/cpp/string_utils/base64/base64.h +++ b/library/cpp/string_utils/base64/base64.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once   #include <util/system/defaults.h>  #include <util/generic/strbuf.h> diff --git a/library/cpp/string_utils/base64/fuzz/uneven/main.cpp b/library/cpp/string_utils/base64/fuzz/uneven/main.cpp index 915e81a7e5e..9e1e934e09d 100644 --- a/library/cpp/string_utils/base64/fuzz/uneven/main.cpp +++ b/library/cpp/string_utils/base64/fuzz/uneven/main.cpp @@ -1,10 +1,10 @@ -#include <library/cpp/string_utils/base64/base64.h> - -#include <util/system/types.h> -#include <util/system/yassert.h> - -extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { -    const TStringBuf example{reinterpret_cast<const char*>(data), size}; -    Y_UNUSED(Base64DecodeUneven(example)); -    return 0; -} +#include <library/cpp/string_utils/base64/base64.h>  +  +#include <util/system/types.h>  +#include <util/system/yassert.h>  +  +extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) {  +    const TStringBuf example{reinterpret_cast<const char*>(data), size};  +    Y_UNUSED(Base64DecodeUneven(example));  +    return 0;  +}  diff --git a/library/cpp/string_utils/base64/fuzz/uneven/ya.make b/library/cpp/string_utils/base64/fuzz/uneven/ya.make index 18cb18ef52f..5ebcb21ecfb 100644 --- a/library/cpp/string_utils/base64/fuzz/uneven/ya.make +++ b/library/cpp/string_utils/base64/fuzz/uneven/ya.make @@ -1,15 +1,15 @@ -FUZZ() - -OWNER( -    g:util -) - -SRCS( -    main.cpp -) - -PEERDIR( -    library/cpp/string_utils/base64 -) - -END() +FUZZ()  +  +OWNER(  +    g:util  +)  +  +SRCS(  +    main.cpp  +)  +  +PEERDIR(  +    library/cpp/string_utils/base64  +)  +  +END()  diff --git a/library/cpp/string_utils/base64/fuzz/ya.make b/library/cpp/string_utils/base64/fuzz/ya.make index bef82061c46..b4e427326dc 100644 --- a/library/cpp/string_utils/base64/fuzz/ya.make +++ b/library/cpp/string_utils/base64/fuzz/ya.make @@ -6,5 +6,5 @@ OWNER(  RECURSE(      generic      lib -    uneven +    uneven   ) diff --git a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h index 8a240bfed8f..0dd8e492517 100644 --- a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h +++ b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once   #include <util/draft/matrix.h>  #include <util/generic/algorithm.h> diff --git a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h index d7ea7c12596..97d2a48fd0d 100644 --- a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h +++ b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h @@ -1,14 +1,14 @@ -#pragma once - -#include <util/stream/output.h> -#include <util/string/escape.h> +#pragma once  +  +#include <util/stream/output.h>  +#include <util/string/escape.h>   #include <util/memory/tempbuf.h>  #include <util/generic/strbuf.h> - -namespace NEscJ { +  +namespace NEscJ {       // almost copypaste from util/string/escape.h      // todo: move there (note difference in IsPrintable and handling of string) - +       inline char HexDigit(char value) {          if (value < 10)              return '0' + value; @@ -17,32 +17,32 @@ namespace NEscJ {      }      inline char OctDigit(char value) { -        return '0' + value; +        return '0' + value;       } - +       inline bool IsUTF8(ui8 c) {          return c < 0xf5 && c != 0xC0 && c != 0xC1;      } - +       inline bool IsControl(ui8 c) {          return c < 0x20 || c == 0x7f;      } - +       inline bool IsPrintable(ui8 c) {          return IsUTF8(c) && !IsControl(c);      } - +       inline bool IsHexDigit(ui8 c) {          return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');      } - +       inline bool IsOctDigit(ui8 c) {          return c >= '0' && c <= '7';      } - +       struct TEscapeUtil {          static const size_t ESCAPE_C_BUFFER_SIZE = 6; - +           template <bool asunicode>          static inline size_t EscapeJ(ui8 c, ui8 next, char r[ESCAPE_C_BUFFER_SIZE], TStringBuf safe, TStringBuf unsafe) {              // (1) Printable characters go as-is, except backslash and double quote. @@ -109,88 +109,88 @@ namespace NEscJ {                  return 4;              }          } - +           static inline size_t EscapeJ(ui8 c, ui8 next, char r[ESCAPE_C_BUFFER_SIZE], TStringBuf safe, TStringBuf unsafe) {              return EscapeJ<false>(c, next, r, safe, unsafe); -        } +        }       };      inline size_t SuggestBuffer(size_t len) {          return len * TEscapeUtil::ESCAPE_C_BUFFER_SIZE;      } - +       template <bool tounicode>      inline size_t EscapeJ(const char* str, size_t len, char* out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) {          char* out0 = out;          char buffer[TEscapeUtil::ESCAPE_C_BUFFER_SIZE]; - +           size_t i, j;          for (i = 0, j = 0; i < len; ++i) {              size_t rlen = TEscapeUtil::EscapeJ<tounicode>(str[i], (i + 1 < len ? str[i + 1] : 0), buffer, safe, unsafe); - +               if (rlen > 1) {                  strncpy(out, str + j, i - j);                  out += i - j;                  j = i + 1; - +                   strncpy(out, buffer, rlen);                  out += rlen;              }          } - +           if (j > 0) {              strncpy(out, str + j, len - j);              out += len - j;          } else {              strncpy(out, str, len);              out += len; -        } - +        }  +           return out - out0; -    } - +    }  +       template <bool quote, bool tounicode>      inline void EscapeJ(TStringBuf in, IOutputStream& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) {          TTempBuf b(SuggestBuffer(in.size()) + 2); - +           if (quote)              b.Append("\"", 1); - +           b.Proceed(EscapeJ<tounicode>(in.data(), in.size(), b.Current(), safe, unsafe)); - +           if (quote)              b.Append("\"", 1); - +           out.Write(b.Data(), b.Filled());      } - +       template <bool quote, bool tounicode>      inline void EscapeJ(TStringBuf in, TString& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) {          TTempBuf b(SuggestBuffer(in.size()) + 2); - +           if (quote)              b.Append("\"", 1); - +           b.Proceed(EscapeJ<tounicode>(in.data(), in.size(), b.Current(), safe, unsafe)); - +           if (quote)              b.Append("\"", 1); - +           out.append(b.Data(), b.Filled());      } - +       template <bool quote, bool tounicode>      inline TString EscapeJ(TStringBuf in, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) {          TString s;          EscapeJ<quote, tounicode>(in, s, safe, unsafe);          return s;      } - +       // If the template parameter "tounicode" is ommited, then use the default value false      inline size_t EscapeJ(const char* str, size_t len, char* out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) {          return EscapeJ<false>(str, len, out, safe, unsafe);      } - +       template <bool quote>      inline void EscapeJ(TStringBuf in, IOutputStream& out, TStringBuf safe = TStringBuf(), TStringBuf unsafe = TStringBuf()) {          EscapeJ<quote, false>(in, out, safe, unsafe); diff --git a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp index 768555ea3ae..9132fbad916 100644 --- a/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp +++ b/library/cpp/string_utils/relaxed_escaper/relaxed_escaper_ut.cpp @@ -1,57 +1,57 @@ -#include "relaxed_escaper.h" - +#include "relaxed_escaper.h"  +   #include <library/cpp/testing/unittest/registar.h> - +   #define RESC_FIXED_STR(s) TStringBuf(s, sizeof(s) - 1)  static const TStringBuf CommonTestData[] = { -    // Should be valid UTF-8. -    RESC_FIXED_STR("http://ya.ru/"), RESC_FIXED_STR("http://ya.ru/"), -    RESC_FIXED_STR("http://ya.ru/\\x17\\n"), RESC_FIXED_STR("http://ya.ru/\x17\n"), - -    RESC_FIXED_STR("http://ya.ru/\\0"), RESC_FIXED_STR("http://ya.ru/\0"), -    RESC_FIXED_STR("http://ya.ru/\\0\\0"), RESC_FIXED_STR("http://ya.ru/\0\0"), +    // Should be valid UTF-8.  +    RESC_FIXED_STR("http://ya.ru/"), RESC_FIXED_STR("http://ya.ru/"),  +    RESC_FIXED_STR("http://ya.ru/\\x17\\n"), RESC_FIXED_STR("http://ya.ru/\x17\n"),  +  +    RESC_FIXED_STR("http://ya.ru/\\0"), RESC_FIXED_STR("http://ya.ru/\0"),  +    RESC_FIXED_STR("http://ya.ru/\\0\\0"), RESC_FIXED_STR("http://ya.ru/\0\0"),       RESC_FIXED_STR("http://ya.ru/\\0\\0000"), RESC_FIXED_STR("http://ya.ru/\0\0"                                                               "0"),      RESC_FIXED_STR("http://ya.ru/\\0\\0001"), RESC_FIXED_STR("http://ya.ru/\0\x00"                                                               "1"), - +       RESC_FIXED_STR("\\2\\4\\00678"), RESC_FIXED_STR("\2\4\6"                                                      "78"), -    RESC_FIXED_STR("\\2\\4\\689"), RESC_FIXED_STR("\2\4\689"), - -    RESC_FIXED_STR("\\\"Hello\\\", Alice said."), RESC_FIXED_STR("\"Hello\", Alice said."), -    RESC_FIXED_STR("Slash\\\\dash!"), RESC_FIXED_STR("Slash\\dash!"), -    RESC_FIXED_STR("There\\nare\\r\\nnewlines."), RESC_FIXED_STR("There\nare\r\nnewlines."), +    RESC_FIXED_STR("\\2\\4\\689"), RESC_FIXED_STR("\2\4\689"),  +  +    RESC_FIXED_STR("\\\"Hello\\\", Alice said."), RESC_FIXED_STR("\"Hello\", Alice said."),  +    RESC_FIXED_STR("Slash\\\\dash!"), RESC_FIXED_STR("Slash\\dash!"),  +    RESC_FIXED_STR("There\\nare\\r\\nnewlines."), RESC_FIXED_STR("There\nare\r\nnewlines."),       RESC_FIXED_STR("There\\tare\\ttabs."), RESC_FIXED_STR("There\tare\ttabs.")}; -#undef RESC_FIXED_STR - +#undef RESC_FIXED_STR  +   Y_UNIT_TEST_SUITE(TRelaxedEscaperTest) {      Y_UNIT_TEST(TestEscaper) { -        using namespace NEscJ; +        using namespace NEscJ;           for (size_t i = 0; i < Y_ARRAY_SIZE(CommonTestData); i += 2) {              TString expected(CommonTestData[i].data(), CommonTestData[i].size());              TString source(CommonTestData[i + 1].data(), CommonTestData[i + 1].size());              TString actual(EscapeJ<false>(source));              TString actual2(UnescapeC(expected)); - -            UNIT_ASSERT_VALUES_EQUAL(expected, actual); -            UNIT_ASSERT_VALUES_EQUAL(source, actual2); -        } - -        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\x17\\n\xAB", EscapeJ<false>("http://ya.ru/\x17\n\xab")); +  +            UNIT_ASSERT_VALUES_EQUAL(expected, actual);  +            UNIT_ASSERT_VALUES_EQUAL(source, actual2);  +        }  +  +        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\x17\\n\xAB", EscapeJ<false>("http://ya.ru/\x17\n\xab"));           TString s = EscapeJ<false, true>("http://ya.ru/\x17\n\xab\xff"); -        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\u0017\\n\xAB\\xFF", s); -        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\x17\n\xAB", EscapeJ<false>("http://ya.ru/\x17\n\xab", "\n")); -        UNIT_ASSERT_VALUES_EQUAL("http:\\x2F\\x2Fya.ru\\x2F\\x17\n\xAB'", EscapeJ<false>("http://ya.ru/\x17\n\xab'", "\n'", "/")); -        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\x17\n\xab", UnescapeC("http:\\x2F\\x2Fya.ru\\x2F\\x17\n\xAB")); -        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\x17\n\xab", UnescapeC("http://ya.ru/\\x17\\n\xAB")); -        UNIT_ASSERT_VALUES_EQUAL("h", EscapeJ<false>("h")); -        UNIT_ASSERT_VALUES_EQUAL("\"h\"", EscapeJ<true>("h")); -        UNIT_ASSERT_VALUES_EQUAL("h", UnescapeC("h")); -        UNIT_ASSERT_VALUES_EQUAL("\\xFF", EscapeJ<false>("\xFF")); -        UNIT_ASSERT_VALUES_EQUAL("\"\\xFF\"", EscapeJ<true>("\xFF")); -        UNIT_ASSERT_VALUES_EQUAL("\xFF", UnescapeC("\\xFF")); - +        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\u0017\\n\xAB\\xFF", s);  +        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\\x17\n\xAB", EscapeJ<false>("http://ya.ru/\x17\n\xab", "\n"));  +        UNIT_ASSERT_VALUES_EQUAL("http:\\x2F\\x2Fya.ru\\x2F\\x17\n\xAB'", EscapeJ<false>("http://ya.ru/\x17\n\xab'", "\n'", "/"));  +        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\x17\n\xab", UnescapeC("http:\\x2F\\x2Fya.ru\\x2F\\x17\n\xAB"));  +        UNIT_ASSERT_VALUES_EQUAL("http://ya.ru/\x17\n\xab", UnescapeC("http://ya.ru/\\x17\\n\xAB"));  +        UNIT_ASSERT_VALUES_EQUAL("h", EscapeJ<false>("h"));  +        UNIT_ASSERT_VALUES_EQUAL("\"h\"", EscapeJ<true>("h"));  +        UNIT_ASSERT_VALUES_EQUAL("h", UnescapeC("h"));  +        UNIT_ASSERT_VALUES_EQUAL("\\xFF", EscapeJ<false>("\xFF"));  +        UNIT_ASSERT_VALUES_EQUAL("\"\\xFF\"", EscapeJ<true>("\xFF"));  +        UNIT_ASSERT_VALUES_EQUAL("\xFF", UnescapeC("\\xFF"));  +           UNIT_ASSERT_VALUES_EQUAL("\\377f", EscapeJ<false>("\xff"                                                            "f"));          UNIT_ASSERT_VALUES_EQUAL("\xff" @@ -62,5 +62,5 @@ Y_UNIT_TEST_SUITE(TRelaxedEscaperTest) {          UNIT_ASSERT_VALUES_EQUAL("\xff"                                   "g",                                   UnescapeC("\\xFFg")); -    } -} +    }  +}  diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 85f4ac5d693..5050e2bf3a8 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -48,13 +48,13 @@ namespace {          const TChar httpsPrefix[] = {'h', 't', 't', 'p', 's', ':', '/', '/', 0};          if (urlSize.Has(7) && Compare1Case2(url, httpPrefix, 7) == 0)              return 7; -        if (!ignorehttps && urlSize.Has(8) && Compare1Case2(url, httpsPrefix, 8) == 0) +        if (!ignorehttps && urlSize.Has(8) && Compare1Case2(url, httpsPrefix, 8) == 0)               return 8;          return 0;      }      template <typename T> -    inline T CutHttpPrefixImpl(const T& url, bool ignorehttps) { +    inline T CutHttpPrefixImpl(const T& url, bool ignorehttps) {           size_t prefixSize = GetHttpPrefixSizeImpl<typename T::char_type>(url.data(), TKnownSize(url.size()), ignorehttps);          if (prefixSize)              return url.substr(prefixSize); @@ -90,11 +90,11 @@ size_t GetHttpPrefixSize(const TWtringBuf url, bool ignorehttps) noexcept {  }  TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps) noexcept { -    return CutHttpPrefixImpl(url, ignorehttps); +    return CutHttpPrefixImpl(url, ignorehttps);   }  TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps) noexcept { -    return CutHttpPrefixImpl(url, ignorehttps); +    return CutHttpPrefixImpl(url, ignorehttps);   }  size_t GetSchemePrefixSize(const TStringBuf url) noexcept { diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h index 84137ccc57d..3c12e514fa9 100644 --- a/library/cpp/string_utils/url/url.h +++ b/library/cpp/string_utils/url/url.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once   #include <util/generic/fwd.h>  #include <util/generic/strbuf.h> @@ -49,7 +49,7 @@ TStringBuf GetSchemePrefix(const TStringBuf url) noexcept;  //! @return a new URL without protocol prefix  Y_PURE_FUNCTION  TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps = false) noexcept; - +   Y_PURE_FUNCTION  TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps = false) noexcept; diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp index 15880138939..36fdaa0f6db 100644 --- a/library/cpp/string_utils/url/url_ut.cpp +++ b/library/cpp/string_utils/url/url_ut.cpp @@ -19,8 +19,8 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) {          UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetHost("www.ya.ru:8080/bebe"));          UNIT_ASSERT_VALUES_EQUAL("www.ya.ru", GetHost("https://www.ya.ru:8080/bebe"));          UNIT_ASSERT_VALUES_EQUAL("ya.ru:8080", GetHostAndPort("ya.ru:8080/bebe")); -        // irl RFC3986 sometimes gets ignored -        UNIT_ASSERT_VALUES_EQUAL("pravda-kmv.ru", GetHost("pravda-kmv.ru?page=news&id=6973")); +        // irl RFC3986 sometimes gets ignored  +        UNIT_ASSERT_VALUES_EQUAL("pravda-kmv.ru", GetHost("pravda-kmv.ru?page=news&id=6973"));           UNIT_ASSERT_VALUES_EQUAL("pravda-kmv.ru", GetHostAndPort("pravda-kmv.ru?page=news&id=6973"));          // check simple string          UNIT_ASSERT_VALUES_EQUAL("some_blender_url", GetHost("some_blender_url")); @@ -99,9 +99,9 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) {          UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz"));          UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz", true));          UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz")); -        UNIT_ASSERT_VALUES_EQUAL("https://ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz", true)); +        UNIT_ASSERT_VALUES_EQUAL("https://ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz", true));           UNIT_ASSERT_VALUES_EQUAL("", CutHttpPrefix("https://"));               // is that right? -        UNIT_ASSERT_VALUES_EQUAL("https://", CutHttpPrefix("https://", true)); // is that right? +        UNIT_ASSERT_VALUES_EQUAL("https://", CutHttpPrefix("https://", true)); // is that right?       }      Y_UNIT_TEST(TestMisc) { | 
