{"id":16073308,"url":"https://github.com/8ightfold/slimfmt","last_synced_at":"2025-03-18T05:31:12.882Z","repository":{"id":227194926,"uuid":"769832882","full_name":"8ightfold/slimfmt","owner":"8ightfold","description":"A small, simple formatting library for C++17","archived":false,"fork":false,"pushed_at":"2024-05-01T17:11:52.000Z","size":161,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T07:34:34.900Z","etag":null,"topics":["c-plus-plus","cpp","cpp17","output","performance","printf","type-safety"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/8ightfold.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-10T07:25:14.000Z","updated_at":"2024-05-01T17:11:57.000Z","dependencies_parsed_at":"2024-03-14T22:55:28.912Z","dependency_job_id":"ffe50717-efae-42a3-ba7a-27fefa17c654","html_url":"https://github.com/8ightfold/slimfmt","commit_stats":null,"previous_names":["8ightfold/slimfmt"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8ightfold%2Fslimfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8ightfold%2Fslimfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8ightfold%2Fslimfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/8ightfold%2Fslimfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/8ightfold","download_url":"https://codeload.github.com/8ightfold/slimfmt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243903172,"owners_count":20366436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","cpp","cpp17","output","performance","printf","type-safety"],"created_at":"2024-10-09T08:06:12.360Z","updated_at":"2025-03-18T05:31:11.704Z","avatar_url":"https://github.com/8ightfold.png","language":"C++","readme":"# slimfmt\n\nThis is a small formatting library for C++17, made with the intent of\nreducing compile times. It has a similar API to [fmt](https://github.com/fmtlib/fmt),\nbut has no compile time checking. This doesn't mean it is unsafe, as it still does\ntype checking, but these checks have been moved to runtime.\n\n## API\n\n*Note:* Template arguments have been removed, and are formatted like functions.\n``N`` is a ``std::size_t``, and ``TT`` is a variadic template.\n\n```cpp\nstd::string format(const char(\u0026Str)[N], TT\u0026\u0026...Args);\nvoid null(const char(\u0026Str)[N], TT\u0026\u0026...Args);\n\nvoid print(std::FILE* File, const char(\u0026Str)[N], TT\u0026\u0026...Args);\nvoid print(std::ostream\u0026 Stream, const char(\u0026Str)[N], TT\u0026\u0026...Args);\nvoid print(const char(\u0026Str)[N], TT\u0026\u0026...Args);\n\nvoid println(std::FILE* File, const char(\u0026Str)[N], TT\u0026\u0026...Args);\nvoid println(std::ostream\u0026 Stream, const char(\u0026Str)[N], TT\u0026\u0026...Args);\nvoid println(const char(\u0026Str)[N], TT\u0026\u0026...Args);\n\nvoid out([...]);\nvoid err([...]);\nvoid outln([...]);\nvoid errln([...]);\n\nvoid flush(std::FILE* File);\nvoid flush(std::ostream\u0026 Stream);\nbool setColorMode(bool Value);\n```\n\n- ``null[s]``: Tests in debug, does nothing in release.\n- ``out``/``print``: Formats the arguments, and prints to the passed stream/file (``stdout`` by default).\n- ``outln``/``println``: Same as ``print``, but adds a newline.\n- ``err[ln]``: Same as ``print[ln]``, but prints to ``stderr`` by default.\n- ``format``: Formats the arguments and returns a string.\n- ``flush``: Self explanatory...\n- ``setColorMode``: Enables/disables colors, currently affects errors (if enabled) and ``err[ln]``.\n\nBecause the printers are actually objects, you can use them for simple optional printing.\nFor example:\n\n```cpp\nsfmt::Printer\u0026 getDbgErrorPrinter(bool IsDebug) {\n  if (IsDebug)\n    return sfmt::errln;\n  else\n    return sfmt::null;\n}\n\nvoid dbgTest(bool IsDebug) {\n  auto\u0026 Dbg = getDbgErrorPrinter(IsDebug);\n  Dbg(\"{}, {}, {}\", 'x', 'y', 'z');\n}\n\n// Won't print anything.\ndbgTest(false);\n\n// Prints `x, y, z`.\ndbgTest(true);\n```\n\nKeep in mind this is not the case for ``sfmt::format``.\n\n## Format Strings\n\nA format string will look something like:\n``\"{} {%x} {: =5} {:#-*%o}\"`` (very clear, I know).\n\nFormat specifiers can be broken in two parts: alignment and options.\nAlignment handles if, where, and how an argument should be aligned/padded.\nOptions are miscellaneous controls over how formatting is done.\n\n### Grammar\n\n*Note:* Anything in backticks is a regular expression.\n\n```ebnf\nreplacement := \"{\" [alignment] [options] \"}\";\nalignment := \":\" character [align] width;\noptions := \"%\" [base] [extra];\n\nwidth := (digit+) | dynamic_align;\nalign := `[\u003c \u003e]` | `[+=-]`;\nbase  := alpha_base | radix_base;\nextra := `[pPcC]`;\n\ndynamic_align := \"*\";\nhex_base   := `[hHxX]`;\nalpha_base := `[bBoOdD]` | hex_base;\nradix_base := (\"r\" | \"R\") digit [digit];\n\ndigit := `[0-9]`;\ncharacter := `[ -~]`;\n```\n\n### Alignment\n\nThe alignment spec must begin with the character ``':'``.\nIt is followed by a printable character, which will be used for padding.\nThis can optionally be followed by an alignment:\n\n- Left: ``'\u003c'`` or ``'+'``\n- Right: ``'\u003e'`` or ``'-'``\n- Center: ``' '`` or ``'='``\n\nThe argument will be left aligned by default.\nFinally, you have the width, which can either be a decimal integer,\nor the character ``'*'``, which specifies dynamic alignment.\nWhen using dynamic align, you must pass a positive integer before\nthe argument you intend to format. For example:\n\n```cpp\n// Prints `123###`\nsfmt::print(\"{:#*}\", 6, \"123\");\n```\n\n### Options\n\nOptions modify the way values are printed.\nThe base is a single letter identifier, and when capitalized,\nwill print a number with uppercase digits.\nSome of the default bases are:\n\n- Binary: ``'b'`` or ``'B'``\n- Octal: ``'o'`` or ``'O'``\n- Decimal: ``'d'`` or ``'D'``\n- Hex: ``'x'`` or ``'X'``, and alternatively ``'h'`` or ``'H'``\n  \nYou may also print arbitrary radix bases with ``r[base]`` or ``R[base]``.\nOnly bases in the range ``[1, 32]`` are valid.\n\nSome miscellaneous options are:\n\n- Pointer: ``'p'`` or ``'P'``, will print strings as pointers.\n- Character: ``'c'`` or ``'C'``, will only print the first character of strings.\n  \nThese options must always follow an explicit base, as they are handled differently.\nFor example, ``%xP`` is valid, but ``%Px`` is not.\n\n## CMake\n\nThe CMake file also adds a few options. These are:\n\n- ``SLIMFMT_FORCE_ASSERT``: Keep assertions enabled in release.\n- ``SLIMFMT_STDERR_ASSERT``: Prints to ``stderr`` instead of aborting.\n\nThese are not made public, so do not check for them.\n\n## Benchmarks\n\nComing soon...\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8ightfold%2Fslimfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F8ightfold%2Fslimfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F8ightfold%2Fslimfmt/lists"}