SimpleWindow
载入中...
搜索中...
未找到
sw::Utils类 参考

工具类 更多...

#include <Utils.h>

静态 Public 成员函数

static void UseUtf8Encoding (bool useUtf8)
 设置Utils类是否使用UTF-8编码进行字符串转换(默认启用)
 
static std::wstring ToWideStr (const std::string &str)
 将窄字符串转为宽字符串
 
static std::string ToMultiByteStr (const std::wstring &wstr)
 将宽字符串转为窄字符串
 
static std::wstring ToWideStr (const std::string &str, bool utf8)
 将窄字符串转为宽字符串
 
static std::string ToMultiByteStr (const std::wstring &wstr, bool utf8)
 将宽字符串转为窄字符串
 
static std::wstring Trim (const std::wstring &str)
 删除首尾空白字符
 
static std::wstring TrimStart (const std::wstring &str)
 删除串首空白字符
 
static std::wstring TrimEnd (const std::wstring &str)
 删除串尾空白字符
 
static std::vector< std::wstring > Split (const std::wstring &str, const std::wstring &delimiter)
 对字符串按照指定分隔符进行拆分
 
static std::wstring FormatStr (const wchar_t *fmt,...)
 格式化字符串,类似于 swprintf,但返回一个动态分配的 std::wstring
 
template<typename T >
static constexprMax (const T &a, const T &b)
 取两值中的较大值
 
template<typename T >
static constexprMin (const T &a, const T &b)
 取两值中的较小值
 
template<typename... Args>
static std::wstring BuildStr (const Args &...args)
 拼接字符串,也可使用此函数将其他类型转为wstring
 

详细描述

工具类

成员函数说明

◆ FormatStr()

static std::wstring sw::Utils::FormatStr ( const wchar_t fmt,
  ... 
)
static

格式化字符串,类似于 swprintf,但返回一个动态分配的 std::wstring

参数
fmt格式化字符串
...可变参数,符合 fmt 格式的输入
返回
返回一个包含格式化结果的字符串

◆ Split()

static std::vector< std::wstring > sw::Utils::Split ( const std::wstring &  str,
const std::wstring &  delimiter 
)
static

对字符串按照指定分隔符进行拆分

参数
str输入的字符串
delimiter分隔符
返回
包含字串的vector

◆ ToMultiByteStr() [1/2]

static std::string sw::Utils::ToMultiByteStr ( const std::wstring &  wstr)
static

将宽字符串转为窄字符串

参数
wstr要转换的字符串
返回
转换后的字符串

◆ ToMultiByteStr() [2/2]

static std::string sw::Utils::ToMultiByteStr ( const std::wstring &  wstr,
bool  utf8 
)
static

将宽字符串转为窄字符串

参数
wstr要转换的字符串
utf8是否使用utf8编码
返回
转换后的字符串

◆ ToWideStr() [1/2]

static std::wstring sw::Utils::ToWideStr ( const std::string &  str)
static

将窄字符串转为宽字符串

参数
str要转换的字符串
返回
转换后的字符串

◆ ToWideStr() [2/2]

static std::wstring sw::Utils::ToWideStr ( const std::string &  str,
bool  utf8 
)
static

将窄字符串转为宽字符串

参数
str要转换的字符串
utf8是否使用utf8编码
返回
转换后的字符串

◆ Trim()

static std::wstring sw::Utils::Trim ( const std::wstring &  str)
static

删除首尾空白字符

参数
str输入的字符串
返回
删除首位空白字符后的字符串

◆ TrimEnd()

static std::wstring sw::Utils::TrimEnd ( const std::wstring &  str)
static

删除串尾空白字符

参数
str输入的字符串
返回
删除串尾空白字符后的字符串

◆ TrimStart()

static std::wstring sw::Utils::TrimStart ( const std::wstring &  str)
static

删除串首空白字符

参数
str输入的字符串
返回
删除串首空白字符后的字符串

◆ UseUtf8Encoding()

static void sw::Utils::UseUtf8Encoding ( bool  useUtf8)
static

设置Utils类是否使用UTF-8编码进行字符串转换(默认启用)

参数
useUtf8若为true则使用UTF-8编码,否则使用系统默认编码

该类的文档由以下文件生成: