|
Console Library 8.0.0
A header-only library that makes C++ simple
|
提供字符串处理工具函数和格式化类。 More...
#include <algorithm>#include <cctype>#include <climits>#include <clocale>#include <cstdint>#include <initializer_list>#include <iostream>#include <locale>#include <sstream>#include <string>#include <utility>#include <vector>#include "../core/csexc.h"Go to the source code of this file.
Classes | |
| struct | console::BasicPartitionResult< CharT, Traits, Allocator > |
| 字符串分区结果,包含左部分、分隔符、右部分。 More... | |
Namespaces | |
| namespace | console |
| 本库所有组件所在的顶层命名空间。 | |
Typedefs | |
| using | console::PartitionResult = BasicPartitionResult<char> |
| BasicPartitionResult<char> 的类型别名。 | |
| using | console::WPartitionResult = BasicPartitionResult<wchar_t> |
| BasicPartitionResult<wchar_t> 的类型别名。 | |
Functions | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::ltrim (std::basic_string< CharT, Traits, Allocator > str) |
| 移除字符串左侧的空白字符(空格、制表符等)。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::rtrim (std::basic_string< CharT, Traits, Allocator > str) |
| 移除字符串右侧的空白字符。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::trim (std::basic_string< CharT, Traits, Allocator > str) |
| 移除字符串两侧的空白字符。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::ltrim (std::basic_string< CharT, Traits, Allocator > str, const std::basic_string< CharT, Traits, Allocator > &chars) |
| 移除字符串左侧指定的字符集合。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::rtrim (std::basic_string< CharT, Traits, Allocator > str, const std::basic_string< CharT, Traits, Allocator > &chars) |
| 移除字符串右侧指定的字符集合。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::trim (std::basic_string< CharT, Traits, Allocator > str, const std::basic_string< CharT, Traits, Allocator > &chars) |
| 移除字符串两侧指定的字符集合。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::upper (std::basic_string< CharT, Traits, Allocator > str, const std::locale &loc=std::locale{}) |
| 将字符串转换为大写。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::lower (std::basic_string< CharT, Traits, Allocator > str, const std::locale &loc=std::locale{}) |
| 将字符串转换为小写。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::basic_string< CharT, Traits, Allocator > | console::title (std::basic_string< CharT, Traits, Allocator > str, const std::locale &loc=std::locale{}) |
| 将字符串转换为标题格式(每个单词首字母大写,其余小写)。 | |
| template<class CharT, class Traits, class Allocator> | |
| BasicPartitionResult< CharT, Traits, Allocator > | console::partition (const std::basic_string< CharT, Traits, Allocator > &text, const std::basic_string< CharT, Traits, Allocator > &sep) |
| 在字符串中查找第一个分隔符,并返回分隔符之前、分隔符本身、分隔符之后的三部分。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::vector< std::basic_string< CharT, Traits, Allocator > > | console::split (const std::basic_string< CharT, Traits, Allocator > &text, const std::basic_string< CharT, Traits, Allocator > &sep=std::basic_string< CharT, Traits, Allocator >(1, CharT{' '})) |
| 以分隔符分割字符串(类似 Python 的 split,默认按空格分割)。 | |
| template<class T, class CharT = char, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>> | |
| std::basic_string< CharT, Traits, Allocator > | console::join (const std::vector< T > &vec, const std::basic_string< CharT, Traits, Allocator > &sep=std::basic_string< CharT, Traits, Allocator >{}) |
| 以分隔符连接容器中的字符串元素。 | |
| std::string | console::ltrim (const char *str) |
| std::wstring | console::ltrim (const wchar_t *str) |
| std::string | console::rtrim (const char *str) |
| std::wstring | console::rtrim (const wchar_t *str) |
| std::string | console::trim (const char *str) |
| std::wstring | console::trim (const wchar_t *str) |
| std::string | console::ltrim (const char *str, const std::string &chars) |
| std::wstring | console::ltrim (const wchar_t *str, const std::wstring &chars) |
| std::string | console::rtrim (const char *str, const std::string &chars) |
| std::wstring | console::rtrim (const wchar_t *str, const std::wstring &chars) |
| std::string | console::trim (const char *str, const std::string &chars) |
| std::wstring | console::trim (const wchar_t *str, const std::wstring &chars) |
| std::string | console::ltrim (const char *str, const char *chars) |
| std::wstring | console::ltrim (const wchar_t *str, const wchar_t *chars) |
| std::string | console::rtrim (const char *str, const char *chars) |
| std::wstring | console::rtrim (const wchar_t *str, const wchar_t *chars) |
| std::string | console::trim (const char *str, const char *chars) |
| std::wstring | console::trim (const wchar_t *str, const wchar_t *chars) |
| std::string | console::ltrim (const std::string &str, const char *chars) |
| std::wstring | console::ltrim (const std::wstring &str, const wchar_t *chars) |
| std::string | console::rtrim (const std::string &str, const char *chars) |
| std::wstring | console::rtrim (const std::wstring &str, const wchar_t *chars) |
| std::string | console::trim (const std::string &str, const char *chars) |
| std::wstring | console::trim (const std::wstring &str, const wchar_t *chars) |
| std::string | console::upper (const char *str, const std::locale &loc=std::locale{}) |
| 将字符串转换为大写。 | |
| std::wstring | console::upper (const wchar_t *str, const std::locale &loc=std::locale{}) |
| 将字符串转换为大写。 | |
| std::string | console::lower (const char *str, const std::locale &loc=std::locale{}) |
| 将字符串转换为小写。 | |
| std::wstring | console::lower (const wchar_t *str, const std::locale &loc=std::locale{}) |
| 将字符串转换为小写。 | |
| std::string | console::title (const char *str, const std::locale &loc=std::locale{}) |
| 将字符串转换为标题格式(每个单词首字母大写,其余小写)。 | |
| std::wstring | console::title (const wchar_t *str, const std::locale &loc=std::locale{}) |
| 将字符串转换为标题格式(每个单词首字母大写,其余小写)。 | |
| template<class CharT, class Traits, class Allocator> | |
| BasicPartitionResult< CharT, Traits, Allocator > | console::partition (const std::basic_string< CharT, Traits, Allocator > &text, const CharT *sep) |
| 在字符串中查找第一个分隔符,并返回分隔符之前、分隔符本身、分隔符之后的三部分。 | |
| template<class CharT, class Traits, class Allocator> | |
| std::vector< std::basic_string< CharT, Traits, Allocator > > | console::split (const std::basic_string< CharT, Traits, Allocator > &text, const CharT *sep) |
| 以分隔符分割字符串(类似 Python 的 split,默认按空格分割)。 | |
| BasicPartitionResult | console::partition (const char *text, const std::string &sep) |
| 在字符串中查找第一个分隔符,并返回分隔符之前、分隔符本身、分隔符之后的三部分。 | |
| BasicPartitionResult< wchar_t > | console::partition (const wchar_t *text, const std::wstring &sep) |
| 在字符串中查找第一个分隔符,并返回分隔符之前、分隔符本身、分隔符之后的三部分。 | |
| std::vector< std::string > | console::split (const char *text, const std::string &sep=" ") |
| 以分隔符分割字符串(类似 Python 的 split,默认按空格分割)。 | |
| std::vector< std::wstring > | console::split (const wchar_t *text, const std::wstring &sep=L" ") |
| 以分隔符分割字符串(类似 Python 的 split,默认按空格分割)。 | |
| std::string | console::join (const std::vector< std::string > &items, const std::string &sep="") |
| 以分隔符连接容器中的字符串元素。 | |
| std::wstring | console::join (const std::vector< std::wstring > &items, const std::wstring &sep=L"") |
| 以分隔符连接容器中的字符串元素。 | |
| template<class CharT, class Traits> | |
| void | console::to_stream (char ch, std::basic_ostream< CharT, Traits > &os) |
| 将 ch 输出到流。 | |
| template<class CharT, class Traits> | |
| void | console::to_stream (wchar_t wch, std::basic_ostream< CharT, Traits > &os) |
| 将 wch 输出到流。 | |
| template<class Traits> | |
| void | console::to_stream (wchar_t wch, std::basic_ostream< wchar_t, Traits > &os) |
| 将 wch 输出到流。 | |
| template<class CharT, class Traits> | |
| void | console::to_stream (const std::string &str, std::basic_ostream< CharT, Traits > &os) |
| 将 std::string 输出到流。 | |
| template<class CharT, class Traits> | |
| void | console::to_stream (const std::wstring &wstr, std::basic_ostream< CharT, Traits > &os) |
| 将 std::wstring 输出到流。 | |
| template<class CharT, class Traits> | |
| void | console::to_stream (const char *str, std::basic_ostream< CharT, Traits > &os) |
| 将 const char * 输出到流。 | |
| template<class CharT, class Traits> | |
| void | console::to_stream (const wchar_t *wstr, std::basic_ostream< CharT, Traits > &os) |
| 将 const wchar_t * 输出到流。 | |
| template<class CharT, class Traits, std::size_t N> | |
| void | console::to_stream (char(&arr)[N], std::basic_ostream< CharT, Traits > &os) |
| template<class CharT, class Traits, std::size_t N> | |
| void | console::to_stream (wchar_t(&arr)[N], std::basic_ostream< CharT, Traits > &os) |
| template<class CharT, class Traits, class T> | |
| std::enable_if<!std::is_same< typenamestd::decay< T >::type, char >::value &&!std::is_same< typenamestd::decay< T >::type, wchar_t >::value &&!std::is_same< typenamestd::decay< T >::type, char * >::value &&!std::is_same< typenamestd::decay< T >::type, wchar_t * >::value &&!std::is_same< typenamestd::decay< T >::type, std::string >::value &&!std::is_same< typenamestd::decay< T >::type, std::wstring >::value >::type | console::to_stream (T &&value, std::basic_ostream< CharT, Traits > &os) |
| template<class... Args> | |
| std::string | console::to_string (Args &&...args) |
| 将任意多个参数转换为字符串并拼接(无分隔符)。 | |
| template<class CharT, class Traits, class Allocator, class... Args> | |
| void | console::from_string (std::basic_string< CharT, Traits, Allocator > str, Args &...args) |
| 将字符串中的值提取到多个参数中,参数类型由调用者指定。 | |
提供字符串处理工具函数和格式化类。
包含去除空白字符、大小写转换、分割与连接、分区、可变参数转字符串、格式化字符串(f_string)等功能。