Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
AbstractStringBuffer.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
22#pragma once
23
24#include "sese/Config.h"
25#include "sese/text/String.h"
26
27#include <vector>
28
29namespace sese::text {
30
35public:
39 explicit AbstractStringBuffer(size_t cap = STRING_BUFFER_SIZE_FACTOR) noexcept;
44 explicit AbstractStringBuffer(const char *str) noexcept;
45 virtual ~AbstractStringBuffer() noexcept;
46
47 AbstractStringBuffer(const AbstractStringBuffer &abstract_string_buffer) noexcept;
48 AbstractStringBuffer(AbstractStringBuffer &&abstract_string_buffer) noexcept;
49
50 static std::vector<std::string> split(const std::string_view &text, const std::string_view &sub) noexcept;
51 static bool startsWith(const std::string_view &text, const std::string_view &prefix) noexcept;
52 static bool endsWith(const std::string_view &text, const std::string_view &suffix) noexcept;
53
54protected:
55 size_t cap{};
56 size_t len = 0;
57 char *buffer = nullptr;
58
59protected:
64 void expansion(size_t new_size) noexcept;
65
66
67 bool insertAt(int index, const char *data, size_t len);
68
69public:
70 virtual void append(char ch) noexcept;
71 virtual void append(const char *str) noexcept;
72 virtual void append(const std::string &str) noexcept;
73 virtual void append(const std::string_view &str) noexcept;
74 virtual void append(const String &str) noexcept;
75 virtual void append(const StringView &view) noexcept;
76 virtual void append(const char *data, size_t len) noexcept;
77 [[nodiscard]] virtual size_t length() const noexcept { return this->len; }
78 [[nodiscard]] virtual size_t size() const noexcept { return this->cap; }
79 [[nodiscard]] virtual bool empty() const noexcept { return 0 == this->len; };
80 virtual void clear() noexcept;
81 virtual void reverse() noexcept;
82 [[nodiscard]] virtual char getCharAt(int index) const;
83 virtual bool setChatAt(int index, char ch);
84 virtual bool delCharAt(int index);
85 virtual bool del(int start, int l);
86 virtual bool insertAt(int index, const char *str);
87 virtual bool insertAt(int index, const std::string &str);
88 virtual bool insertAt(int index, const std::string_view &str);
89 virtual bool insertAt(int index, const String &str);
90 virtual bool insertAt(int index, const StringView &view);
92 virtual void trim() noexcept;
93 [[nodiscard]] virtual std::vector<std::string> split(const std::string_view &str) const noexcept;
94 [[nodiscard]] virtual bool startsWith(const std::string_view &prefix) const noexcept;
95 [[nodiscard]] virtual bool endsWith(const std::string_view &suffix) const noexcept;
96 virtual std::string toString();
97 virtual String toSString();
98 virtual void *buf();
99};
100
101} // namespace sese::text