From bd76710ada09f36b8d52e8ebc85f1ffd8fbb5c6b Mon Sep 17 00:00:00 2001 From: wjjsn <109321530+wjjsn@users.noreply.github.com> Date: Sat, 25 Oct 2025 10:09:20 +0800 Subject: [PATCH] Highlight embedded-friendly focus in READMEs --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ README_en.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 README.md create mode 100644 README_en.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..e70358b --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# em_fmt 0.1.0 + +`em_fmt` 是一个针对 C++23 的轻量级嵌入式友好格式化库实验,强调在编译期解析格式字符串并以极少依赖提供快速 `fprint` 输出接口。本次 0.1.0 版本主要聚焦于构建核心能力并提供示例和测试工程,便于继续迭代。 + +## 特性 +- **编译期格式校验**:使用 `fixed_string` 在编译期解析格式字符串,提前检查花括号匹配与参数个数,让格式错误在编译阶段暴露。 +- **嵌入式可用的轻量实现**:完全头文件形式、仅依赖 C++23 标准库,无额外第三方依赖,在资源受限的嵌入式或交叉编译场景中也能轻松集成。 +- **广泛的参数支持**:当前支持整型、浮点、布尔、`std::string`、`std::string_view`、C 风格字符串以及原始指针和 `nullptr`。 +- **可配置的缓冲策略**:通过 `details/config.hpp` 切换静态缓冲区或栈上缓冲区,并支持选择浮点格式化方案,便于按需权衡性能与内存占用。 +- **极简构建依赖**:仅需 CMake 和支持 C++23 的编译器即可完成编译与测试,适合集成到现有构建流水线。 + +## 快速开始 +1. 安装 C++23 编译器(如 GCC 13+ 或 Clang 16+)和 CMake 3.15 及以上版本。 +2. 在仓库根目录执行: + ```bash + cmake -S . -B build + cmake --build build + ctest --test-dir build + ``` + `func_test` 将演示格式化输出,`speed_test` 用于性能基准。 + +## 使用示例 +```cpp +#include + +int main() { + em::fprint<"answer={}, pi={}\n">(stdout, 42, 3.14); + return 0; +} +``` + +## 配置项 +可编辑 `em_fmt/details/config.hpp` 调整以下选项: +- `USE_STATIC_BUFFER` / `USE_STACK_BUFFER`:选择静态缓冲区或每次调用时的栈缓冲区。 +- `STATIC_BUFFER_SIZE` / `STACK_BUFFER_SIZE`:控制缓冲区大小。 +- `FLOAT_FORMAT_BY_STD_TO_CHAR` / `FLOAT_FORMAT_BY_STD_SNPRINTF`:选择浮点格式化方式。 + +## 后续计划 +- 支持更多 STL 容器与自定义类型。 +- 提供可扩展的格式说明符。 +- 增加更多性能与正确性测试。 + +欢迎提交 Issue 或 PR 共同完善! diff --git a/README_en.md b/README_en.md new file mode 100644 index 0000000..556ecc8 --- /dev/null +++ b/README_en.md @@ -0,0 +1,43 @@ +# em_fmt 0.1.0 + +`em_fmt` is an experimental, lightweight, and embedded-friendly formatting library for C++23. It performs compile-time parsing of format strings and keeps dependencies to a bare minimum while offering a fast `fprint` helper at runtime. Version 0.1.0 lays down the core infrastructure together with sample targets so future iterations can focus on feature growth. + +## Highlights +- **Compile-time validation** – `fixed_string` analyses the format literal before compilation finishes, ensuring braces are balanced and argument counts match so mistakes surface during the build. +- **Embedded-ready footprint** – header-only, relying solely on the C++23 standard library with no third-party dependencies, making it easy to drop into constrained or cross-compilation environments. +- **Wide argument coverage** – integers, floating-point numbers, booleans, `std::string`, `std::string_view`, C-style strings, raw pointers, and `nullptr` are already supported. +- **Configurable buffering** – tweak `details/config.hpp` to switch between static or stack-based buffers and to choose the floating-point formatting backend, helping balance performance and memory use. +- **Minimal build requirements** – only CMake and a C++23-capable compiler are needed to build and test, easing integration into existing pipelines. + +## Getting started +1. Install a C++23 capable toolchain (GCC 13+, Clang 16+, or MSVC with /std:c++latest) and CMake ≥ 3.15. +2. Build and run the bundled tests: + ```bash + cmake -S . -B build + cmake --build build + ctest --test-dir build + ``` + `func_test` demonstrates formatted output while `speed_test` is designed for benchmarking. + +## Usage example +```cpp +#include + +int main() { + em::fprint<"answer={}, pi={}\n">(stdout, 42, 3.14); + return 0; +} +``` + +## Configuration knobs +Edit `em_fmt/details/config.hpp` to adjust: +- `USE_STATIC_BUFFER` vs `USE_STACK_BUFFER` for buffer lifetime management. +- `STATIC_BUFFER_SIZE` and `STACK_BUFFER_SIZE` for buffer sizing. +- `FLOAT_FORMAT_BY_STD_TO_CHAR` vs `FLOAT_FORMAT_BY_STD_SNPRINTF` for floating-point formatting. + +## Roadmap +- Extend support to additional STL containers and user-defined types. +- Provide richer, customizable format specifiers. +- Add more benchmarks and correctness suites. + +Contributions and feedback are very welcome!