### Install Source: https://github.com/toge/frozenchars/blob/main/README.md Command to install the library using CMake. ```bash cmake --install build --prefix ./install ``` -------------------------------- ### Minimal compile example (1 command) Source: https://github.com/toge/frozenchars/blob/main/README.md Build and run the example with a single command. ```bash g++ -std=c++23 -O2 -Wall -Wextra -pedantic -I. example.cpp && ./a.out ``` -------------------------------- ### `to_pascal_case` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates converting strings to PascalCase. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr p = to_pascal_case("hello_world"_fs); // "HelloWorld" static_assert(p.sv() == "HelloWorld"); ``` -------------------------------- ### `base64_encode` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates Base64 encoding strings. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr e1 = base64_encode("Hello"_fs); // "SGVsbG8=" auto constexpr e2 = base64_encode<"f"_fs>(); // NTTP版(正確なサイズ) static_assert(e1.sv() == "SGVsbG8="); static_assert(e2.sv() == "Zg=="); ``` -------------------------------- ### Freeze Function Examples Source: https://github.com/toge/frozenchars/blob/main/README.md Examples of using the `freeze` function with various supported types. ```C++ // String literal freeze("hello"); // C-string pointer char const* ptr = "world"; freeze(ptr); // Unsigned char pointer unsigned char const* uptr = reinterpret_cast(ptr); freeze(uptr); // std::span char buffer[] = "span_data"; freeze(std::span{buffer}); // std::array std::array arr = {{'a', 'b', 'c'}}; freeze(arr); // std::vector std::vector vec = {'d', 'e', 'f'}; freeze(vec); // Numeric types freeze(255); // Decimal freeze(0xFF); // Hexadecimal freeze(0377); // Octal // Floating point freeze(3.14159); // Default precision freeze(Precision(3.14, 2)); // Specific precision // String convertible types std::string str = "convertible"; freeze(str); ``` -------------------------------- ### `capitalize` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates capitalizing the first letter of a string. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr c = capitalize("hELLO wORLD"_fs); // "Hello world" static_assert(c.sv() == "Hello world"); ``` -------------------------------- ### Quick Start Source: https://github.com/toge/frozenchars/blob/main/README.md Concatenates strings and numbers at compile time. ```cpp #include "frozenchars.hpp" auto constexpr msg = frozenchars::concat("answer=", 42, ", hex=0x", frozenchars::Hex(255)); // msg.sv() == "answer=42, hex=0xff" ``` -------------------------------- ### `url_decode` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates URL decoding strings. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr d1 = url_decode("Hello%20World%21"_fs); // "Hello World!" auto constexpr d2 = url_decode("a+b+c"_fs); // "a b c" static_assert(d1.sv() == "Hello World!"); static_assert(d2.sv() == "a b c"); ``` -------------------------------- ### `base64_decode` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates Base64 decoding strings. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr d1 = base64_decode("SGVsbG8="_fs); // "Hello" auto constexpr d2 = base64_decode<"Zg=="_fs>(); // NTTP版(正確なサイズ) static_assert(d1.sv() == "Hello"); static_assert(d2.sv() == "f"); ``` -------------------------------- ### `url_encode` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates URL encoding strings. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr e1 = url_encode("Hello World!"_fs); // "Hello%20World%21" auto constexpr e2 = url_encode<"a b c"_fs>(); // NTTP版(正確なサイズ) static_assert(e1.sv() == "Hello%20World%21"); static_assert(e2.sv() == "a%20b%20c"); ``` -------------------------------- ### `to_camel_case` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates converting strings to camelCase. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr c = to_camel_case("hello_world"_fs); // "helloWorld" static_assert(c.sv() == "helloWorld"); ``` -------------------------------- ### std::format compile-time check example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates using NTTP to generate safe format_strings for std::format. ```cpp { constexpr auto fmt = "Hello, {}!"_fs; constexpr auto fmt_str = make_format_string(); std::string result = std::format(fmt_str, 42); std::cout << result << '\n'; // 出力: Hello, 42! } { constexpr auto fmt = "Hello, {}!"_fs; constexpr auto fmt_str = make_format_string(); std::string result = std::format(fmt_str, std::string_view{"World"}); std::cout << result << '\n'; // 出力: Hello, World! } { constexpr auto fmt = "Hello, {}!"_fs; constexpr auto fmt_str = make_format_string(); std::string result = std::format(fmt_str, static_cast("World")); std::cout << result << '\n'; // 出力: Hello, World! } { // 例: NTTPを使用して安全なformat_stringを生成 constexpr auto fmt = "Hello, {}!"_fs; constexpr auto fmt_str = make_format_string(); std::string result = std::format(fmt_str, std::string{"World"}.c_str()); std::cout << result << '\n'; // 出力: Hello, World! } ``` -------------------------------- ### `to_snake_case` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates converting strings to snake_case. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr s1 = to_snake_case("helloWorld"_fs); // "hello_world" auto constexpr s2 = to_snake_case("HelloWorld"); // "hello_world" static_assert(s1.sv() == "hello_world"); static_assert(s2.sv() == "hello_world"); ``` -------------------------------- ### `parse_to_tuple` example Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates parsing a type list string into a std::tuple. ```cpp #include "frozenchars.hpp" #include using namespace frozenchars; using namespace frozenchars::literals; using T1 = typename decltype(parse_to_tuple<"int, string?, bool"_fs>())::type; static_assert(std::is_same_v, bool>>); using T2 = typename decltype(parse_to_tuple<"[int, bool?], void, sv"_fs>())::type; static_assert(std::is_same_v>, void, std::string_view>>); using T3 = typename decltype(parse_to_tuple<"int,,[char, double]?"_fs>())::type; static_assert(std::is_same_v>>>); ``` -------------------------------- ### Initialization with aggregates and custom classes Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates initializing aggregate structs and custom classes using the results of hex color parsing functions. ```cpp #include "frozenchars.hpp" #include using namespace frozenchars; struct AggregateColor { std::uint8_t r; std::uint8_t g; std::uint8_t b; }; struct AggregateColorA { std::uint8_t r; std::uint8_t g; std::uint8_t b; std::uint8_t a; }; struct AggregateColorBgr { std::uint8_t b; std::uint8_t g; std::uint8_t r; }; struct LibraryColor { std::uint8_t r; std::uint8_t g; std::uint8_t b; constexpr LibraryColor(std::uint8_t red, std::uint8_t green, std::uint8_t blue) : r(red), g(green), b(blue) {} }; struct LibraryColorA { std::uint8_t r; std::uint8_t g; std::uint8_t b; std::uint8_t a; constexpr LibraryColorA(std::uint8_t red, std::uint8_t green, std::uint8_t blue, std::uint8_t alpha) : r(red), g(green), b(blue), a(alpha) {} }; struct LibraryColorAbgr { std::uint8_t a; std::uint8_t b; std::uint8_t g; std::uint8_t r; constexpr LibraryColorAbgr(std::uint8_t alpha, std::uint8_t blue, std::uint8_t green, std::uint8_t red) : a(alpha), b(blue), g(green), r(red) {} }; auto constexpr aggregate = std::apply( [](auto... channels) constexpr { return AggregateColor{channels...}; }, parse_hex_rgb("#123") ); auto constexpr aggregate_a = std::apply( [](auto... channels) constexpr { return AggregateColorA{channels...}; }, parse_hex_rgba("#1234") ); auto constexpr aggregate_bgr = std::apply( [](auto... channels) constexpr { return AggregateColorBgr{channels...}; }, to_bgr(parse_hex_rgb("#abcdef")) ); auto constexpr color = std::make_from_tuple(parse_hex_rgb("#abcdef")); auto constexpr color_a = std::make_from_tuple(parse_hex_rgba("#abcdef99")); auto constexpr color_abgr = std::make_from_tuple(to_abgr(parse_hex_rgba("#12345678"))); static_assert(aggregate.r == 0x11); static_assert(color.g == 0xcd); static_assert(aggregate_a.a == 0x44); static_assert(color_a.a == 0x99); static_assert(aggregate_bgr.b == 0xef); static_assert(color_abgr.a == 0x78); ``` -------------------------------- ### Build and Test Source: https://github.com/toge/frozenchars/blob/main/README.md Commands to build and test the repository. ```bash build.sh test.sh ``` -------------------------------- ### Inja-style templating (constexpr parse + runtime rendering) Source: https://github.com/toge/frozenchars/blob/main/README.md Allows parsing template structures at compile time by passing FrozenString as an NTTP, and then rendering them at runtime with provided values. ```cpp #include "frozenchars.hpp" using namespace frozenchars::inja; using namespace frozenchars::literals; auto constexpr src = "Hello {{ name }}{# comment #}{% if items %}:{% for x in items %}{{ x }}{% endfor %}{% endif %}"_fs; auto const ctx = make_object({ {"name", "A"}, {"items", make_array({1, 2})}, }); auto const out = render(ctx); // "Hello A:12" ``` -------------------------------- ### マルチライン文字列の処理関数例 Source: https://github.com/toge/frozenchars/blob/main/README.md 複数行文字列に対する様々な加工を行うスタンドアロン関数の使用例。 ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr src = " line1\n##comment\n line2 # inline comment\n\nline3"_fs; // 先頭の空白を2つ削除 auto constexpr r1 = remove_leading_spaces(src, 2); // "line1\n##comment\nline2 # inline comment\n\nline3" // コメント行(## で始まる行)を削除 auto constexpr r2 = remove_comment_lines(src, "##"); // " line1\n line2 # inline comment\n\nline3" // インラインコメント(# 以降)を削除(直前の空白は残る) auto constexpr r3 = remove_comments(src, "#"); // " line1\n##comment\n line2 \n\nline3" // 行末の連続スペースを削除 auto constexpr r4 = remove_trailing_spaces(r3); // " line1\n##comment\n line2\n\nline3" // 行を結合(スペース補完あり) auto constexpr r5 = join_lines("line1\nline2"_fs); // "line1 line2" // 末尾の空白を削除 auto constexpr r6 = trim_trailing_spaces("line1 \nline2 \n"_fs); // "line1\nline2\n" // 空行を削除 auto constexpr r7 = remove_empty_lines("line1\n\nline2"_fs); // "line1\nline2" ``` -------------------------------- ### make_querystring Source: https://github.com/toge/frozenchars/blob/main/README.md Generates a URL query string from key-value pairs. Accepts FrozenString and string literals, as well as tuple-like types. Values are URL-encoded. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr q = make_querystring("name", "Alice & Bob"); // "name=Alice%20%26%20Bob" static_assert(q.sv() == "?name=Alice%20%26%20Bob"); auto constexpr q2 = make_querystring(std::tuple{"name", "Alice & Bob"}); static_assert(q2.sv() == "?name=Alice%20%26%20Bob"); ``` -------------------------------- ### frozen_map with braced-init-list Source: https://github.com/toge/frozenchars/blob/main/README.md Creates a frozen_map using a braced-init-list where values are provided in declaration order. ```cpp #include "frozenchars/frozen_map.hpp" using namespace frozenchars; using namespace frozenchars::literals; frozen_map map{ "30", "5", "2" }; assert(map["timeout"] == "30"); assert(map["retry"] == "5"); assert(map["backoff"] == "2"); frozen_map view_map{ "30", "5", "2" }; assert(view_map["timeout"] == "30"); ``` -------------------------------- ### パイプ演算子による文字列ヘルパーの連結 Source: https://github.com/toge/frozenchars/blob/main/README.md パイプ演算子を使用して、文字列ヘルパー関数を左から右へ連結する例。 ```cpp #include "frozenchars.hpp" using namespace frozenchars::literals; namespace fops = frozenchars::ops; auto constexpr value = " abcdef "_fs | fops::trim | fops::toupper | fops::substr(0, 3); static_assert(value.sv() == "ABC"); ``` -------------------------------- ### frozen_map from compile-time key/value sequences Source: https://github.com/toge/frozenchars/blob/main/README.md Creates a frozen_map using a compile-time API with kv{key, value} pairs. ```cpp #include "frozenchars.hpp" using namespace frozenchars; auto map = make_frozen_map_kv(); static_assert(map["aaa"] == 5); static_assert(map["ddd"] == 0); ``` -------------------------------- ### toupper / tolower (case conversion) Source: https://github.com/toge/frozenchars/blob/main/README.md Converts ASCII alphabetic characters to uppercase or lowercase at compile time. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr u = toupper("Hello, World!"_fs); // "HELLO, WORLD!" auto constexpr l = tolower("Hello, World!"); // "hello, world!" static_assert(u.sv() == "HELLO, WORLD!"); static_assert(l.sv() == "hello, world!"); ``` -------------------------------- ### Specialized Arrays Source: https://github.com/toge/frozenchars/blob/main/README.md Demonstrates the use of specialized arrays for improved memory efficiency and execution speed when all elements are of the same type. ```C++ #include #include // Example usage of specialized arrays std::vector int_array; std::vector double_array; std::vector string_array; // The range() function generates an integer-specialized array from the start. // auto int_range = range(10); // Explicitly convert to specialized types // auto int_arr = as_int_array(arr); // auto double_arr = as_double_array(arr); // auto string_arr = as_string_array(arr); ``` -------------------------------- ### frozen_map from pair-like entries Source: https://github.com/toge/frozenchars/blob/main/README.md Creates a frozen_map using std::pair entries. ```cpp #include "frozenchars/frozen_map.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto map = make_frozen_map( std::pair{"retry", 5}, std::pair{"timeout", 30} ); static_assert(decltype(map)::size() == 2); ``` -------------------------------- ### frozen_format / to_format_string (std::format integration) Source: https://github.com/toge/frozenchars/blob/main/README.md Enables compile-time checked formatting using std::format with FrozenString as a non-type template parameter. ```cpp #include "frozenchars.hpp" #include using namespace frozenchars; using namespace frozenchars::literals; auto s = frozen_format<"id={} name={}"_fs>(42, std::string{"alice"}); // s == "id=42 name=alice" ``` -------------------------------- ### repeat (repetition) Source: https://github.com/toge/frozenchars/blob/main/README.md Repeats a string a specified number of times at compile time. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr r1 = repeat<3>("abc"_fs); // "abcabcabc" auto constexpr r2 = repeat<2>("xyz"); // "xyzxyz" ``` -------------------------------- ### right / center (alignment) Source: https://github.com/toge/frozenchars/blob/main/README.md Aligns strings to the right or center within a specified width, with an optional fill character. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr r1 = right<8>("abc"_fs); // " abc" auto constexpr r2 = right<8, '.'>("abc"); // ".....abc" auto constexpr c1 = center<7>("abc"_fs); // " abc " auto constexpr c2 = center<8, '-'>("abc"); // "--abc---" static_assert(r1.sv() == " abc"); static_assert(r2.sv() == ".....abc"); static_assert(c1.sv() == " abc "); static_assert(c2.sv() == "--abc---"); ``` -------------------------------- ### trim / ltrim / rtrim (edge trimming) Source: https://github.com/toge/frozenchars/blob/main/README.md Removes specified characters from the beginning, end, or both ends of a string at compile time. ```cpp #include "frozenchars.hpp" using namespace frozenchars; using namespace frozenchars::literals; auto constexpr s1 = trim(" hello "_fs); // "hello" auto constexpr s2 = ltrim<'-'>("---hello"); // "hello" auto constexpr s3 = rtrim("hello "); // "hello" static_assert(s1.sv() == "hello"); static_assert(s2.sv() == "hello"); static_assert(s3.sv() == "hello"); ``` -------------------------------- ### Converting frozen_map to STL containers with to() Source: https://github.com/toge/frozenchars/blob/main/README.md Converts a frozen_map to various STL containers like std::map, std::unordered_map, or std::array. ```cpp auto map = make_frozen_map( std::pair{"retry", 5}, std::pair{"timeout", 30}, std::pair{"backoff", 2} ); auto ordered = map.to>(); auto hashed = map.to>(); auto slots = map.to, 3>>(); auto moved = std::move(map).to>(); ``` -------------------------------- ### parse_hex_rgb / parse_hex_rgba (hex color → RGB/RGBA tuple) Source: https://github.com/toge/frozenchars/blob/main/README.md Converts RGB and RGBA color strings to std::tuple. Supports short hex codes and BGR/BGRA/ABGR conversions. ```cpp #include "frozenchars.hpp" #include using namespace frozenchars; auto constexpr rgb = parse_hex_rgb("#335577"); auto constexpr short_rgb = parse_hex_rgb("#532"); auto constexpr rgba = parse_hex_rgba("#5a3c"); auto constexpr bgr = to_bgr(rgb); auto constexpr bgra = to_bgra(rgba); auto constexpr abgr = to_abgr(rgba); auto constexpr [r, g, b] = rgb; auto constexpr [sr, sg, sb] = short_rgb; auto constexpr [rr, rg, rb, ra] = rgba; auto constexpr [blue, green, red] = bgr; auto constexpr [bb, bg, br, ba] = bgra; auto constexpr [aa, ab, ag, ar] = abgr; static_assert(r == 0x33); static_assert(g == 0x55); static_assert(b == 0x77); static_assert(sr == 0x55); static_assert(sg == 0x33); static_assert(sb == 0x22); static_assert(rr == 0x55); static_assert(rg == 0xaa); static_assert(rb == 0x33); static_assert(ra == 0xcc); static_assert(blue == 0x77); static_assert(green == 0x55); static_assert(red == 0x33); static_assert(bb == 0x33); static_assert(bg == 0xaa); static_assert(br == 0x55); static_assert(ba == 0xcc); static_assert(aa == 0xcc); static_assert(ab == 0x33); static_assert(ag == 0xaa); static_assert(ar == 0x55); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.