aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/str.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/stream/str.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream/str.h')
-rw-r--r--util/stream/str.h122
1 files changed, 61 insertions, 61 deletions
diff --git a/util/stream/str.h b/util/stream/str.h
index 028bd572c0..fc45baec27 100644
--- a/util/stream/str.h
+++ b/util/stream/str.h
@@ -1,12 +1,12 @@
#pragma once
-
+
#include "zerocopy.h"
#include "zerocopy_output.h"
-
+
#include <util/generic/string.h>
#include <util/generic/noncopyable.h>
#include <util/generic/store_policy.h>
-
+
/**
* @addtogroup Streams_Strings
* @{
@@ -16,7 +16,7 @@
* Input stream for reading data from a string.
*/
class TStringInput: public IZeroCopyInputFastReadTo {
-public:
+public:
/**
* Constructs a string input stream that reads character data from the
* provided string.
@@ -31,38 +31,38 @@ public:
*/
inline TStringInput(const TString& s) noexcept
: S_(&s)
- , Pos_(0)
- {
- }
-
+ , Pos_(0)
+ {
+ }
+
TStringInput(const TString&&) = delete;
~TStringInput() override;
-
+
TStringInput(TStringInput&&) noexcept = default;
TStringInput& operator=(TStringInput&&) noexcept = default;
- inline void Swap(TStringInput& s) noexcept {
- DoSwap(S_, s.S_);
- DoSwap(Pos_, s.Pos_);
- }
-
+ inline void Swap(TStringInput& s) noexcept {
+ DoSwap(S_, s.S_);
+ DoSwap(Pos_, s.Pos_);
+ }
+
protected:
size_t DoNext(const void** ptr, size_t len) override;
void DoUndo(size_t len) override;
-
-private:
+
+private:
const TString* S_;
- size_t Pos_;
+ size_t Pos_;
friend class TStringStream;
-};
-
+};
+
/**
* Stream for writing data into a string.
*/
class TStringOutput: public IZeroCopyOutput {
-public:
+public:
/**
* Constructs a string output stream that appends character data to the
* provided string.
@@ -74,74 +74,74 @@ public:
* @param s String to append to.
*/
inline TStringOutput(TString& s) noexcept
- : S_(&s)
- {
- }
-
- TStringOutput(TStringOutput&& s) noexcept = default;
+ : S_(&s)
+ {
+ }
+
+ TStringOutput(TStringOutput&& s) noexcept = default;
~TStringOutput() override;
-
+
/**
* @param size Number of additional characters to
* reserve in output string.
*/
inline void Reserve(size_t size) {
- S_->reserve(S_->size() + size);
- }
-
- inline void Swap(TStringOutput& s) noexcept {
- DoSwap(S_, s.S_);
+ S_->reserve(S_->size() + size);
}
+ inline void Swap(TStringOutput& s) noexcept {
+ DoSwap(S_, s.S_);
+ }
+
protected:
size_t DoNext(void** ptr) override;
void DoUndo(size_t len) override;
void DoWrite(const void* buf, size_t len) override;
void DoWriteC(char c) override;
-
-private:
- TString* S_;
-};
-
+
+private:
+ TString* S_;
+};
+
/**
* String input/output stream, similar to `std::stringstream`.
*/
class TStringStream: private TEmbedPolicy<TString>, public TStringInput, public TStringOutput {
using TEmbeddedString = TEmbedPolicy<TString>;
-public:
- inline TStringStream()
+public:
+ inline TStringStream()
: TEmbeddedString()
, TStringInput(*TEmbeddedString::Ptr())
, TStringOutput(*TEmbeddedString::Ptr())
- {
- }
-
+ {
+ }
+
inline TStringStream(const TString& string)
: TEmbeddedString(string)
, TStringInput(*TEmbeddedString::Ptr())
, TStringOutput(*TEmbeddedString::Ptr())
- {
- }
+ {
+ }
- inline TStringStream(const TStringStream& other)
+ inline TStringStream(const TStringStream& other)
: TEmbeddedString(other.Str())
, TStringInput(*TEmbeddedString::Ptr())
, TStringOutput(*TEmbeddedString::Ptr())
- {
- }
+ {
+ }
- inline TStringStream& operator=(const TStringStream& other) {
- // All references remain alive, we need to change position only
+ inline TStringStream& operator=(const TStringStream& other) {
+ // All references remain alive, we need to change position only
Str() = other.Str();
- Pos_ = other.Pos_;
-
- return *this;
- }
+ Pos_ = other.Pos_;
+
+ return *this;
+ }
~TStringStream() override;
-
+
/**
* @returns Whether @c this contains any data
*/
@@ -151,17 +151,17 @@ public:
/**
* @returns String that this stream is writing into.
- */
+ */
inline TString& Str() noexcept {
return *Ptr();
- }
-
+ }
+
/**
* @returns String that this stream is writing into.
*/
inline const TString& Str() const noexcept {
return *Ptr();
- }
+ }
/**
* @returns Pointer to the character data contained
@@ -186,7 +186,7 @@ public:
* @returns Whether the string that this stream
* operates on is empty.
*/
- Y_PURE_FUNCTION inline bool Empty() const noexcept {
+ Y_PURE_FUNCTION inline bool Empty() const noexcept {
return Str().empty();
}
@@ -203,13 +203,13 @@ public:
// TODO: compatibility with existing code, remove
- Y_PURE_FUNCTION bool empty() const {
+ Y_PURE_FUNCTION bool empty() const {
return Empty();
}
void clear() {
Clear();
}
-};
-
+};
+
/** @} */