SHA256
统一命名
This commit is contained in:
+36
-36
@@ -11,69 +11,69 @@ namespace bstl {
|
||||
class String {
|
||||
public:
|
||||
String();
|
||||
String(const std::string& str);
|
||||
String(std::string str);
|
||||
String(const char* str);
|
||||
String(const String& other) = default;
|
||||
String& operator=(const String& other) = default;
|
||||
|
||||
// 获取标准字符串
|
||||
std::string str() const;
|
||||
const char* c_str() const;
|
||||
size_t length() const;
|
||||
size_t size() const;
|
||||
bool empty() const;
|
||||
[[nodiscard]] std::string str() const;
|
||||
[[nodiscard]] const char* c_str() const;
|
||||
[[nodiscard]] size_t length() const;
|
||||
[[nodiscard]] size_t size() const;
|
||||
[[nodiscard]] bool empty() const;
|
||||
|
||||
// 获取/修改字符
|
||||
char at(size_t pos) const;
|
||||
[[nodiscard]] char at(size_t pos) const;
|
||||
char operator[](size_t pos) const;
|
||||
char& operator[](size_t pos);
|
||||
|
||||
// 分割 - 按分隔符分割字符串
|
||||
std::vector<String> split(const String& delimiter = " ") const;
|
||||
[[nodiscard]] std::vector<String> split(const String& delimiter = " ") const;
|
||||
|
||||
// 连接 - 用分隔符连接多个字符串
|
||||
static String join(const std::vector<String>& parts, const String& delimiter = "");
|
||||
|
||||
// 替换 - 替换第一个/所有匹配项
|
||||
String replace(const String& oldStr, const String& newStr, int count = -1) const;
|
||||
[[nodiscard]] String replace(const String& oldStr, const String& newStr, int count = -1) const;
|
||||
|
||||
// 大小写转换
|
||||
String upper() const;
|
||||
String lower() const;
|
||||
String capitalize() const; // 首字母大写
|
||||
String title() const; // 每个单词首字母大写
|
||||
[[nodiscard]] String upper() const;
|
||||
[[nodiscard]] String lower() const;
|
||||
[[nodiscard]] String capitalize() const; // 首字母大写
|
||||
[[nodiscard]] String title() const; // 每个单词首字母大写
|
||||
|
||||
// 判断函数
|
||||
bool startswith(const String& prefix) const;
|
||||
bool endswith(const String& suffix) const;
|
||||
bool contains(const String& substring) const;
|
||||
bool isdigit() const;
|
||||
bool isalpha() const;
|
||||
bool isalnum() const;
|
||||
bool isspace() const;
|
||||
bool isupper() const;
|
||||
bool islower() const;
|
||||
[[nodiscard]] bool startswith(const String& prefix) const;
|
||||
[[nodiscard]] bool endswith(const String& suffix) const;
|
||||
[[nodiscard]] bool contains(const String& substring) const;
|
||||
[[nodiscard]] bool isdigit() const;
|
||||
[[nodiscard]] bool isalpha() const;
|
||||
[[nodiscard]] bool isalnum() const;
|
||||
[[nodiscard]] bool isspace() const;
|
||||
[[nodiscard]] bool isupper() const;
|
||||
[[nodiscard]] bool islower() const;
|
||||
|
||||
// 查找和计数
|
||||
int find(const String& substring, size_t start = 0) const;
|
||||
int rfind(const String& substring) const; // 从后往前查找
|
||||
int count(const String& substring) const;
|
||||
[[nodiscard]] int find(const String& substring, size_t start = 0) const;
|
||||
[[nodiscard]] int rfind(const String& substring) const; // 从后往前查找
|
||||
[[nodiscard]] int count(const String& substring) const;
|
||||
|
||||
// 去除空格和其他字符
|
||||
String strip() const; // 去除前后空格
|
||||
String lstrip() const; // 去除前导空格
|
||||
String rstrip() const; // 去除尾部空格
|
||||
String strip(const String& chars) const; // 去除指定字符
|
||||
[[nodiscard]] String strip() const; // 去除前后空格
|
||||
[[nodiscard]] String lstrip() const; // 去除前导空格
|
||||
[[nodiscard]] String rstrip() const; // 去除尾部空格
|
||||
[[nodiscard]] String strip(const String& chars) const; // 去除指定字符
|
||||
|
||||
// 对齐和填充
|
||||
String ljust(size_t width, char fillchar = ' ') const;
|
||||
String rjust(size_t width, char fillchar = ' ') const;
|
||||
String center(size_t width, char fillchar = ' ') const;
|
||||
[[nodiscard]] String ljust(size_t width, char fillchar = ' ') const;
|
||||
[[nodiscard]] String rjust(size_t width, char fillchar = ' ') const;
|
||||
[[nodiscard]] String center(size_t width, char fillchar = ' ') const;
|
||||
|
||||
// 字符串转换
|
||||
int toInt() const;
|
||||
long long toLongLong() const;
|
||||
double toDouble() const;
|
||||
[[nodiscard]] int toInt() const;
|
||||
[[nodiscard]] long long toLongLong() const;
|
||||
[[nodiscard]] double toDouble() const;
|
||||
|
||||
// 运算符重载
|
||||
String operator+(const String& other) const;
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
bool operator>=(const String& other) const;
|
||||
|
||||
private:
|
||||
std::string data_;
|
||||
std::string m_data;
|
||||
};
|
||||
|
||||
// 流运算符重载
|
||||
|
||||
Reference in New Issue
Block a user