{"id":22433639,"url":"https://github.com/nlitsme/cpputils","last_synced_at":"2025-07-17T21:35:50.802Z","repository":{"id":71128146,"uuid":"74962561","full_name":"nlitsme/cpputils","owner":"nlitsme","description":"various c++ utility classes","archived":false,"fork":false,"pushed_at":"2024-11-06T20:37:16.000Z","size":745,"stargazers_count":22,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-06T21:34:37.235Z","etag":null,"topics":["cplusplus-14","cpp","iconv","stringformatter","variadic-templates"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlitsme.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","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":"2016-11-28T10:34:40.000Z","updated_at":"2024-11-06T20:37:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"f76629e2-c01f-400c-80ee-a260e0cc9448","html_url":"https://github.com/nlitsme/cpputils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fcpputils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fcpputils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fcpputils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlitsme%2Fcpputils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlitsme","download_url":"https://codeload.github.com/nlitsme/cpputils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228377529,"owners_count":17910449,"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":["cplusplus-14","cpp","iconv","stringformatter","variadic-templates"],"created_at":"2024-12-05T22:15:30.945Z","updated_at":"2024-12-05T22:15:31.796Z","avatar_url":"https://github.com/nlitsme.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cpputils\nvarious c++ utility classes\n\n* iostreams based hexdumper utility\n* string formatter using variadic templates instead of varargs,\n  making use of iostreams for formatting.\n* utf-X string converter.\n* c++17 required.\n* a argc/argv argument parsing library: `argparse.h`\n* `arrayview.h` - provide an interface similar to std::stringview, or boost::span\n* `asn1parser: decodes BER encoded data\n* datapacking: big/little endian data extraction\n* fhandle: c++ wrapper for a POSIX file handle.\n* fslibrary: enumerates files recursively.\n* mmem: memory mapped files.\n* stringconvert: utf-N conversion tools.\n* stringlibrary: type independent string functions.\n* xmlparser: idea based on the python html.parser module.\n\n\n# usage:\n\nSeveral methods of including this project:\n * include this project using cmake `add\\_subdirectory`\n * add the Findcpputils.cmake to your `CMAKE\\_MODULE\\_PATH`, and then use `find\\_package(cpputils)`\n * add `-I cpputils/include` to your compiler commandline.\n\nHow to use the include files:\n\n```\n#include \u003ccpputils/formatter.h\u003e\n\nint main(...)\n{\n    print(\"%s\\n\", std::string(\"test\"));\n}\n```\n\n## hexdumper\n\nUsing iostream to configure hexdump output:\n\n    std::cout \u003c\u003c Hex::hexstring \u003c\u003c Hex::dumper(data, size) \u003c\u003c \"\\n\";\n    std::cout \u003c\u003c Hex::offset(0x12000) \u003c\u003c Hex::right \u003c\u003c Hex::dumper(data, size) \u003c\u003c \"\\n\";\n    \nA more detailed description can be found [in this blog post](http://nlitsme.github.io/posts/hexdumper-for-c%2B%2B-iostreams/)\n\n\n## formatter\n\nprintf like formatting using a combination of variadic templates and iostreams.\n\nExample:\n\n    std::cout \u003c\u003c stringformat(\"%d %s %d\", 1LL, std::string(\"test\"), size_t(3));\n\nYou can stringify custom types by defining a suitable `operator\u003c\u003c(os, customtype)`.\n\nCompared to alternatives like fmtlib, boost::format, this implementation creates very small binaries. Performance is below that of fmtlib, but well about boost::format.\n\nThe code is centered around the `StringFormatter` class. Several functions use this\nto provide formatting:\n * `std::string stringformat(const char *fmt, ...)`\n    * print to a stl string\n * `QString qstringformat(const char *fmt, ...)`\n    * print to a QT string\n * `fprint(FILE *out, const char*fmt, ...)`\n    * print to a file\n * `print(const char*fmt, ...)`\n    * print to stdout\n * `debug(const char*fmt, ...)`\n    * print to windows debug log\n\n\n\n### benchmarks\n\nMakefile.bench builds several small programs for comparing my formatter to several other\nsimilar libraries.\n\n\n## stringconvert\n\nConvert C or C++ strings to C++ strings, between any of UTF-8, UTF-16, UTF-32, depending on the size of the character type.\n\nExample:\n\n    auto utf8str = string::convert\u003cchar\u003e(L\"test\");\n    auto utf16str = string::convert\u003cuint16_t\u003e(L\"test\");\n\nThe first line converts a wchar\\_t string, which is either utf-16 or utf-32 encoded depending on the compiler,\nto a utf-8 string, the second line converts to utf-16.\n\n## argparse\n\nClass for conveniently parsing commandline arguments.\n\nThis example will parse: `cmd -apple  -a 1234   first  second  -`\n\n```c++\nfor (auto\u0026 arg : ArgParser(argc, argv))\n   switch (arg.option())\n   {\n   case 'a': if (arg.match(\"-apple\")) {\n                 /*...*/\n             }\n             else {\n                 a_arg = arg.getint();\n             }\n             break;\n   case '-': if (arg.match(\"--verbose\"))\n                 verbosity = 1;\n             break;\n   case 'v': verbosity = arg.count();\n             break;\n   case 0:   usestdin = true;\n             break;\n   case -1:  switch(n++)\n             {\n             case 0: first = arg.getstr(); break;\n             case 1: second = arg.getstr(); break;\n             }\n   }\n```\n\n## stringlibrary\n\nSeveral utility functions for handling NUL terminated char and wchar strings, \nand std::strings:\n * stringcopy, stringlength, stringcompare, stringicompare, stringsplitter, (lr)strip\n\nParsing integers from strings:\n * parseunsigned, parsesigned\n\n## datapacking\n\nClasses for packing and unpacking fixed width numeric data, in either little or big-endian format.\n\n\n## fhandle\n\nExeption safe wrapper for posix filehandles.\n\n## mmem\n\nclass for using mem-mapped files.\n\n\n## fslibrary\n\nA Recursive file iterator, which can be used from a ranged-for-loop.\n\n## asn1parser\n\nProvides several methods of accessing items in an asn.1 BER encoded object.\n * `asn1tlv` is an object which decodes the Type + Length fields, and \n   Provides the 'range' where the Data is located.\n * `enumtlvs` iterates over all BER objects found in the given range.\n * `traverse` extracts a specific part from a BER encoded object.\n\n\n## unittests\n\nA Makefile is provided for building the unittests. These can be build 'normally', \nand also with options for code coverage testing.\n\nseveral targets exist:\n * `all`, the old method of building the tests\n * `cmake`, using cmake to resolve dependencies\n * `vc`, for building this on windows platforms with cmake + visualc++\n\n\n### todo\n\n * add support for hexdumping data from streams.\n * string alignment / width does not work correctly for unicode characters \u003e 0x80.\n * `\"% d\"` : space-for-positive is not supported.\n * `\"%\\*d\"` : width from argument list is not supported.\n * `\"%+08d\"`  produces the wrong result: the sign will be after the padding, instead of in front.\n * `\"%.8s\"`  string truncation does not work.\n * add support for different alphabets in base32/base64.\n * add linereader which takes either a filehandle, or a range\n * add read() which allocates it's return buffer.\n\n(C) 2016-2023 Willem Hengeveld \u003citsme@xs4all.nl\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlitsme%2Fcpputils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlitsme%2Fcpputils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlitsme%2Fcpputils/lists"}