- 重组文档目录结构: 每个模块的概述页移动到模块子目录 - 重命名 index.md 为 main.md - 修正所有模块文档中的错误: - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式 - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节 - core: 修复 types 链接错误 - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI - memory: 修复头文件路径, malloc vs operator new, 新增方法文档 - resources: 修复 Shader/Texture 链接错误 - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接 - 验证: fix_links.py 确认 0 个断裂引用
1.1 KiB
1.1 KiB
String::Length / Capacity / Empty
SizeType Length() const;
SizeType Capacity() const;
bool Empty() const;
获取字符串的长度、容量和判空状态。
参数: 无
返回:
Length()- 返回字符串的字符数(不包括终止 null 字符)Capacity()- 返回已分配的存储容量Empty()- 如果字符串为空则返回true
复杂度: 均为 O(1)
示例:
#include "XCEngine/Containers/String.h"
#include <iostream>
int main() {
XCEngine::Containers::String s1;
std::cout << "Empty: " << s1.Empty() << std::endl; // 输出: Empty: 1
XCEngine::Containers::String s2("Hello");
std::cout << "Length: " << s2.Length() << std::endl; // 输出: Length: 5
std::cout << "Capacity: " << s2.Capacity() << std::endl; // 输出: Capacity: 6 或更大
s2.Reserve(100);
std::cout << "After Reserve(100), Capacity: " << s2.Capacity() << std::endl; // 输出: 100
return 0;
}
相关文档
- String 总览 - 返回类总览
- CStr - 获取 C 字符串
- Reserve / Resize - 内存管理