refactor: refactor encoding helper again.
- add the convertion between yycc_char8_t and system char type because we decide use our char8_t in the whole library. - make a clear boundary between yycc char8_t declarations and related assist functions. the declarations present in internal header and assist functions are written in encoding helper. - use std::basic_string_view instead of std::basic_string to provide more abilities to encoding convertion functions and reduce the redundant memory occupation at the same time.
This commit is contained in:
@ -25,22 +25,19 @@
|
||||
#endif
|
||||
|
||||
// Define the UTF8 char type we used.
|
||||
// Also define an universal macro to create UTF8 string literal.
|
||||
// And do a polyfill if no embedded char8_t type.
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
namespace YYCC {
|
||||
#if defined(__cpp_char8_t)
|
||||
using yycc_char8_t = char8_t;
|
||||
using yycc_u8string = std::u8string;
|
||||
|
||||
#define _YYCC_U8(strl) u8 ## strl
|
||||
#define YYCC_U8(strl) (_YYCC_U8(strl))
|
||||
using yycc_u8string_view = std::u8string_view;
|
||||
#else
|
||||
using yycc_char8_t = unsigned char;
|
||||
using yycc_u8string = std::basic_string<yycc_char8_t>;
|
||||
|
||||
#define _YYCC_U8(strl) u8 ## strl
|
||||
#define YYCC_U8(strl) (reinterpret_cast<const yycc_char8_t*>(_YYCC_U8(strl)))
|
||||
using yycc_u8string_view = std::basic_string_view<yycc_char8_t>;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user