diff options
author | pozhilov <pozhilov@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
commit | 23bf1d16dddf213a6aa8e8d5c8621e1242a1f118 (patch) | |
tree | ed030ff443eb83431f11e53b6460b1b73d035412 /util/string | |
parent | 7156b3713e77ce36387436e5558320917698b7a2 (diff) | |
download | ydb-23bf1d16dddf213a6aa8e8d5c8621e1242a1f118.tar.gz |
Restoring authorship annotation for <pozhilov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/cast.h | 6 | ||||
-rw-r--r-- | util/string/cast.pxd | 6 | ||||
-rw-r--r-- | util/string/cast_ut.pyx | 12 | ||||
-rw-r--r-- | util/string/split.h | 24 | ||||
-rw-r--r-- | util/string/split_ut.cpp | 54 |
5 files changed, 51 insertions, 51 deletions
diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..48d4c5c5cd 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -119,9 +119,9 @@ inline const TUtf16String& ToWtring(TUtf16String& w) { return w; } -struct TFromStringException: public TBadCastException { -}; - +struct TFromStringException: public TBadCastException { +}; + /* * specialized for: * bool diff --git a/util/string/cast.pxd b/util/string/cast.pxd index dc23619e1e..b0fcc8123f 100644 --- a/util/string/cast.pxd +++ b/util/string/cast.pxd @@ -1,8 +1,8 @@ -from util.generic.string cimport TString - +from util.generic.string cimport TString + from libcpp cimport bool as bool_t -cdef extern from "<util/string/cast.h>" nogil: +cdef extern from "<util/string/cast.h>" nogil: T FromString[T](const TString&) except + bool_t TryFromString[T](const TString&, T&) except + TString ToString[T](const T&) except + diff --git a/util/string/cast_ut.pyx b/util/string/cast_ut.pyx index 88e86ef961..16bc90e5f5 100644 --- a/util/string/cast_ut.pyx +++ b/util/string/cast_ut.pyx @@ -1,13 +1,13 @@ # cython: c_string_type=str, c_string_encoding=utf8 from util.string.cast cimport FromString, ToString - -import unittest - + +import unittest + class TestFromString(unittest.TestCase): def test_from_int(self): self.assertEquals(FromString[int]("42"), 42) -class TestToString(unittest.TestCase): - def test_from_int(self): - self.assertEquals(ToString(42), "42") +class TestToString(unittest.TestCase): + def test_from_int(self): + self.assertEquals(ToString(42), "42") diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..81607e0961 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -1,10 +1,10 @@ #pragma once #include "strspn.h" -#include "cast.h" +#include "cast.h" #include <util/generic/algorithm.h> -#include <util/generic/fwd.h> +#include <util/generic/fwd.h> #include <util/generic/iterator.h> #include <util/generic/iterator_range.h> #include <util/generic/store_policy.h> @@ -431,16 +431,16 @@ void GetNext(TStringBuf& s, D delim, P& param) { param = FromString<P>(next); } -template <class P, class D> -void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { - TStringBuf next = s.NextTok(delim); - if (next.IsInited()) { - param = FromString<P>(next); - } else { - param.Clear(); - } -} - +template <class P, class D> +void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { + TStringBuf next = s.NextTok(delim); + if (next.IsInited()) { + param = FromString<P>(next); + } else { + param.Clear(); + } +} + // example: // Split(TStringBuf("Sherlock,2014,36.6"), ',', name, year, temperature); template <class D, class P1, class P2> diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..89c28258e5 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -5,7 +5,7 @@ #include <util/stream/output.h> #include <util/charset/wide.h> #include <util/datetime/cputimer.h> -#include <util/generic/maybe.h> +#include <util/generic/maybe.h> #include <string> #include <string_view> @@ -258,25 +258,25 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { double num2 = 0; TStringBuf strBuf; Split(data, ' ', str, num1, num2, strBuf); - UNIT_ASSERT_VALUES_EQUAL(str, "abc"); - UNIT_ASSERT_VALUES_EQUAL(num1, 22); - UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); - UNIT_ASSERT_VALUES_EQUAL(strBuf, "xyz"); + UNIT_ASSERT_VALUES_EQUAL(str, "abc"); + UNIT_ASSERT_VALUES_EQUAL(num1, 22); + UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); + UNIT_ASSERT_VALUES_EQUAL(strBuf, "xyz"); } Y_UNIT_TEST(ConvenientSplitTestWithMaybe) { TString data("abc 42"); TString str; - TMaybe<double> num2 = 1; - TMaybe<double> maybe = 1; - - Split(data, ' ', str, num2, maybe); - - UNIT_ASSERT_VALUES_EQUAL(str, "abc"); - UNIT_ASSERT_VALUES_EQUAL(*num2, 42); - UNIT_ASSERT(!maybe); - } - + TMaybe<double> num2 = 1; + TMaybe<double> maybe = 1; + + Split(data, ' ', str, num2, maybe); + + UNIT_ASSERT_VALUES_EQUAL(str, "abc"); + UNIT_ASSERT_VALUES_EQUAL(*num2, 42); + UNIT_ASSERT(!maybe); + } + Y_UNIT_TEST(ConvenientSplitTestExceptions) { TString data("abc 22 33"); TString s1, s2, s3, s4; @@ -285,22 +285,22 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, s3)); UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, s3, s4), yexception); } - + Y_UNIT_TEST(ConvenientSplitTestMaybeExceptions) { TString data("abc 22 33"); TString s1, s2; TMaybe<TString> m1, m2; - - UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, m1), yexception); - UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2), yexception); - UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1)); - - UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2)); - UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2, s1, s2), yexception); - - UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1)); - UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1, s1), yexception); - } + + UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, m1), yexception); + UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2), yexception); + UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1)); + + UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2)); + UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2, s1, s2), yexception); + + UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1)); + UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1, s1), yexception); + } } template <typename I, typename C> |