diff options
author | babenko <babenko@yandex-team.com> | 2025-02-22 17:28:25 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2025-02-22 17:48:29 +0300 |
commit | 59afaa0cb7cd89146dd10f5446256afcce33bd0e (patch) | |
tree | 38d3c46bcba8da7c3b8ffc6b818695bc6b62d532 /library/cpp | |
parent | 1d9cc117e33b162a5247032e175ed7ea26971437 (diff) | |
download | ydb-59afaa0cb7cd89146dd10f5446256afcce33bd0e.tar.gz |
YT-22593: More trivial TString->std::string migrations
[nodiff:runtime]
commit_hash:1ba799aed1703ab7c6304b6da7090b3337f768dd
Diffstat (limited to 'library/cpp')
29 files changed, 140 insertions, 140 deletions
diff --git a/library/cpp/yt/backtrace/backtrace.cpp b/library/cpp/yt/backtrace/backtrace.cpp index 153a0a5dd0..e663cbb8a4 100644 --- a/library/cpp/yt/backtrace/backtrace.cpp +++ b/library/cpp/yt/backtrace/backtrace.cpp @@ -4,9 +4,9 @@ namespace NYT::NBacktrace { //////////////////////////////////////////////////////////////////////////////// -TString SymbolizeBacktrace(TBacktrace backtrace) +std::string SymbolizeBacktrace(TBacktrace backtrace) { - TString result; + std::string result; SymbolizeBacktrace( backtrace, [&] (TStringBuf str) { result += str; }); diff --git a/library/cpp/yt/backtrace/backtrace.h b/library/cpp/yt/backtrace/backtrace.h index ea70d9558c..fcb1dc782f 100644 --- a/library/cpp/yt/backtrace/backtrace.h +++ b/library/cpp/yt/backtrace/backtrace.h @@ -34,7 +34,7 @@ void SymbolizeBacktrace( /*! * \param backtrace Backtrace to symbolize */ -TString SymbolizeBacktrace(TBacktrace backtrace); +std::string SymbolizeBacktrace(TBacktrace backtrace); //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/coding/unittests/varint_ut.cpp b/library/cpp/yt/coding/unittests/varint_ut.cpp index ed83ab5c92..cb6a800311 100644 --- a/library/cpp/yt/coding/unittests/varint_ut.cpp +++ b/library/cpp/yt/coding/unittests/varint_ut.cpp @@ -15,13 +15,14 @@ using ::testing::Values; //////////////////////////////////////////////////////////////////////////////// -class TWriteVarIntTest: public ::testing::TestWithParam<std::tuple<ui64, TString> > +class TWriteVarIntTest + : public ::testing::TestWithParam<std::tuple<ui64, std::string>> { }; TEST_P(TWriteVarIntTest, Serialization) { ui64 value = std::get<0>(GetParam()); - TString rightAnswer = std::get<1>(GetParam()); + std::string rightAnswer = std::get<1>(GetParam()); TStringStream outputStream; WriteVarUint64(&outputStream, value); @@ -30,13 +31,13 @@ TEST_P(TWriteVarIntTest, Serialization) //////////////////////////////////////////////////////////////////////////////// -class TReadVarIntTest: public ::testing::TestWithParam<std::tuple<ui64, TString> > +class TReadVarIntTest: public ::testing::TestWithParam<std::tuple<ui64, std::string> > { }; TEST_P(TReadVarIntTest, Serialization) { ui64 rightAnswer = std::get<0>(GetParam()); - TString input = std::get<1>(GetParam()); + auto input = TString(std::get<1>(GetParam())); TStringInput inputStream(input); ui64 value; @@ -56,34 +57,34 @@ TEST(TReadVarIntTest, Overflow) auto ValuesForVarIntTests = Values( // Simple cases. - std::make_tuple(0x0ull, TString("\x00", 1)), - std::make_tuple(0x1ull, TString("\x01", 1)), - std::make_tuple(0x2ull, TString("\x02", 1)), - std::make_tuple(0x3ull, TString("\x03", 1)), - std::make_tuple(0x4ull, TString("\x04", 1)), + std::make_tuple(0x0ull, std::string("\x00", 1)), + std::make_tuple(0x1ull, std::string("\x01", 1)), + std::make_tuple(0x2ull, std::string("\x02", 1)), + std::make_tuple(0x3ull, std::string("\x03", 1)), + std::make_tuple(0x4ull, std::string("\x04", 1)), // The following "magic numbers" are critical points for varint encoding. - std::make_tuple((1ull << 7) - 1, TString("\x7f", 1)), - std::make_tuple((1ull << 7), TString("\x80\x01", 2)), - std::make_tuple((1ull << 14) - 1, TString("\xff\x7f", 2)), - std::make_tuple((1ull << 14), TString("\x80\x80\x01", 3)), - std::make_tuple((1ull << 21) - 1, TString("\xff\xff\x7f", 3)), - std::make_tuple((1ull << 21), TString("\x80\x80\x80\x01", 4)), - std::make_tuple((1ull << 28) - 1, TString("\xff\xff\xff\x7f", 4)), - std::make_tuple((1ull << 28), TString("\x80\x80\x80\x80\x01", 5)), - std::make_tuple((1ull << 35) - 1, TString("\xff\xff\xff\xff\x7f", 5)), - std::make_tuple((1ull << 35), TString("\x80\x80\x80\x80\x80\x01", 6)), - std::make_tuple((1ull << 42) - 1, TString("\xff\xff\xff\xff\xff\x7f", 6)), - std::make_tuple((1ull << 42), TString("\x80\x80\x80\x80\x80\x80\x01", 7)), - std::make_tuple((1ull << 49) - 1, TString("\xff\xff\xff\xff\xff\xff\x7f", 7)), - std::make_tuple((1ull << 49), TString("\x80\x80\x80\x80\x80\x80\x80\x01", 8)), - std::make_tuple((1ull << 56) - 1, TString("\xff\xff\xff\xff\xff\xff\xff\x7f", 8)), - std::make_tuple((1ull << 56), TString("\x80\x80\x80\x80\x80\x80\x80\x80\x01", 9)), - std::make_tuple((1ull << 63) - 1, TString("\xff\xff\xff\xff\xff\xff\xff\xff\x7f", 9)), - std::make_tuple((1ull << 63), TString("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01", 10)), + std::make_tuple((1ull << 7) - 1, std::string("\x7f", 1)), + std::make_tuple((1ull << 7), std::string("\x80\x01", 2)), + std::make_tuple((1ull << 14) - 1, std::string("\xff\x7f", 2)), + std::make_tuple((1ull << 14), std::string("\x80\x80\x01", 3)), + std::make_tuple((1ull << 21) - 1, std::string("\xff\xff\x7f", 3)), + std::make_tuple((1ull << 21), std::string("\x80\x80\x80\x01", 4)), + std::make_tuple((1ull << 28) - 1, std::string("\xff\xff\xff\x7f", 4)), + std::make_tuple((1ull << 28), std::string("\x80\x80\x80\x80\x01", 5)), + std::make_tuple((1ull << 35) - 1, std::string("\xff\xff\xff\xff\x7f", 5)), + std::make_tuple((1ull << 35), std::string("\x80\x80\x80\x80\x80\x01", 6)), + std::make_tuple((1ull << 42) - 1, std::string("\xff\xff\xff\xff\xff\x7f", 6)), + std::make_tuple((1ull << 42), std::string("\x80\x80\x80\x80\x80\x80\x01", 7)), + std::make_tuple((1ull << 49) - 1, std::string("\xff\xff\xff\xff\xff\xff\x7f", 7)), + std::make_tuple((1ull << 49), std::string("\x80\x80\x80\x80\x80\x80\x80\x01", 8)), + std::make_tuple((1ull << 56) - 1, std::string("\xff\xff\xff\xff\xff\xff\xff\x7f", 8)), + std::make_tuple((1ull << 56), std::string("\x80\x80\x80\x80\x80\x80\x80\x80\x01", 9)), + std::make_tuple((1ull << 63) - 1, std::string("\xff\xff\xff\xff\xff\xff\xff\xff\x7f", 9)), + std::make_tuple((1ull << 63), std::string("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01", 10)), // Boundary case. - std::make_tuple(static_cast<ui64>(-1), TString("\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01", 10)) + std::make_tuple(static_cast<ui64>(-1), std::string("\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01", 10)) ); INSTANTIATE_TEST_SUITE_P(ValueParametrized, TWriteVarIntTest, diff --git a/library/cpp/yt/compact_containers/unittests/compact_vector_ut.cpp b/library/cpp/yt/compact_containers/unittests/compact_vector_ut.cpp index 5ffc04efdc..fc40f6fdbe 100644 --- a/library/cpp/yt/compact_containers/unittests/compact_vector_ut.cpp +++ b/library/cpp/yt/compact_containers/unittests/compact_vector_ut.cpp @@ -273,7 +273,7 @@ TYPED_TEST(CompactVectorTest, InsertEnd) { SCOPED_TRACE("InsertEnd"); - TCompactVector<TString, 5> vector; + TCompactVector<std::string, 5> vector; for (int index = 0; index < 10; ++index) { vector.insert(vector.end(), ToString(index)); } @@ -286,7 +286,7 @@ TYPED_TEST(CompactVectorTest, ShrinkToSmall) { SCOPED_TRACE("ShrinkToSmall"); - TCompactVector<TString, 5> vector; + TCompactVector<std::string, 5> vector; for (int index = 0; index < 10; ++index) { vector.shrink_to_small(); vector.push_back(ToString(index)); @@ -1061,8 +1061,8 @@ TEST(CompactVectorTest, InitializerList) { } TEST(CompactVectorTest, AssignToShorter) { - TCompactVector<TString, 4> lhs; - TCompactVector<TString, 4> rhs; + TCompactVector<std::string, 4> lhs; + TCompactVector<std::string, 4> rhs; rhs.emplace_back("foo"); lhs = rhs; EXPECT_EQ(1U, lhs.size()); @@ -1070,10 +1070,10 @@ TEST(CompactVectorTest, AssignToShorter) { } TEST(CompactVectorTest, AssignToLonger) { - TCompactVector<TString, 4> lhs; + TCompactVector<std::string, 4> lhs; lhs.emplace_back("bar"); lhs.emplace_back("baz"); - TCompactVector<TString, 4> rhs; + TCompactVector<std::string, 4> rhs; rhs.emplace_back("foo"); lhs = rhs; EXPECT_EQ(1U, lhs.size()); diff --git a/library/cpp/yt/error/error-inl.h b/library/cpp/yt/error/error-inl.h index f82b8eb20d..6329528f02 100644 --- a/library/cpp/yt/error/error-inl.h +++ b/library/cpp/yt/error/error-inl.h @@ -55,14 +55,14 @@ constexpr bool TErrorCode::operator == (TErrorCode rhs) const namespace NDetail { template <class... TArgs> -TString FormatErrorMessage(TStringBuf format, TArgs&&... args) +std::string FormatErrorMessage(TStringBuf format, TArgs&&... args) { return Format(TRuntimeFormat{format}, std::forward<TArgs>(args)...); } -inline TString FormatErrorMessage(TStringBuf format) +inline std::string FormatErrorMessage(TStringBuf format) { - return TString(format); + return std::string(format); } } // namespace NDetail diff --git a/library/cpp/yt/error/error.cpp b/library/cpp/yt/error/error.cpp index 4790fbf606..636d7d81fc 100644 --- a/library/cpp/yt/error/error.cpp +++ b/library/cpp/yt/error/error.cpp @@ -46,14 +46,14 @@ public: , InnerErrors_(other.InnerErrors_) { } - explicit TImpl(TString message) + explicit TImpl(std::string message) : Code_(NYT::EErrorCode::Generic) , Message_(std::move(message)) { OriginAttributes_.Capture(); } - TImpl(TErrorCode code, TString message) + TImpl(TErrorCode code, std::string message) : Code_(code) , Message_(std::move(message)) { @@ -77,12 +77,12 @@ public: Code_ = code; } - const TString& GetMessage() const noexcept + const std::string& GetMessage() const noexcept { return Message_; } - TString* MutableMessage() noexcept + std::string* MutableMessage() noexcept { return &Message_; } @@ -164,7 +164,7 @@ public: private: TErrorCode Code_; - TString Message_; + std::string Message_; TOriginAttributes OriginAttributes_{ .Pid = 0, @@ -277,11 +277,11 @@ TError::TErrorOr(const std::exception& ex) YT_VERIFY(!IsOK()); } -TError::TErrorOr(TString message, TDisableFormat) +TError::TErrorOr(std::string message, TDisableFormat) : Impl_(std::make_unique<TImpl>(std::move(message))) { } -TError::TErrorOr(TErrorCode code, TString message, TDisableFormat) +TError::TErrorOr(TErrorCode code, std::string message, TDisableFormat) : Impl_(std::make_unique<TImpl>(code, std::move(message))) { } @@ -363,16 +363,16 @@ THashSet<TErrorCode> TError::GetDistinctNonTrivialErrorCodes() const return result; } -const TString& TError::GetMessage() const +const std::string& TError::GetMessage() const { if (!Impl_) { - static const TString Result; + static const std::string Result; return Result; } return Impl_->GetMessage(); } -TError& TError::SetMessage(TString message) +TError& TError::SetMessage(std::string message) { MakeMutable(); *Impl_->MutableMessage() = std::move(message); @@ -422,7 +422,7 @@ NThreading::TThreadId TError::GetTid() const TStringBuf TError::GetThreadName() const { if (!Impl_) { - static TString empty; + static std::string empty; return empty; } return Impl_->GetThreadName(); @@ -482,7 +482,7 @@ void TError::UpdateOriginAttributes() Impl_->UpdateOriginAttributes(); } -const TString InnerErrorsTruncatedKey("inner_errors_truncated"); +const std::string InnerErrorsTruncatedKey("inner_errors_truncated"); TError TError::Truncate( int maxInnerErrorCount, @@ -513,8 +513,7 @@ TError TError::Truncate( auto result = std::make_unique<TImpl>(); result->SetCode(GetCode()); - *result->MutableMessage() - = std::move(TruncateString(GetMessage(), stringLimit, ErrorMessageTruncatedSuffix)); + *result->MutableMessage() = TruncateString(GetMessage(), stringLimit, ErrorMessageTruncatedSuffix); if (Impl_->HasAttributes()) { truncateAttributes(Impl_->Attributes(), result->MutableAttributes()); } @@ -608,13 +607,13 @@ TError TError::Wrap() && return std::move(*this); } -Y_WEAK TString GetErrorSkeleton(const TError& /*error*/) +Y_WEAK std::string GetErrorSkeleton(const TError& /*error*/) { // Proper implementation resides in yt/yt/library/error_skeleton/skeleton.cpp. THROW_ERROR_EXCEPTION("Error skeleton implementation library is not linked; consider PEERDIR'ing yt/yt/library/error_skeleton"); } -TString TError::GetSkeleton() const +std::string TError::GetSkeleton() const { return GetErrorSkeleton(*this); } @@ -775,7 +774,7 @@ void AppendError(TStringBuilderBase* builder, const TError& error, int indent) AppendAttribute( builder, "host", - TString{originAttributes->Host}, + std::string{originAttributes->Host}, indent); } diff --git a/library/cpp/yt/error/error.h b/library/cpp/yt/error/error.h index beb097afe2..8b459d0beb 100644 --- a/library/cpp/yt/error/error.h +++ b/library/cpp/yt/error/error.h @@ -83,8 +83,8 @@ public: { }; static constexpr TDisableFormat DisableFormat = {}; - TErrorOr(TString message, TDisableFormat); - TErrorOr(TErrorCode code, TString message, TDisableFormat); + TErrorOr(std::string message, TDisableFormat); + TErrorOr(TErrorCode code, std::string message, TDisableFormat); template <class... TArgs> explicit TErrorOr( @@ -110,8 +110,8 @@ public: TErrorCode GetNonTrivialCode() const; THashSet<TErrorCode> GetDistinctNonTrivialErrorCodes() const; - const TString& GetMessage() const; - TError& SetMessage(TString message); + const std::string& GetMessage() const; + TError& SetMessage(std::string message); bool HasOriginAttributes() const; TProcessId GetPid() const; @@ -197,7 +197,7 @@ public: //! In order to prevent core -> re2 dependency, implementation belongs to a separate library //! yt/yt/library/error_skeleton. Calling this method without PEERDIR'ing implementation //! results in an exception. - TString GetSkeleton() const; + std::string GetSkeleton() const; TError& operator <<= (const TErrorAttribute& attribute) &; TError& operator <<= (const std::vector<TErrorAttribute>& attributes) &; @@ -281,7 +281,7 @@ public: const char* what() const noexcept override; private: - mutable TString CachedWhat_; + mutable std::string CachedWhat_; }; // Make these templates to avoid type erasure during throw. diff --git a/library/cpp/yt/error/error_attributes-inl.h b/library/cpp/yt/error/error_attributes-inl.h index 399c0792d4..310ededd02 100644 --- a/library/cpp/yt/error/error_attributes-inl.h +++ b/library/cpp/yt/error/error_attributes-inl.h @@ -55,8 +55,7 @@ template <class T> requires CConvertibleFromAttributeValue<T> T TErrorAttributes::GetAndRemove(const TKey& key, const T& defaultValue) { - auto value = Find<T>(key); - if (value) { + if (auto value = Find<T>(key)) { Remove(key); return *value; } else { diff --git a/library/cpp/yt/error/error_attributes.h b/library/cpp/yt/error/error_attributes.h index 8ab6388ef3..0ab0687dac 100644 --- a/library/cpp/yt/error/error_attributes.h +++ b/library/cpp/yt/error/error_attributes.h @@ -10,7 +10,7 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// // TODO(arkady-e1ppa): Try switching to TString/std::string eventually. -// representing text-encoded yson string eventually (maybe). +// representing text-encoded YSON string eventually (maybe). class TErrorAttributes { public: diff --git a/library/cpp/yt/error/error_code.cpp b/library/cpp/yt/error/error_code.cpp index 9cb0d57dc2..d82d03214d 100644 --- a/library/cpp/yt/error/error_code.cpp +++ b/library/cpp/yt/error/error_code.cpp @@ -85,7 +85,7 @@ bool TErrorCodeRegistry::TErrorCodeRangeInfo::Contains(int value) const return From <= value && value <= To; } -void TErrorCodeRegistry::RegisterErrorCodeRange(int from, int to, TString namespaceName, std::function<TString(int)> formatter) +void TErrorCodeRegistry::RegisterErrorCodeRange(int from, int to, std::string namespaceName, std::function<std::string(int)> formatter) { YT_VERIFY(from <= to); @@ -117,24 +117,26 @@ void TErrorCodeRegistry::CheckCodesAgainstRanges() const } } -TString TErrorCodeRegistry::ParseNamespace(const std::type_info& errorCodeEnumTypeInfo) +std::string TErrorCodeRegistry::ParseNamespace(const std::type_info& errorCodeEnumTypeInfo) { - TString name; + std::string name; // Ensures that "EErrorCode" is found as a substring in the type name and stores the prefix before // the first occurrence into #name. YT_VERIFY(StringSplitter( TypeName(errorCodeEnumTypeInfo)).SplitByString("EErrorCode").Limit(2).TryCollectInto(&name, &std::ignore)); // TypeName returns name in form "enum ErrorCode" on Windows - if (name.StartsWith("enum ")) { - name.remove(0, 5); + constexpr TStringBuf enumPrefix = "enum "; + if (name.starts_with(enumPrefix)) { + name.erase(0, enumPrefix.size()); } // If the enum was declared directly in the global namespace, #name should be empty. // Otherwise, #name should end with "::". + constexpr TStringBuf namespaceSeparator = "::"; if (!name.empty()) { - YT_VERIFY(name.EndsWith("::")); - name.resize(name.size() - 2); + YT_VERIFY(name.ends_with(namespaceSeparator)); + name.resize(name.size() - namespaceSeparator.size()); } return name; } diff --git a/library/cpp/yt/error/error_code.h b/library/cpp/yt/error/error_code.h index 1c2c08fbb4..fe1a25c3c3 100644 --- a/library/cpp/yt/error/error_code.h +++ b/library/cpp/yt/error/error_code.h @@ -19,9 +19,9 @@ public: struct TErrorCodeInfo { - TString Namespace; + std::string Namespace; //! Human-readable error code name. - TString Name; + std::string Name; bool operator==(const TErrorCodeInfo& rhs) const; }; @@ -30,8 +30,8 @@ public: { int From; int To; - TString Namespace; - std::function<TString(int code)> Formatter; + std::string Namespace; + std::function<std::string(int code)> Formatter; TErrorCodeInfo Get(int code) const; bool Intersects(const TErrorCodeRangeInfo& other) const; @@ -51,9 +51,9 @@ public: void RegisterErrorCode(int code, const TErrorCodeInfo& errorCodeInfo); //! Registers a range of error codes given a human-readable code to name formatter. - void RegisterErrorCodeRange(int from, int to, TString namespaceName, std::function<TString(int code)> formatter); + void RegisterErrorCodeRange(int from, int to, std::string namespaceName, std::function<std::string(int code)> formatter); - static TString ParseNamespace(const std::type_info& errorCodeEnumTypeInfo); + static std::string ParseNamespace(const std::type_info& errorCodeEnumTypeInfo); private: THashMap<int, TErrorCodeInfo> CodeToInfo_; diff --git a/library/cpp/yt/error/origin_attributes.cpp b/library/cpp/yt/error/origin_attributes.cpp index 2abb060ce2..69569762c4 100644 --- a/library/cpp/yt/error/origin_attributes.cpp +++ b/library/cpp/yt/error/origin_attributes.cpp @@ -84,7 +84,7 @@ std::optional<TOriginAttributes::TErasedExtensionData> GetExtensionData() return std::nullopt; } -TString FormatOrigin(const TOriginAttributes& attributes) +std::string FormatOrigin(const TOriginAttributes& attributes) { using TFunctor = TString(*)(const TOriginAttributes&); @@ -142,7 +142,7 @@ TOriginAttributes ExtractFromDictionaryDefault(TErrorAttributes* attributes) result.Tid = attributes->GetAndRemove(TidKey, NThreading::InvalidThreadId); static const std::string ThreadNameKey("thread"); - result.ThreadName = TString(attributes->GetAndRemove(ThreadNameKey, std::string())); + result.ThreadName = {attributes->GetAndRemove(ThreadNameKey, std::string())}; return result; } diff --git a/library/cpp/yt/error/origin_attributes.h b/library/cpp/yt/error/origin_attributes.h index e25eb37ea7..7d35446318 100644 --- a/library/cpp/yt/error/origin_attributes.h +++ b/library/cpp/yt/error/origin_attributes.h @@ -76,7 +76,7 @@ inline constexpr NGlobal::TVariableTag ExtractFromDictionaryTag = {}; // NB(arkady-e1ppa): ExtractFromDictionary symbol is left in yt/yt/core/misc/origin_attributes // because it depends on ytree for now. std::optional<TOriginAttributes::TErasedExtensionData> GetExtensionData(); -TString FormatOrigin(const TOriginAttributes& attributes); +std::string FormatOrigin(const TOriginAttributes& attributes); //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/error/text_yson.cpp b/library/cpp/yt/error/text_yson.cpp index 42ad52bbcc..698c2fd244 100644 --- a/library/cpp/yt/error/text_yson.cpp +++ b/library/cpp/yt/error/text_yson.cpp @@ -137,7 +137,7 @@ std::string ConvertToTextYsonString<double>(const double& value) "%v%v", str, MakeFormatterWrapper([&] (TStringBuilderBase* builder) { - if (str.find('.') == TString::npos && str.find('e') == TString::npos && std::isfinite(value)) { + if (str.find('.') == std::string::npos && str.find('e') == std::string::npos && std::isfinite(value)) { builder->AppendChar('.'); } })); @@ -233,13 +233,13 @@ TSomeInt ParseSomeIntFromTextYsonString(TStringBuf strBuf) //////////////////////////////////////////////////////////////////////////////// -TString DoParseStringFromTextYson(TStringBuf strBuf) +std::string DoParseStringFromTextYson(TStringBuf strBuf) { // Remove quotation marks. return ::UnescapeC(TStringBuf{strBuf.data() + 1, strBuf.length() - 2}); } -TString ParseStringFromTextYsonString(TStringBuf strBuf) +std::string ParseStringFromTextYsonString(TStringBuf strBuf) { if (std::ssize(strBuf) < 2 || strBuf.front() != '\"' || strBuf.back() != '\"') { THROW_ERROR_EXCEPTION( @@ -314,7 +314,7 @@ PARSE_INT(ui64, ui64) //////////////////////////////////////////////////////////////////////////////// template <> -TString ConvertFromTextYsonString<TString>(TStringBuf str) +std::string ConvertFromTextYsonString<std::string>(TStringBuf str) { try { return ParseStringFromTextYsonString(str); @@ -324,9 +324,9 @@ TString ConvertFromTextYsonString<TString>(TStringBuf str) } template <> -std::string ConvertFromTextYsonString<std::string>(TStringBuf str) +TString ConvertFromTextYsonString<TString>(TStringBuf str) { - return std::string(ConvertFromTextYsonString<TString>(str)); + return TString(ConvertFromTextYsonString<std::string>(str)); } template <> diff --git a/library/cpp/yt/error/unittests/error_code_ut.cpp b/library/cpp/yt/error/unittests/error_code_ut.cpp index 4bdb17f5d9..833982ea02 100644 --- a/library/cpp/yt/error/unittests/error_code_ut.cpp +++ b/library/cpp/yt/error/unittests/error_code_ut.cpp @@ -61,7 +61,7 @@ YT_DEFINE_ERROR_ENUM( ((Kukarek) (-2007)) ); -TString TestErrorCodeFormatter(int code) +std::string TestErrorCodeFormatter(int code) { return Format("formatted%v", code); } @@ -74,7 +74,7 @@ DEFINE_ENUM(EDifferentTestErrorCode, ((ErrorNumberThree) (-10002)) ); -TString DifferentTestErrorCodeFormatter(int code) +std::string DifferentTestErrorCodeFormatter(int code) { return TEnumTraits<EDifferentTestErrorCode>::ToString(static_cast<EDifferentTestErrorCode>(code)); } diff --git a/library/cpp/yt/error/unittests/error_ut.cpp b/library/cpp/yt/error/unittests/error_ut.cpp index a4248b3956..198aa1ecd8 100644 --- a/library/cpp/yt/error/unittests/error_ut.cpp +++ b/library/cpp/yt/error/unittests/error_ut.cpp @@ -202,7 +202,7 @@ void IterateTestOverEveryRightOperand(TOverloadTest& tester) } template <class T> -void SetErrorAttribute(TError* error, TString key, const T& value) +void SetErrorAttribute(TError* error, const std::string& key, const T& value) { *error <<= TErrorAttribute(key, value); } @@ -357,7 +357,7 @@ TEST(TErrorTest, ThrowErrorExceptionIfFailedMacroExpression) EXPECT_EQ(outerError.GetMessage(), "Outer error"); EXPECT_EQ(outerError.InnerErrors().size(), 1u); EXPECT_EQ(outerError.InnerErrors()[0].GetMessage(), "Inner error"); - EXPECT_EQ(outerError.InnerErrors()[0].Attributes().Get<TString>("attr"), "attr_value"); + EXPECT_EQ(outerError.InnerErrors()[0].Attributes().Get<std::string>("attr"), "attr_value"); } } @@ -427,7 +427,7 @@ TEST(TErrorTest, TruncateSimple) EXPECT_EQ(error.GetPid(), truncatedError.GetPid()); EXPECT_EQ(error.GetTid(), truncatedError.GetTid()); EXPECT_EQ(error.GetDatetime(), truncatedError.GetDatetime()); - EXPECT_EQ(error.Attributes().Get<TString>("my_attr"), truncatedError.Attributes().Get<TString>("my_attr")); + EXPECT_EQ(error.Attributes().Get<std::string>("my_attr"), truncatedError.Attributes().Get<std::string>("my_attr")); EXPECT_EQ(error.InnerErrors().size(), truncatedError.InnerErrors().size()); EXPECT_EQ(error.InnerErrors()[0].GetMessage(), truncatedError.InnerErrors()[0].GetMessage()); } @@ -444,7 +444,7 @@ TEST(TErrorTest, TruncateLarge) auto truncatedError = error.Truncate(/*maxInnerErrorCount*/ 3, /*stringLimit*/ 10); EXPECT_EQ(error.GetCode(), truncatedError.GetCode()); EXPECT_EQ("Some long ...<message truncated>", truncatedError.GetMessage()); - EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<TString>("my_attr")); + EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<std::string>("my_attr")); EXPECT_EQ(truncatedError.InnerErrors().size(), 3u); EXPECT_EQ("First inne...<message truncated>", truncatedError.InnerErrors()[0].GetMessage()); @@ -466,7 +466,7 @@ TEST(TErrorTest, TruncateSimpleRValue) EXPECT_EQ(error.GetPid(), truncatedError.GetPid()); EXPECT_EQ(error.GetTid(), truncatedError.GetTid()); EXPECT_EQ(error.GetDatetime(), truncatedError.GetDatetime()); - EXPECT_EQ(error.Attributes().Get<TString>("my_attr"), truncatedError.Attributes().Get<TString>("my_attr")); + EXPECT_EQ(error.Attributes().Get<std::string>("my_attr"), truncatedError.Attributes().Get<std::string>("my_attr")); EXPECT_EQ(error.InnerErrors().size(), truncatedError.InnerErrors().size()); EXPECT_EQ(error.InnerErrors()[0].GetMessage(), truncatedError.InnerErrors()[0].GetMessage()); } @@ -486,7 +486,7 @@ TEST(TErrorTest, TruncateLargeRValue) EXPECT_EQ(error.GetCode(), truncatedError.GetCode()); EXPECT_EQ("Some long ...<message truncated>", truncatedError.GetMessage()); - EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<TString>("my_attr")); + EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<std::string>("my_attr")); EXPECT_EQ(truncatedError.InnerErrors().size(), 3u); EXPECT_EQ("First inne...<message truncated>", truncatedError.InnerErrors()[0].GetMessage()); @@ -524,8 +524,8 @@ TEST(TErrorTest, TruncateWhitelist) EXPECT_EQ(error.GetCode(), truncatedError.GetCode()); EXPECT_EQ(error.GetMessage(), truncatedError.GetMessage()); - EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<TString>("attr1")); - EXPECT_EQ("Some long long attr", truncatedError.Attributes().Get<TString>("attr2")); + EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<std::string>("attr1")); + EXPECT_EQ("Some long long attr", truncatedError.Attributes().Get<std::string>("attr2")); } TEST(TErrorTest, TruncateWhitelistRValue) @@ -543,8 +543,8 @@ TEST(TErrorTest, TruncateWhitelistRValue) EXPECT_EQ(error.GetCode(), truncatedError.GetCode()); EXPECT_EQ(error.GetMessage(), truncatedError.GetMessage()); - EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<TString>("attr1")); - EXPECT_EQ("Some long long attr", truncatedError.Attributes().Get<TString>("attr2")); + EXPECT_EQ("...<attribute truncated>...", truncatedError.Attributes().Get<std::string>("attr1")); + EXPECT_EQ("Some long long attr", truncatedError.Attributes().Get<std::string>("attr2")); } TEST(TErrorTest, TruncateWhitelistInnerErrors) @@ -563,8 +563,8 @@ TEST(TErrorTest, TruncateWhitelistInnerErrors) auto truncatedInnerError = truncatedError.InnerErrors()[0]; EXPECT_EQ(truncatedInnerError.GetCode(), innerError.GetCode()); EXPECT_EQ(truncatedInnerError.GetMessage(), innerError.GetMessage()); - EXPECT_EQ("...<attribute truncated>...", truncatedInnerError.Attributes().Get<TString>("attr1")); - EXPECT_EQ("Some long long attr", truncatedInnerError.Attributes().Get<TString>("attr2")); + EXPECT_EQ("...<attribute truncated>...", truncatedInnerError.Attributes().Get<std::string>("attr1")); + EXPECT_EQ("Some long long attr", truncatedInnerError.Attributes().Get<std::string>("attr2")); } TEST(TErrorTest, TruncateWhitelistInnerErrorsRValue) @@ -585,8 +585,8 @@ TEST(TErrorTest, TruncateWhitelistInnerErrorsRValue) auto truncatedInnerError = truncatedError.InnerErrors()[0]; EXPECT_EQ(truncatedInnerError.GetCode(), innerError.GetCode()); EXPECT_EQ(truncatedInnerError.GetMessage(), innerError.GetMessage()); - EXPECT_EQ("...<attribute truncated>...", truncatedInnerError.Attributes().Get<TString>("attr1")); - EXPECT_EQ("Some long long attr", truncatedInnerError.Attributes().Get<TString>("attr2")); + EXPECT_EQ("...<attribute truncated>...", truncatedInnerError.Attributes().Get<std::string>("attr1")); + EXPECT_EQ("Some long long attr", truncatedInnerError.Attributes().Get<std::string>("attr2")); } TEST(TErrorTest, TruncateWhitelistSaveInnerError) @@ -668,7 +668,7 @@ TEST(TErrorTest, YTExceptionWithAttributesToError) EXPECT_TRUE(boolValue); EXPECT_EQ(*boolValue, false); - auto stringValue = error.Attributes().Find<TString>("String value"); + auto stringValue = error.Attributes().Find<std::string>("String value"); EXPECT_TRUE(stringValue); EXPECT_EQ(*stringValue, "FooBar"); } @@ -677,19 +677,19 @@ TEST(TErrorTest, YTExceptionWithAttributesToError) TEST(TErrorTest, AttributeSerialization) { auto getWeededText = [] (const TError& err) { - std::vector<TString> lines; + std::vector<std::string> lines; for (const auto& line : StringSplitter(ToString(err)).Split('\n')) { if (!line.Contains("origin") && !line.Contains("datetime")) { - lines.push_back(TString{line}); + lines.push_back(std::string{line}); } } return JoinSeq("\n", lines); }; - EXPECT_EQ(getWeededText(TError("E1") << TErrorAttribute("A1", "V1")), TString( + EXPECT_EQ(getWeededText(TError("E1") << TErrorAttribute("A1", "V1")), std::string( "E1\n" " A1 V1\n")); - EXPECT_EQ(getWeededText(TError("E1") << TErrorAttribute("A1", "L1\nL2\nL3")), TString( + EXPECT_EQ(getWeededText(TError("E1") << TErrorAttribute("A1", "L1\nL2\nL3")), std::string( "E1\n" " A1\n" " L1\n" diff --git a/library/cpp/yt/exception/exception.cpp b/library/cpp/yt/exception/exception.cpp index 71ece1ff2e..5a1e33d7a6 100644 --- a/library/cpp/yt/exception/exception.cpp +++ b/library/cpp/yt/exception/exception.cpp @@ -20,14 +20,14 @@ void AddAttributes(TSimpleException::TAttributes& attrs, TRange&& range) //////////////////////////////////////////////////////////////////////////////// -TSimpleException::TSimpleException(TString message) +TSimpleException::TSimpleException(std::string message) : Message_(std::move(message)) , What_(Message_) { } TSimpleException::TSimpleException( const std::exception& exception, - TString message) + std::string message) : InnerException_(std::current_exception()) , Message_(std::move(message)) , What_(Message_ + "\n" + exception.what()) @@ -43,7 +43,7 @@ const char* TSimpleException::what() const noexcept return What_.c_str(); } -const TString& TSimpleException::GetMessage() const +const std::string& TSimpleException::GetMessage() const { return Message_; } diff --git a/library/cpp/yt/exception/exception.h b/library/cpp/yt/exception/exception.h index 2898b99f0d..6e939d072a 100644 --- a/library/cpp/yt/exception/exception.h +++ b/library/cpp/yt/exception/exception.h @@ -25,15 +25,15 @@ public: { ex <<= std::forward<TValue>(operand) } -> std::same_as<TSimpleException&>; }; - explicit TSimpleException(TString message); + explicit TSimpleException(std::string message); TSimpleException( const std::exception& exception, - TString message); + std::string message); const std::exception_ptr& GetInnerException() const; const char* what() const noexcept override; - const TString& GetMessage() const; + const std::string& GetMessage() const; const TAttributes& GetAttributes() const &; TAttributes&& GetAttributes() &&; @@ -65,8 +65,8 @@ public: private: const std::exception_ptr InnerException_; - const TString Message_; - const TString What_; + const std::string Message_; + const std::string What_; TAttributes Attributes_; }; diff --git a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp index 8b46d5679f..c23c5693b0 100644 --- a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp +++ b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp @@ -66,7 +66,7 @@ private: IOutputStream* const Output_; NThreading::TForkAwareSpinLock SpinLock_; - THashMap<TString, std::unique_ptr<TLoggingCategory>> NameToCategory_; + THashMap<std::string, std::unique_ptr<TLoggingCategory>, THash<TStringBuf>, TEqualTo<TStringBuf>> NameToCategory_; std::atomic<int> Version_ = 1; TPlainTextEventFormatter EventFormatter_{/*enableSourceLocation*/ false}; diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h index 510acf1310..53bb13e705 100644 --- a/library/cpp/yt/logging/logger.h +++ b/library/cpp/yt/logging/logger.h @@ -30,7 +30,7 @@ constexpr double DefaultStructuredValidationSamplingRate = 0.01; struct TLoggingCategory { - TString Name; + std::string Name; //! This value is used for early dropping of plaintext events in order //! to reduce load on logging thread for events which are definitely going //! to be dropped due to rule setup. @@ -50,7 +50,7 @@ struct TLoggingAnchor TLoggingAnchor* NextAnchor = nullptr; ::TSourceLocation SourceLocation = {TStringBuf{}, 0}; - TString AnchorMessage; + std::string AnchorMessage; std::atomic<int> CurrentVersion = 0; diff --git a/library/cpp/yt/misc/guid.cpp b/library/cpp/yt/misc/guid.cpp index fc4f146532..0dcb9a1f7e 100644 --- a/library/cpp/yt/misc/guid.cpp +++ b/library/cpp/yt/misc/guid.cpp @@ -49,7 +49,7 @@ TGuid TGuid::FromString(TStringBuf str) TGuid guid; if (!FromString(str, &guid)) { throw TSimpleException(Sprintf("Error parsing GUID \"%s\"", - TString(str).c_str())); + std::string(str).c_str())); } return guid; } @@ -106,7 +106,7 @@ TGuid TGuid::FromStringHex32(TStringBuf str) TGuid guid; if (!FromStringHex32(str, &guid)) { throw TSimpleException(Sprintf("Error parsing Hex32 GUID \"%s\"", - TString(str).c_str())); + str.data())); } return guid; } diff --git a/library/cpp/yt/misc/thread_name.cpp b/library/cpp/yt/misc/thread_name.cpp index bb1737b08a..11e20abcf5 100644 --- a/library/cpp/yt/misc/thread_name.cpp +++ b/library/cpp/yt/misc/thread_name.cpp @@ -20,7 +20,7 @@ TStringBuf TThreadName::ToStringBuf() const //////////////////////////////////////////////////////////////////////////////// -TThreadName::TThreadName(const TString& name) +TThreadName::TThreadName(TStringBuf name) { Length = std::min<int>(TThreadName::BufferCapacity - 1, name.length()); ::memcpy(Buffer.data(), name.data(), Length); diff --git a/library/cpp/yt/misc/thread_name.h b/library/cpp/yt/misc/thread_name.h index 233808f99f..3515388083 100644 --- a/library/cpp/yt/misc/thread_name.h +++ b/library/cpp/yt/misc/thread_name.h @@ -11,7 +11,7 @@ namespace NYT { struct TThreadName { TThreadName() = default; - TThreadName(const TString& name); + TThreadName(TStringBuf name); TStringBuf ToStringBuf() const; diff --git a/library/cpp/yt/string/enum-inl.h b/library/cpp/yt/string/enum-inl.h index 84b0941d15..9f8ca893d2 100644 --- a/library/cpp/yt/string/enum-inl.h +++ b/library/cpp/yt/string/enum-inl.h @@ -129,7 +129,7 @@ void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase) } template <class T> -TString FormatEnum(T value) +std::string FormatEnum(T value) { TStringBuilder builder; FormatEnum(&builder, value, /*lowerCase*/ true); diff --git a/library/cpp/yt/string/enum.cpp b/library/cpp/yt/string/enum.cpp index 935c3e6e3e..844254faa0 100644 --- a/library/cpp/yt/string/enum.cpp +++ b/library/cpp/yt/string/enum.cpp @@ -16,7 +16,7 @@ void ThrowMalformedEnumValueException(TStringBuf typeName, TStringBuf value) } template <bool ThrowOnError> -std::optional<TString> DecodeEnumValueImpl(TStringBuf value) +std::optional<std::string> DecodeEnumValueImpl(TStringBuf value) { auto camelValue = UnderscoreCaseToCamelCase(value); auto underscoreValue = CamelCaseToUnderscoreCase(camelValue); @@ -34,19 +34,19 @@ std::optional<TString> DecodeEnumValueImpl(TStringBuf value) } // namespace NDetail -std::optional<TString> TryDecodeEnumValue(TStringBuf value) +std::optional<std::string> TryDecodeEnumValue(TStringBuf value) { return NDetail::DecodeEnumValueImpl<false>(value); } -TString DecodeEnumValue(TStringBuf value) +std::string DecodeEnumValue(TStringBuf value) { auto decodedValue = NDetail::DecodeEnumValueImpl<true>(value); YT_VERIFY(decodedValue); return *decodedValue; } -TString EncodeEnumValue(TStringBuf value) +std::string EncodeEnumValue(TStringBuf value) { return CamelCaseToUnderscoreCase(value); } diff --git a/library/cpp/yt/string/enum.h b/library/cpp/yt/string/enum.h index a0be527583..de7d6a52fa 100644 --- a/library/cpp/yt/string/enum.h +++ b/library/cpp/yt/string/enum.h @@ -10,9 +10,9 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -std::optional<TString> TryDecodeEnumValue(TStringBuf value); -TString DecodeEnumValue(TStringBuf value); -TString EncodeEnumValue(TStringBuf value); +std::optional<std::string> TryDecodeEnumValue(TStringBuf value); +std::string DecodeEnumValue(TStringBuf value); +std::string EncodeEnumValue(TStringBuf value); template <class T> std::optional<T> TryParseEnum(TStringBuf str, bool enableUnknown = false); @@ -24,7 +24,7 @@ template <class T> void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase); template <class T> -TString FormatEnum(T value); +std::string FormatEnum(T value); //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/string/string.cpp b/library/cpp/yt/string/string.cpp index b9c3236134..ed51f453fb 100644 --- a/library/cpp/yt/string/string.cpp +++ b/library/cpp/yt/string/string.cpp @@ -359,7 +359,7 @@ TStringBuf FormatBool(bool value) //////////////////////////////////////////////////////////////////////////////// -void TruncateStringInplace(TString* string, int lengthLimit, TStringBuf truncatedSuffix) +void TruncateStringInplace(std::string* string, int lengthLimit, TStringBuf truncatedSuffix) { if (std::ssize(*string) > lengthLimit) { string->resize(lengthLimit); @@ -367,7 +367,7 @@ void TruncateStringInplace(TString* string, int lengthLimit, TStringBuf truncate } } -TString TruncateString(TString string, int lengthLimit, TStringBuf truncatedSuffix) +std::string TruncateString(std::string string, int lengthLimit, TStringBuf truncatedSuffix) { TruncateStringInplace(&string, lengthLimit, truncatedSuffix); return string; diff --git a/library/cpp/yt/string/string.h b/library/cpp/yt/string/string.h index ac5aa5d4e4..5e472a572c 100644 --- a/library/cpp/yt/string/string.h +++ b/library/cpp/yt/string/string.h @@ -183,9 +183,8 @@ TStringBuf FormatBool(bool value); inline constexpr TStringBuf DefaultTruncatedMessage = "...<truncated>"; -void TruncateStringInplace(TString* string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage); - -TString TruncateString(TString string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage); +void TruncateStringInplace(std::string* string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage); +std::string TruncateString(std::string string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage); //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/string/unittests/guid_ut.cpp b/library/cpp/yt/string/unittests/guid_ut.cpp index ed02b87391..9cff37c380 100644 --- a/library/cpp/yt/string/unittests/guid_ut.cpp +++ b/library/cpp/yt/string/unittests/guid_ut.cpp @@ -12,7 +12,7 @@ namespace { static_assert(CFormattable<TGuid>); -TString CanonicalToString(TGuid value) +std::string CanonicalToString(TGuid value) { return Sprintf("%x-%x-%x-%x", value.Parts32[3], @@ -48,7 +48,7 @@ TEST(TGuidTest, FormatAllSymbols) TEST(TGuidTest, ByteOrder) { auto guid = TGuid::FromStringHex32("12345678ABCDEF0112345678ABCDEF01"); - TString bytes{reinterpret_cast<const char*>(&(guid.Parts32[0])), 16}; + std::string bytes{reinterpret_cast<const char*>(&(guid.Parts32[0])), 16}; EXPECT_EQ(HexEncode(bytes), "01EFCDAB7856341201EFCDAB78563412"); } |