Giter Site home page Giter Site logo

seanmiddleditch / nanofmt Goto Github PK

View Code? Open in Web Editor NEW
23.0 1.0 1.0 188 KB

Cut down and minimalistic C++ string formatting library

Home Page: https://nanofmt.readthedocs.io/

License: MIT License

CMake 1.18% C++ 98.52% C 0.29%
c-plus-plus c-plus-plus-17 formatting

nanofmt's Introduction

nanofmt

https://github.com/potatoengine/nanofmt

License

Copyright (c) Sean Middleditch and contributors

nanofmt is released under the MIT license.

nanofmt uses the Dragonbox reference implementation which released under either the Apache License Version 2.0 with LLVM Exceptions or the Boost Software License Version 1.0.

Documentation

Exmaple

char buffer[128];

char const* const end = nanofmt::format_to_n(
        buffer,
        sizeof buffer,
        "Hello, {0}! You are visitor {1}.",
        user_name,
        visitor_count);

// void write_log(char const* str, size_t length);
write_log(buffer, end - buffer);

About

nanofmt aims to provide a lite-weight semi-compatible implementation of the excellent fmtlib. This can be used in environments or team cultures where neither std::format nor fmtlib are available for use.

The primary motivation for nanofmt is to minimize dependencies on standard C++ headers and to minimize compile time. nanofmt does not aim to offer the fastest runtime efficiency, the most features, fmtlib or std::format compatibility, nor the most portable implementation.

C++17 is required.

Most notably, nanofmt only supports the (v)format_to_n interfaces to basic char* buffers and does not support any other character type or output iterators. There are custom (v)format_to wrappers that work only with the provided buffer type, which itself is just a wrapper around char* buffers.

nanofmt does not aim to be a true drop-in replacement of fmtlib, even for the interfaces found in both libraries. Some interfaces have been modified to appeal more to "C with Classes" programmers; this is not a judgement of modern C++, just an acquiescence to the prevalent tastes and opinions in the industries targetted by nanofmt (primarily the AAA game industry).

Support for floating-point types can optionally be disabled via the NANOFMT_FLOAT CMake option. Pass -DNANOFMT_FLOAT=OFF on the CMake command line to disable.

When to Use nanofmt

If you're in doubt, use fmtlib! It is in almost every conceivable way more complete, more runtime efficient, more reliable, better maintained, more portable, and otherwise superior.

Use nanofmt if your organization or team has decided they won't use fmtlib because of its standard library dependencies or its large-ish header sizes.

Use nanofmt if your organization or team believes that snprintf is the superior formatting library, other than limitations created by C varargs.

When NOT to Use nanofmt

Literally anytime that you have the option of using std::format or fmtlib, you should prefer using those instead!

If you're not sure if nanofmt is the right fit for your project, then it isn't. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.