MCPcopy Create free account
hub / github.com/catboost/catboost / TStringBase

Class TStringBase

util/generic/strbase.h:38–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>>
38class TStringBase {
39 using TStringView = std::basic_string_view<TCharType>;
40 using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>;
41
42public:
43 using TChar = TCharType;
44 using TTraits = TTraitsType;
45 using TSelf = TStringBase<TDerived, TChar, TTraits>;
46
47 using size_type = size_t;
48 using difference_type = ptrdiff_t;
49 static constexpr size_t npos = size_t(-1);
50
51 using const_iterator = const TCharType*;
52 using const_reference = const TCharType&;
53
54 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
55
56 static constexpr size_t StrLen(const TCharType* s) noexcept {
57 if (Y_LIKELY(s)) {
58 return TTraits::length(s);
59 }
60 return 0;
61 }
62
63 template <class TCharTraits>
64 inline constexpr operator std::basic_string_view<TCharType, TCharTraits>() const {
65 return std::basic_string_view<TCharType, TCharTraits>(data(), size());
66 }
67
68 template <class TCharTraits, class Allocator>
69 inline explicit operator std::basic_string<TCharType, TCharTraits, Allocator>() const {
70 return std::basic_string<TCharType, TCharTraits, Allocator>(Ptr(), Len());
71 }
72
73 /**
74 * @param Pointer to character inside the string, or nullptr.
75 * @return Offset from string beginning (in chars), or npos on nullptr.
76 */
77 inline size_t off(const TCharType* ret) const noexcept {
78 return ret ? (size_t)(ret - Ptr()) : npos;
79 }
80
81 inline size_t IterOff(const_iterator it) const noexcept {
82 return begin() <= it && end() > it ? size_t(it - begin()) : npos;
83 }
84
85 constexpr const_iterator begin() const noexcept {
86 return Ptr();
87 }
88
89 constexpr const_iterator end() const noexcept {
90 return Ptr() + size();
91 }
92
93 constexpr const_iterator cbegin() const noexcept {
94 return begin();
95 }

Callers

nothing calls this directly

Calls 2

TDerivedClass · 0.70
emptyFunction · 0.50

Tested by

no test coverage detected