Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
StringBuffer.h
浏览该文件的文档.
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
21#pragma once
22
24#include "sese/Config.h"
25
26#include <mutex>
27
28#ifdef _WIN32
29#pragma warning(disable : 4275)
30#pragma warning(disable : 4251)
31#endif
32
33namespace sese::text {
34
38class StringBuffer final : private AbstractStringBuffer {
39public:
40 using Ptr = std::unique_ptr<StringBuffer>;
41
42 explicit StringBuffer(size_t cap = STRING_BUFFER_SIZE_FACTOR) noexcept;
43 explicit StringBuffer(const char *str) noexcept;
44
45public:
46 void append(char ch) noexcept override;
47 void append(const char *str) noexcept override;
48 void append(const std::string &str) noexcept override;
49 void append(const std::string_view &str) noexcept override;
50 void append(const String &str) noexcept override;
51 void append(const StringView &str) noexcept override;
52 void append(const char *data, size_t length) noexcept override;
53 [[nodiscard]] size_t length() noexcept;
54 [[nodiscard]] size_t size() noexcept;
55 [[nodiscard]] bool empty() noexcept;
56 void clear() noexcept override;
57 void reverse() noexcept override;
58 [[nodiscard]] char getCharAt(int index);
59 bool setChatAt(int index, char ch) override;
60 bool delCharAt(int index) override;
61 bool del(int start, int len) override;
62 bool insertAt(int index, const char *str) override;
63 bool insertAt(int index, const std::string &str) override;
64 bool insertAt(int index, const std::string_view &str) override;
65 bool insertAt(int index, const String &str) override;
66 bool insertAt(int index, const StringView &str) override;
67 void trim() noexcept override;
68 [[nodiscard]] std::vector<std::string> split(const std::string &str) noexcept;
69 [[nodiscard]] bool startsWith(const std::string_view &prefix) noexcept;
70 [[nodiscard]] bool endsWith(const std::string_view &suffix) noexcept;
71 std::string toString() override;
72 String toSString() override;
73
74private:
80
82};
83} // namespace sese::text
84
85sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, char ch);
86
87sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const char *str);
88
89sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const std::string &str);
90
91sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const std::string_view &str);
92
93sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const sese::text::String &str);
94
95sese::text::StringBuffer &operator<<(sese::text::StringBuffer &buffer, const sese::text::StringView &str);