FawLib

C++公共支持库

MIT License

Stars
18

FawLib

C++

faw::Encoding

ASCIIUTF8GB18030UTF16

std::string_view _data = "xxx"; // ...
std::string _encoding = faw::Encoding::guess (_data);
if (_encoding == "utf8" || _encoding == "ascii") {
    // utf8
} else if (_encoding == "gb18030" || _encoding == "ascii") {
    // gb18030
} else if (_encoding == "utf16") {
    // utf16
}
std::string_view _data = "xxx"; // ...
if (faw::Encoding::is_ascii (_data)) {
    // ASCIIutf8GB18030
} else if (faw::Encoding::is_utf8 (_data)) {
    // utf8
} else if (faw::Encoding::is_gb18030 (_data)) {
    // gb18030
} else if (faw::Encoding::is_utf16 (_data)) {
    // utf16
}
std::string_view _data = "xxx"; // ...
if (faw::Encoding::is_percent_str (_data)) {
    // %23%E5%FA
} else if (faw::Encoding::is_escape_x_str (_data)) {
    // \xBB\xD2\x2A
} else if (faw::Encoding::is_escape_u_str (_data)) {
    // \u6f73\u23BE
} else if (faw::Encoding::is_base64_str (_data)) {
    // Ga7dX83PdQfnua==
}

gb18030utf8utf16

std::wstring _s = faw::Encoding::gb18030_to_utf16 ("test");

xx_to_xxxxTunicodegb18030utf16T

// %23%E5%FA
// percent/URL 
std::string _encoded = faw::Encoding::percent_str_encode ("");
std::string _decoded = faw::Encoding::percent_str_decode (_encoded);

// \xBB\xD2\x2A
// escape_x 
_encoded = faw::Encoding::escape_x_str_encode (_decoded);
_decoded = faw::Encoding::escape_x_str_decode (_encoded);

// \u6f73\u23BE
// escape_u 
_encoded = faw::Encoding::escape_u_str_encode (_decoded);
_decoded = faw::Encoding::escape_u_str_decode (_encoded);

// Ga7dX83PdQfnua==
// Base64 
_encoded = faw::Encoding::base64_encode (_decoded);
_decoded = faw::Encoding::base64_decode (_encoded);

faw::String

std::basic_stringunicodegb18030utf16_T ("")

faw::Stringgb18030utf16

s1s3s5s7unicodes2s4s6s8

s7s8C++17faw::Stringauto

s9s10std::basic_stringCOW0std::basic_stringSSO

faw::String s1 { "abc" };
faw::String s2 { L"abc" };
faw::String s3 ( "abc" );
faw::String s4 ( L"abc" );
faw::String s5 = "abc";
faw::String s6 = L"abc";
faw::String s7 = "abc"_fs;
faw::String s8 = L"abc"_fs;
faw::String s9 (s1);
faw::String s10 (&s1);

=+==

faw::String s1 = "abc"_fs;
faw::String s2 = L"abc"_fs;
faw::String s3 = s1;
faw::String s4 = &s1;
faw::String s5 = "abc";
faw::String s6 = L"abc";
faw::String s7 = std::string ("abc");
faw::String s8 = std::wstring (L"abc");
faw::String s9 = std::string_view ("abc");
faw::String s10 = std::wstring_view (L"abc");
faw::String s = "abc";
s += L"123";
// s _T ("abc123")

+++=+=+faw::Sring

**=python

String s = "a";
s *= 10;
// s _T ("aaaaaaaaaa")

gb18030utf16+

// 
String s = "abc";
bool b1 = (s == "abc"); // true
bool b2 = (s.is_equal (L"abc")); // true

// 
bool b3 = s.is_equal_nocase ("Abc"); // true

beginendcbegincendrbeginrendcrbegincrendstd::basic_string

// abc
// (beginendfor-range)
faw::String s1 = "abc";
for (auto c: s1) {
    std::cout << (char) c << '\n';
}

<<>>faw::Stringfaw::String

faw::String s1 = "12abc";
s1 << _T ('d'); //  12abcd
_T ('-') >> s1; //  -12abcd
s1 << "123"; //  -12abcd123
int i = 0;
s1 >> i; //  -12abcdi123
i << s1; //  abcdi-12

STL

  1. findrfind
  2. trim_lefttrim_righttrimupperlowerreversereplace
  3. trim_left_selftrim_right_selftrim_selfupper_selflower_selfreverse_selfreplace_self
  4. emptyclearfreesizeoperator[]c_strstrstring_t&str_viewstring_view_tstrastd::stringstrwstd::wstringmatch_regex
  5. splitstd::vector<faw::String>
  6. formatfaw::String