Unformat
Fastest type-safe parsing library in the world for C++14 or C++17 (up to 300x faster than std::regex)
Install / Use
/learn @adamyaxley/UnformatREADME
Unformat
Parsing and extraction of original data from brace style "{}" formatted strings. It basically unformats what you thought was formatted for good.
Quick Example
Unformat is simple to use and works on all basic types. See the below example for extracting an ay::string_view and an int
ay::string_view name;
int age;
unformat("Harry is 18 years old.", "{} is {} years old.", name, age);
// name == "Harry" and age == 18
As an optimisation, if the format string is known at compile time, it can be parsed into a constant expression by making use of ay::make_format. In tests, this increases runtime speed by a factor of 3.
ay::string_view name;
int age;
constexpr auto format = ay::make_format("{} is {} years old.");
unformat("Harry is 18 years old.", format, name, age);
// name == "Harry" and age == 18
How do I use this library?
Unformat is a single-file header only library with zero dependencies (only <cstddef> for std::size_t). All you need to do is copy unformat.h into your project, and away you go.
ay::string_view is a simple non-owning struct containing a const char* data pointer and a std::size_t size. It can be converted to your own string type after parsing.
Public Domain
This software is completely open source and in the public domain. See LICENSE for details.
Contributing
Pull requests are very welcome. You may also create Issues and I will have a look into it as soon as I can.
Speed
Unformat is super awesome back to the future style lightning fast compared to traditional parsing methods. Below is the output from Google Benchmark on unformat_benchmark.cpp. Great Scott!
Run on (32 X 2420 MHz CPU s)
---------------------------------------------------------
Benchmark Time
---------------------------------------------------------
Unformat 32.6 ns
Unformat_ConstexprMakeFormat 11.5 ns
StdStringStream 391 ns
StdRegex 3269 ns
StdScanf 677 ns
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
