kihlh / fmt11

Tiny format/mustache templating library (C++11)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fmt11

Tiny format/mustache templating library (C++11) Inspired by the better, safer and more featured library fmtlib

Features:

  • Basic python formatting: "{} {0} {1} {2:#x} {4:8.2} {:<20}"
  • Basic mustache templating "{{key}}"
  • Tiny, cross-platform, macro-less, header-only.
  • Public domain.

Cons:

  • Probably slow. No recursive code, but some heap allocations left.
  • Probably unsafe. Only minimal bound checking is performed.
  • Probably not featured enough.

Alternatives

Showcase

    fmt11( "Hello {} {}", "world", 123);   // variadic arguments
    fmt11( "Hello {0} {1}", "world", 123); // indices
    fmt11( "Hello {1} {0}", "world", 123); // indices: reordering
    fmt11( "{0}{1}{0}", "abra", "cad");    // indices: repeating
    fmt11( "{0:x} {0:d} {0:o}", 42, 42, 42 );                 // formatting
    fmt11( "{0:.8.2} {1:;10.2} {0:!8.5}", 3.14159, 3.14159 ); // formatting
    fmt11( "{:<20} {:>20}", "hello", "world");                // alignment

    // symbols and mustaches
    std::map< std::string, std::string > map { {"player1", "John"} };
    fmt11map( map, "Welcome {{player1}:!<20}. It's {0} {2} in {1}!", 12, "town", "o'clock" );

Changelog

  • v1.0.2 (2016/06/01): Parse valid identifiers only
  • v1.0.1 (2016/05/31): Extra boundary checks
  • v1.0.0 (2016/05/29): Initial version

About

Tiny format/mustache templating library (C++11)

License:The Unlicense


Languages

Language:C++ 100.0%