{"id":24780327,"url":"https://github.com/iokg04/cfmt","last_synced_at":"2025-07-31T11:06:06.066Z","repository":{"id":274352682,"uuid":"922649256","full_name":"IOKG04/cfmt","owner":"IOKG04","description":"sprintf() like formatting entirely in zig - sometimes std.fmt is just too weak","archived":false,"fork":false,"pushed_at":"2025-01-27T09:20:36.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T04:21:27.076Z","etag":null,"topics":["formatting","sprintf-style","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IOKG04.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":"2025-01-26T18:53:16.000Z","updated_at":"2025-01-27T09:20:40.000Z","dependencies_parsed_at":"2025-01-26T19:36:57.263Z","dependency_job_id":"01d73f26-e901-4e4f-a3c1-ecb067b40757","html_url":"https://github.com/IOKG04/cfmt","commit_stats":null,"previous_names":["iokg04/cfmt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/IOKG04/cfmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IOKG04%2Fcfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IOKG04%2Fcfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IOKG04%2Fcfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IOKG04%2Fcfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IOKG04","download_url":"https://codeload.github.com/IOKG04/cfmt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IOKG04%2Fcfmt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268026306,"owners_count":24183392,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["formatting","sprintf-style","zig"],"created_at":"2025-01-29T10:21:30.575Z","updated_at":"2025-07-31T11:06:06.000Z","avatar_url":"https://github.com/IOKG04.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cfmt\n\nZig's `@import(\"std\").fmt` may be good, but in some cases you just need a little bit more functionality.\n\nNow why not just link in `libc` and use `sprintf()` and such? \u003cbr/\u003e\nEither because you are on some device where there isn't (yet) a `libc` to link against,\nbecause you just don't *want* to link against `libc`,\nor lastly because you're using some types c doesn't understand (`u19`, `f128`, etc.) and want a native zig solution.\n\nThat being said, this is not a drop in replacement, the format specifiers are a little different from c's.\nI did design them to be as close as possible though, requiring little rethinking if you're already used to c.\n\nA lot of what's written here isn't implemented yet, I am working on it though. \u003c!-- TODO: remove once everything is implemented --\u003e\nAlso any ideas are appreciated, making this more feature rich would be nice :3\n\nAlso also, I will add a `build.zig.zon` once this can be reasonably used as a library.\nMight even make it so you can compile it to a static/dynamic library to use with other languages.\n\n## Format specifier\n\nFormat specifiers in `cfmt` look something like this:\n```zig\n\"%s\"     // a string\n\"%.4f\"   // a floating-point value rounded to 4 digits after the period\n\"%-4.8i\" // a left alligned integer of at least 4 and at most 8 digits\n```\n\nThey can be split into five parts in this exact order:\nA `%` character,\n[flags](#flags),\n[minimum width](#minimum-width),\n[precision](#precision) and lastly\nthe [specifier](#specifiers). \u003cbr/\u003e\nAll besides the specifier are optional.\n\nThe only exception to this is the specifier for writing a `%` character, which is `%%`.\n\n### Specifiers\n\nSpecifiers tell `cfmt` what kind of type you're formatting and how you want it formatted.\n\nThe following specifiers exist:\n\n**Integers:**\n- `i`: Decimal integer\n- `b`: Binary integer\n- `o`: Octal integer\n- `x`: Hexadecimal integer (lowercase)\n- `X`: Hexadecimal integer (uppercase)\n\n**Floating-point:**\n- `f`: Decimal floating-point\n\u003c!-- `e`: Decimal scientific notation (lowercase) --\u003e\n\u003c!-- `E`: Decimal scientific notation (uppercase) --\u003e\n\u003c!-- `a`: Hexadecimal floating-point (lowercase)  --\u003e\n\u003c!-- `A`: Hexadecimal floating-point (uppercase)  --\u003e\n\n**Other:**\n- `s`: String\n- `c`: Character\n- `p`: Pointer (hexadecimal lowercase)\n- `P`: Pointer (hexadecimal uppercase)\n\u003c!-- - `B`: Boolean (`\"true\"` or `\"false\"`) --\u003e\n\n**Special:**\n\u003cbr/\u003e \\*cricket noises\\*\n\u003c!-- - `n`: Writes characters written so far to a `*usize` --\u003e\n\nFor better compatibility with c's format specifiers, `d` and `u` work the same as `i`.\n\n### Minimum width\n\nIf a minimum width is specified and the formatted string isn't that long, the string will be padded with space characters.\n\nThe minimum width can either be a decimal number, such as `4`, `9` or `142`,\nor a `*`, in which case an `usize` is read from the arguments and its value is used as the minimum width. \u003cbr/\u003e\nIf a `*` is used, the dynamic minimum width must be given before the value to be formatted (and the dynamic precision if used). \u003cbr/\u003e\nPlease note that the decimal number may not have a leading zero as that could interfere with the [`0` flag](#flags).\n\nBy default, the formatted contents will be right alligned (space characters on the left),\nthough this behavior can be changed with the [`-` flag](#flags).\n\n### Precision\n\nWhat exactly *precision* means depends on the type to be formatted:\n\nIf it's a floating point value, precision is the amount of digits after the decimal separator.\n\nIf it's a string, precision defines the maximum amount of characters written.\nWhen truncation happens, the last characters are cut off.\n\u003c!-- maybe making precision negative could make it truncate the first characters instead? --\u003e\n\nIf it's a character, it will be repeated *precision* times.\nDoes it make sense to call that precision? No.\nCould it still be a useful functionality? Yes.\n\nFor any other type, precision doesn't do anything.\n\nTo set the precision, a `.` followed by a number or a `*` is used, similar to [minimum width](#minimum-width) except with a `.` character. \u003cbr/\u003e\nHere however, the precision is put *between* the dynamic minimum width and value to be formatted. \u003cbr/\u003e\nIf neither a `*` or a number follows the `.`, precision is set to `0`.\n\n### Flags\n\nFlags change some parts of formatting.\n\nThe following flags exist:\n- `-`: Allign to the left instead of right (space characters on the right)\n- `+`: Always write `+` and `-` sign for numeric types\n- ` `: (space) Write a space character at start of positive numeric values\n- `\u003c`: Write sign before any padding\n- `0`: Pad with `0` characters instead of space characters\n\u003c!-- `#`: Always write decimal separator for floating-point values --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiokg04%2Fcfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiokg04%2Fcfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiokg04%2Fcfmt/lists"}