aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorsinister <sinister@yandex-team.ru>2022-02-10 16:50:50 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:50 +0300
commiteace2adfb451fa3978f6edbae8aec53a50d1c969 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp
parentb76c7a19e20d232ef1e00ccbe68f64a3024d29ed (diff)
downloadydb-eace2adfb451fa3978f6edbae8aec53a50d1c969.tar.gz
Restoring authorship annotation for <sinister@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yson_pull/detail/lexer_base.h52
-rw-r--r--library/cpp/yson_pull/detail/percent_scalar.h62
-rw-r--r--library/cpp/yson_pull/detail/reader.h26
-rw-r--r--library/cpp/yson_pull/detail/writer.h32
-rw-r--r--library/cpp/yson_pull/ut/reader_ut.cpp58
-rw-r--r--library/cpp/yson_pull/ut/writer_ut.cpp22
6 files changed, 126 insertions, 126 deletions
diff --git a/library/cpp/yson_pull/detail/lexer_base.h b/library/cpp/yson_pull/detail/lexer_base.h
index 61f0c21ca9..572bdb3d18 100644
--- a/library/cpp/yson_pull/detail/lexer_base.h
+++ b/library/cpp/yson_pull/detail/lexer_base.h
@@ -4,7 +4,7 @@
#include "cescape.h"
#include "macros.h"
#include "number.h"
-#include "percent_scalar.h"
+#include "percent_scalar.h"
#include "stream_counter.h"
#include "varint.h"
@@ -199,17 +199,17 @@ namespace NYsonPull {
return token_buffer();
}
- percent_scalar read_percent_scalar() {
- auto throw_incorrect_percent_scalar = [&]() {
- Base::fail("Incorrect %-literal prefix ", NCEscape::quote(token_buffer()));
+ percent_scalar read_percent_scalar() {
+ auto throw_incorrect_percent_scalar = [&]() {
+ Base::fail("Incorrect %-literal prefix ", NCEscape::quote(token_buffer()));
};
- auto assert_literal = [&](TStringBuf literal) -> void {
- for (size_t i = 2; i < literal.size(); ++i) {
+ auto assert_literal = [&](TStringBuf literal) -> void {
+ for (size_t i = 2; i < literal.size(); ++i) {
token_buffer_.push_back(this->Base::template get_byte<false>());
Base::advance(1);
if (Y_UNLIKELY(token_buffer_.back() != literal[i])) {
- throw_incorrect_percent_scalar();
+ throw_incorrect_percent_scalar();
}
}
};
@@ -217,25 +217,25 @@ namespace NYsonPull {
token_buffer_.clear();
token_buffer_.push_back(this->Base::template get_byte<false>());
Base::advance(1);
-
- switch (token_buffer_[0]) {
- case 't':
- assert_literal(percent_scalar::true_literal);
- return percent_scalar(true);
- case 'f':
- assert_literal(percent_scalar::false_literal);
- return percent_scalar(false);
- case 'n':
- assert_literal(percent_scalar::nan_literal);
- return percent_scalar(std::numeric_limits<double>::quiet_NaN());
- case 'i':
- assert_literal(percent_scalar::positive_inf_literal);
- return percent_scalar(std::numeric_limits<double>::infinity());
- case '-':
- assert_literal(percent_scalar::negative_inf_literal);
- return percent_scalar(-std::numeric_limits<double>::infinity());
- default:
- throw_incorrect_percent_scalar();
+
+ switch (token_buffer_[0]) {
+ case 't':
+ assert_literal(percent_scalar::true_literal);
+ return percent_scalar(true);
+ case 'f':
+ assert_literal(percent_scalar::false_literal);
+ return percent_scalar(false);
+ case 'n':
+ assert_literal(percent_scalar::nan_literal);
+ return percent_scalar(std::numeric_limits<double>::quiet_NaN());
+ case 'i':
+ assert_literal(percent_scalar::positive_inf_literal);
+ return percent_scalar(std::numeric_limits<double>::infinity());
+ case '-':
+ assert_literal(percent_scalar::negative_inf_literal);
+ return percent_scalar(-std::numeric_limits<double>::infinity());
+ default:
+ throw_incorrect_percent_scalar();
}
Y_UNREACHABLE();
diff --git a/library/cpp/yson_pull/detail/percent_scalar.h b/library/cpp/yson_pull/detail/percent_scalar.h
index beec425c7d..ff4571842e 100644
--- a/library/cpp/yson_pull/detail/percent_scalar.h
+++ b/library/cpp/yson_pull/detail/percent_scalar.h
@@ -1,36 +1,36 @@
-#pragma once
-
-#include <util/generic/strbuf.h>
-
-namespace NYsonPull::NDetail {
- enum class percent_scalar_type {
- boolean,
- float64
- };
-
- struct percent_scalar {
- //! Text boolean literals
+#pragma once
+
+#include <util/generic/strbuf.h>
+
+namespace NYsonPull::NDetail {
+ enum class percent_scalar_type {
+ boolean,
+ float64
+ };
+
+ struct percent_scalar {
+ //! Text boolean literals
static constexpr TStringBuf true_literal = "%true";
static constexpr TStringBuf false_literal = "%false";
- //! Text floating-point literals
+ //! Text floating-point literals
static constexpr TStringBuf nan_literal = "%nan";
static constexpr TStringBuf positive_inf_literal = "%inf";
static constexpr TStringBuf negative_inf_literal = "%-inf";
-
- percent_scalar_type type;
- union {
- double as_float64;
- bool as_boolean;
- } value;
-
- percent_scalar(double v) {
- type = percent_scalar_type::float64;
- value.as_float64 = v;
- }
-
- percent_scalar(bool v) {
- type = percent_scalar_type::boolean;
- value.as_boolean = v;
- }
- };
-}
+
+ percent_scalar_type type;
+ union {
+ double as_float64;
+ bool as_boolean;
+ } value;
+
+ percent_scalar(double v) {
+ type = percent_scalar_type::float64;
+ value.as_float64 = v;
+ }
+
+ percent_scalar(bool v) {
+ type = percent_scalar_type::boolean;
+ value.as_boolean = v;
+ }
+ };
+}
diff --git a/library/cpp/yson_pull/detail/reader.h b/library/cpp/yson_pull/detail/reader.h
index 29a266edb9..0e02396358 100644
--- a/library/cpp/yson_pull/detail/reader.h
+++ b/library/cpp/yson_pull/detail/reader.h
@@ -300,18 +300,18 @@ namespace NYsonPull {
}
}
- //! Present a value from %-literal variant
- void yield(const percent_scalar& value) {
- switch (value.type) {
- case percent_scalar_type::boolean:
- yield(value.value.as_boolean);
- break;
- case percent_scalar_type::float64:
- yield(value.value.as_float64);
- break;
- }
- }
-
+ //! Present a value from %-literal variant
+ void yield(const percent_scalar& value) {
+ switch (value.type) {
+ case percent_scalar_type::boolean:
+ yield(value.value.as_boolean);
+ break;
+ case percent_scalar_type::float64:
+ yield(value.value.as_float64);
+ break;
+ }
+ }
+
//! Present a value-less event
void yield(EEventType type) {
event_ = TEvent{type};
@@ -654,7 +654,7 @@ namespace NYsonPull {
case char_class::percent:
lexer_.advance(1);
- yield(lexer_.read_percent_scalar());
+ yield(lexer_.read_percent_scalar());
break;
case char_class::none:
diff --git a/library/cpp/yson_pull/detail/writer.h b/library/cpp/yson_pull/detail/writer.h
index 2df6ee8906..b24b994292 100644
--- a/library/cpp/yson_pull/detail/writer.h
+++ b/library/cpp/yson_pull/detail/writer.h
@@ -2,7 +2,7 @@
#include "byte_writer.h"
#include "cescape.h"
-#include "percent_scalar.h"
+#include "percent_scalar.h"
#include "stream_counter.h"
#include "symbols.h"
#include "varint.h"
@@ -385,7 +385,7 @@ namespace NYsonPull {
}
void OnScalarFloat64(double value) override {
- update_state(EEventType::Scalar);
+ update_state(EEventType::Scalar);
begin_node();
write(NSymbol::double_marker);
@@ -425,7 +425,7 @@ namespace NYsonPull {
update_state(EEventType::Scalar);
begin_node();
- write(value ? percent_scalar::true_literal : percent_scalar::false_literal);
+ write(value ? percent_scalar::true_literal : percent_scalar::false_literal);
end_node();
}
@@ -455,20 +455,20 @@ namespace NYsonPull {
void OnScalarFloat64(double value) override {
update_state(EEventType::Scalar);
- begin_node();
-
- if (std::isfinite(value)) {
- char buf[32];
- auto len = ::snprintf(buf, sizeof(buf), "%#.17lg", value);
- write_raw(buf, len);
- } else if (std::isnan(value)) {
- write(percent_scalar::nan_literal);
- } else if (value > 0) {
- write(percent_scalar::positive_inf_literal);
- } else {
- write(percent_scalar::negative_inf_literal);
+ begin_node();
+
+ if (std::isfinite(value)) {
+ char buf[32];
+ auto len = ::snprintf(buf, sizeof(buf), "%#.17lg", value);
+ write_raw(buf, len);
+ } else if (std::isnan(value)) {
+ write(percent_scalar::nan_literal);
+ } else if (value > 0) {
+ write(percent_scalar::positive_inf_literal);
+ } else {
+ write(percent_scalar::negative_inf_literal);
}
-
+
end_node();
}
diff --git a/library/cpp/yson_pull/ut/reader_ut.cpp b/library/cpp/yson_pull/ut/reader_ut.cpp
index 586c91870a..1184265ddb 100644
--- a/library/cpp/yson_pull/ut/reader_ut.cpp
+++ b/library/cpp/yson_pull/ut/reader_ut.cpp
@@ -21,20 +21,20 @@ namespace {
template <>
void expect_scalar(const NYsonPull::TScalar& scalar, double value) {
UNIT_ASSERT_VALUES_EQUAL(NYsonPull::EScalarType::Float64, scalar.Type());
-
- auto scalarValue = scalar.AsFloat64();
- auto message = TStringBuilder() << "expected " << value << ", got " << scalarValue;
-
- if (std::isfinite(value)) {
- UNIT_ASSERT_C(std::isfinite(scalarValue), message);
- UNIT_ASSERT_DOUBLES_EQUAL(value, scalarValue, 1e-5);
- } else if (std::isnan(value)) {
- UNIT_ASSERT_C(std::isnan(scalarValue), message);
- } else if (value > 0) {
- UNIT_ASSERT_C(std::isinf(scalarValue) && (scalarValue > 0), message);
- } else {
- UNIT_ASSERT_C(std::isinf(scalarValue) && (scalarValue < 0), message);
- }
+
+ auto scalarValue = scalar.AsFloat64();
+ auto message = TStringBuilder() << "expected " << value << ", got " << scalarValue;
+
+ if (std::isfinite(value)) {
+ UNIT_ASSERT_C(std::isfinite(scalarValue), message);
+ UNIT_ASSERT_DOUBLES_EQUAL(value, scalarValue, 1e-5);
+ } else if (std::isnan(value)) {
+ UNIT_ASSERT_C(std::isnan(scalarValue), message);
+ } else if (value > 0) {
+ UNIT_ASSERT_C(std::isinf(scalarValue) && (scalarValue > 0), message);
+ } else {
+ UNIT_ASSERT_C(std::isinf(scalarValue) && (scalarValue < 0), message);
+ }
}
template <typename T>
@@ -153,23 +153,23 @@ Y_UNIT_TEST_SUITE(Reader) {
test_scalar(
TStringBuf("\x03\x00\x00\x00\x00\x00\x00\xf8\x7f"sv),
- double{std::numeric_limits<double>::quiet_NaN()});
- test_scalar(
+ double{std::numeric_limits<double>::quiet_NaN()});
+ test_scalar(
TStringBuf("\x03\x00\x00\x00\x00\x00\x00\xf0\x7f"sv),
double{std::numeric_limits<double>::infinity()});
test_scalar(
TStringBuf("\x03\x00\x00\x00\x00\x00\x00\xf0\xff"sv),
double{-std::numeric_limits<double>::infinity()});
- test_scalar(
+ test_scalar(
TStringBuf("%nan"),
- double{std::numeric_limits<double>::quiet_NaN()});
- test_scalar(
+ double{std::numeric_limits<double>::quiet_NaN()});
+ test_scalar(
TStringBuf("%inf"),
- double{std::numeric_limits<double>::infinity()});
- test_scalar(
+ double{std::numeric_limits<double>::infinity()});
+ test_scalar(
TStringBuf("%-inf"),
- double{-std::numeric_limits<double>::infinity()});
+ double{-std::numeric_limits<double>::infinity()});
REJECT("++0.0");
REJECT("++1.0");
@@ -184,13 +184,13 @@ Y_UNIT_TEST_SUITE(Reader) {
// XXX: Rejected on Mac OS, accepted on Linux (?!)
//REJECT(".0");
//REJECT(".5");
-
- REJECT("%NaN");
- REJECT("%+inf");
- REJECT("%infinity");
- REJECT("%na");
- REJECT("%in");
- REJECT("%-in");
+
+ REJECT("%NaN");
+ REJECT("%+inf");
+ REJECT("%infinity");
+ REJECT("%na");
+ REJECT("%in");
+ REJECT("%-in");
}
Y_UNIT_TEST(ScalarString) {
diff --git a/library/cpp/yson_pull/ut/writer_ut.cpp b/library/cpp/yson_pull/ut/writer_ut.cpp
index 4a052e5274..5c304bad0f 100644
--- a/library/cpp/yson_pull/ut/writer_ut.cpp
+++ b/library/cpp/yson_pull/ut/writer_ut.cpp
@@ -123,14 +123,14 @@ Y_UNIT_TEST_SUITE(Writer) {
Y_UNIT_TEST(TextFloat64) {
UNIT_ASSERT_VALUES_EQUAL(
- "%inf",
+ "%inf",
to_yson_text_string(NYsonPull::TScalar{std::numeric_limits<double>::infinity()}));
UNIT_ASSERT_VALUES_EQUAL(
- "%-inf",
+ "%-inf",
to_yson_text_string(NYsonPull::TScalar{-std::numeric_limits<double>::infinity()}));
- UNIT_ASSERT_VALUES_EQUAL(
- "%nan",
- to_yson_text_string(NYsonPull::TScalar{std::numeric_limits<double>::quiet_NaN()}));
+ UNIT_ASSERT_VALUES_EQUAL(
+ "%nan",
+ to_yson_text_string(NYsonPull::TScalar{std::numeric_limits<double>::quiet_NaN()}));
}
Y_UNIT_TEST(TextString) {
@@ -230,15 +230,15 @@ Y_UNIT_TEST_SUITE(Writer) {
UNIT_ASSERT_VALUES_EQUAL(
TStringBuf("\x03\x00\x00\x00\x00\x00\x00\xf0\xff"sv),
to_yson_binary_string(NYsonPull::TScalar{-std::numeric_limits<double>::infinity()}));
- UNIT_ASSERT_VALUES_EQUAL(
+ UNIT_ASSERT_VALUES_EQUAL(
TStringBuf("\x03\x00\x00\x00\x00\x00\x00\xf8\x7f"sv),
- to_yson_binary_string(NYsonPull::TScalar{std::numeric_limits<double>::quiet_NaN()}));
- UNIT_ASSERT_VALUES_EQUAL(
+ to_yson_binary_string(NYsonPull::TScalar{std::numeric_limits<double>::quiet_NaN()}));
+ UNIT_ASSERT_VALUES_EQUAL(
TStringBuf("\x03\x9a\x99\x99\x99\x99\x99\xf1\x3f"),
- to_yson_binary_string(NYsonPull::TScalar{double{1.1}}));
- UNIT_ASSERT_VALUES_EQUAL(
+ to_yson_binary_string(NYsonPull::TScalar{double{1.1}}));
+ UNIT_ASSERT_VALUES_EQUAL(
TStringBuf("\x03\x9a\x99\x99\x99\x99\x99\xf1\xbf"),
- to_yson_binary_string(NYsonPull::TScalar{double{-1.1}}));
+ to_yson_binary_string(NYsonPull::TScalar{double{-1.1}}));
}
Y_UNIT_TEST(BinaryString) {