dl
dl_code_cvt.h
浏览该文件的文档.
1
14#pragma once
15
16#include <string>
17
18#include "dl_buffer.h"
20namespace dl::CodeCvt
21{
22
26Buffer CvtString(std::string_view from, std::string_view to, BufferView buf);
27
29namespace Utf8
30{
37int Check(std::string_view str);
38
45size_t Sub(std::string_view str, size_t max);
46
54void Copy(char* target, size_t size, std::string_view source, bool show_log = true);
55}
56
57//-----------------------------------------------cvt--------------------------------------------
59constexpr size_t SIZE_BUFFER_STRING_CONVERT = 1024;
60
61
62
63//---------------------------------utf8--------------------------------------------
68std::string Utf8ToMultiByte(std::string_view str, std::string_view code_page = "");
72std::wstring Utf8ToWideChar(std::string_view str);
76std::u32string Utf8ToUtf32(std::string_view str);
77
78//---------------------------------本地编码--------------------------------------------
83std::string MultiByteToUtf8(std::string_view str, std::string_view code_page = "");
84
89std::string MultiByteToUtf8(const char* str, std::string_view code_page = "");
90
91//---------------------------------宽字符--------------------------------------------
96std::string WideCharToUtf8(std::wstring_view str);
97
98//---------------------------------utf32--------------------------------------------
102std::string Utf32ToUtf8(std::u32string_view str);
103
104//
107// * @brief 字符串转换:utf-8 -> 宽字符
108//*/
109//std::wstring cvt_u8_wc(string_view str);
110//
112// * @brief 字符串转换:utf-8 -> 本地编码
113// * @note 此函数只在必须时使用
114//*/
115//string cvt_u8_mb(string_view str);
116//
118// * @brief 字符串转换:utf_string -> utf-8
119//*/
120//utf_string cvt_u8_utf(string_view str);
121//
124// * @brief 字符串转换:宽字符 -> utf-8
125//*/
126//string cvt_wc_u8(const wchar_t* str);
127//string cvt_wc_u8(std::wstring_view str);
128//
130// * @brief 字符串转换:宽字符 -> 本地编码
131//*/
132//string cvt_wc_mb(const wchar_t* str, string_view code_name = "");
133//
134//
135//
138//* @brief 字符串转换:mb -> utf-8
139//*/
140//string cvt_mb_u8(const char* str, string_view code_name = "");
141//string cvt_mb_u8(string_view str, string_view code_name = "");
142//
144// * @brief 字符串转换:mb -> wc
145//*/
146//std::wstring cvt_mb_wc(const char* str, string_view code_name = "");
147//
150// * @brief 字符串转换:utf_string -> utf-8
151//*/
152//string cvt_utf_u8(const utf_string& str);
153
154//
155//namespace ANSIExtend
156//{
157// /**
158// * @brief gbk编码截断
159// * @param[in] str 源字符串
160// * @param[in] max 最大长度
161// * @retval 返回应该截断的位置
162// */
163// size_t GbkSubIndex(std::string_view str, size_t max);
164//
165// inline std::string_view GbkSub(std::string_view str, size_t max)
166// {
167// return { str.begin(), str.begin() + GbkSubIndex(str, max) };
168// }
169//}
170
171}
172
173
表示一段内存
int Check(std::string_view str)
返回是否是utf-8编码
size_t Sub(std::string_view str, size_t max)
utf-8的子串计算
void Copy(char *target, size_t size, std::string_view source, bool show_log=true)
utf-8的安全复制
字符编码转换
std::string WideCharToUtf8(std::wstring_view str)
字符串转换:宽字符 -> utf8
std::wstring Utf8ToWideChar(std::string_view str)
字符串转换:utf8 -> 宽字符
constexpr size_t SIZE_BUFFER_STRING_CONVERT
编码转换缓冲区大小,越大使用更多的内存,但会更快
Buffer CvtString(std::string_view from, std::string_view to, BufferView buf)
iconv的简单封装,请使用更具体的函数。
std::string MultiByteToUtf8(std::string_view str, std::string_view code_page="")
字符串转换:本地编码 -> utf8
std::string Utf32ToUtf8(std::u32string_view str)
字符串转换:utf32 -> utf8
std::u32string Utf8ToUtf32(std::string_view str)
字符串转换:utf8 -> utf32
std::string Utf8ToMultiByte(std::string_view str, std::string_view code_page="")
字符串转换:utf8 -> 本地编码