Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
StringBuffer.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
22#pragma once
23
25#include "sese/Config.h"
26
27#include <mutex>
28
29#ifdef _WIN32
30#pragma warning(disable : 4275)
31#pragma warning(disable : 4251)
32#endif
33
34namespace sese::text {
35
39class StringBuffer final : private AbstractStringBuffer {
40public:
41 using Ptr = std::unique_ptr<StringBuffer>;
42
43 explicit StringBuffer(size_t cap = STRING_BUFFER_SIZE_FACTOR) noexcept;
44 explicit StringBuffer(const char *str) noexcept;
45
46public:
47 void append(char ch) noexcept override;
48 void append(const char *str) noexcept override;
49 void append(const std::string &str) noexcept override;
50 void append(const std::string_view &str) noexcept override;
51 void append(const String &str) noexcept override;
52 void append(const StringView &str) noexcept override;
53 void append(const char *data, size_t length) noexcept override;
54 [[nodiscard]] size_t length() noexcept;
55 [[nodiscard]] size_t size() noexcept;
56 [[nodiscard]] bool empty() noexcept;
57 void clear() noexcept override;
58 void reverse() noexcept override;
59 [[nodiscard]] char getCharAt(int index);
60 bool setChatAt(int index, char ch) override;
61 bool delCharAt(int index) override;
62 bool del(int start, int len) override;
63 bool insertAt(int index, const char *str) override;
64 bool insertAt(int index, const std::string &str) override;
65 bool insertAt(int index, const std::string_view &str) override;
66 bool insertAt(int index, const String &str) override;
67 bool insertAt(int index, const StringView &str) override;
68 void trim() noexcept override;
69 [[nodiscard]] std::vector<std::string> split(const std::string &str) noexcept;
70 [[nodiscard]] bool startsWith(const std::string_view &prefix) noexcept;
71 [[nodiscard]] bool endsWith(const std::string_view &suffix) noexcept;
72 std::string toString() override;
73 String toSString() override;
74
75private:
81
83};
84} // namespace sese::text
85
86sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, char ch);
87
88sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const char *str);
89
90sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const std::string &str);
91
92sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const std::string_view &str);
93
94sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const sese::text::String &str);
95
96sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const sese::text::StringView &str);