统一命名

This commit is contained in:
ArchZer0
2026-08-16 19:15:19 +08:00
parent 9cb17262eb
commit 2a6c53d5bf
8 changed files with 451 additions and 321 deletions
+10 -10
View File
@@ -18,11 +18,11 @@ public:
BigDecimal(const BigDecimal& other) = default;
BigDecimal& operator=(const BigDecimal& other) = default;
bool isZero() const;
int sign() const;
int getScale() const;
BigInteger getUnscaledValue() const;
std::string toString() const;
[[nodiscard]] bool isZero() const;
[[nodiscard]] int sign() const;
[[nodiscard]] int getScale() const;
[[nodiscard]] BigInteger getUnscaledValue() const;
[[nodiscard]] std::string toString() const;
// Comparison operators
bool operator==(const BigDecimal& other) const;
@@ -59,14 +59,14 @@ public:
BigDecimal operator*(const BigDecimal& other) const;
BigDecimal operator/(const BigDecimal& other) const;
BigDecimal abs() const;
BigDecimal round(int scale) const;
[[nodiscard]] BigDecimal abs() const;
[[nodiscard]] BigDecimal round(int scale) const;
private:
BigInteger unscaledValue_; // 去掉小数点后的值
int scale_; // 小数点后的位数
BigInteger m_unscaledValue; // 去掉小数点后的值
int m_scale; // 小数点后的位数
static void alignScale(BigInteger& lhs, int& lhsScale,
static void m_alignScale(BigInteger& lhs, int& lhsScale,
BigInteger& rhs, int& rhsScale);
};
+10 -10
View File
@@ -17,9 +17,9 @@ public:
BigInteger(const BigInteger& other) = default;
BigInteger& operator=(const BigInteger& other) = default;
bool isZero() const;
int sign() const;
std::string toString() const;
[[nodiscard]] bool isZero() const;
[[nodiscard]] int sign() const;
[[nodiscard]] std::string toString() const;
bool operator==(const BigInteger& other) const;
bool operator!=(const BigInteger& other) const;
@@ -55,14 +55,14 @@ public:
BigInteger operator/(const BigInteger& other) const;
private:
std::string digits_; // 无符号数字,从高位到低位
int sign_; // -1, 0, 1
std::string m_digits; // 无符号数字,从高位到低位
int m_sign; // -1, 0, 1
static std::string trimLeadingZeros(const std::string& value);
static int compareAbs(const std::string& a, const std::string& b);
static std::string addAbs(const std::string& a, const std::string& b);
static std::string subAbs(const std::string& a, const std::string& b);
static std::string mulAbs(const std::string& a, const std::string& b);
static std::string m_trimLeadingZeros(const std::string& value);
static int m_compareAbs(const std::string& a, const std::string& b);
static std::string m_addAbs(const std::string& a, const std::string& b);
static std::string m_subAbs(const std::string& a, const std::string& b);
static std::string m_mulAbs(const std::string& a, const std::string& b);
static std::string divAbs(const std::string& a, const std::string& b);
};
+36 -36
View File
@@ -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;
};
// 流运算符重载