| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
various c++ utility classes
Several methods of including this project:
How to use the include files:
#include <cpputils/formatter.h>
int main(...)
{
print("%s\n", std::string("test"));
}
Using iostream to configure hexdump output:
std::cout << Hex::hexstring << Hex::dumper(data, size) << "\n"; std::cout << Hex::offset(0x12000) << Hex::right << Hex::dumper(data, size) << "\n";
A more detailed description can be found in this blog post
printf like formatting using a combination of variadic templates and iostreams.
Example:
std::cout << stringformat("%d %s %d", 1LL, std::string("test"), size_t(3));
You can stringify custom types by defining a suitable operator<<(os, customtype).
Compared to alternatives like fmtlib, boost::format, this implementation creates very small binaries. Performance is below that of fmtlib, but well about boost::format.
The code is centered around the StringFormatter class. Several functions use this to provide formatting:
Makefile.bench builds several small programs for comparing my formatter to several other similar libraries.
Convert C or C++ strings to C++ strings, between any of UTF-8, UTF-16, UTF-32, depending on the size of the character type.
Example:
auto utf8str = string::convert<char>(L"test"); auto utf16str = string::convert<uint16_t>(L"test");
The first line converts a wchar_t string, which is either utf-16 or utf-32 encoded depending on the compiler, to a utf-8 string, the second line converts to utf-16.
Class for conveniently parsing commandline arguments.
This example will parse: cmd -apple -a 1234 first second -
for (auto& arg : ArgParser(argc, argv))
switch (arg.option())
{
case 'a': if (arg.match("-apple")) {
/*...*/
}
else {
a_arg = arg.getint();
}
break;
case '-': if (arg.match("--verbose"))
verbosity = 1;
break;
case 'v': verbosity = arg.count();
break;
case 0: usestdin = true;
break;
case -1: switch(n++)
{
case 0: first = arg.getstr(); break;
case 1: second = arg.getstr(); break;
}
}Several utility functions for handling NUL terminated char and wchar strings, and std::strings:
Parsing integers from strings:
Classes for packing and unpacking fixed width numeric data, in either little or big-endian format.
Exeption safe wrapper for posix filehandles.
class for using mem-mapped files.
A Recursive file iterator, which can be used from a ranged-for-loop.
Provides several methods of accessing items in an asn.1 BER encoded object.
A Makefile is provided for building the unittests. These can be build 'normally', and also with options for code coverage testing.
several targets exist:
(C) 2016-2023 Willem Hengeveld itsme@xs4all.nl
| Back | FazBrowse Home | New Git URL |