diff --git a/README.md b/README.md index 3b7e21c..fdb652f 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,60 @@ const char* c_like_easter_egg = "Something cool"_frob; To reverse just apply ROT13 on to the string again. ``` c++ +#include + auto string2 = strdup(easter_egg); memfrob(string2, strlen(easter_egg)); // `string2` now contains the string "Something cool" free(string2); ``` -## Test +## Functions + +Also provided are `memfrob()` and `strfrob()` functions of our own for both strings and binary data, which do the same as libc `memfrob()`. + +``` c++ +/// `memfrob()` +{ + const unsigned char data[] = { + 0xa, 0xd, 0x10, 0xf7, + }; + + const auto ctime = forb::memfrob(data); // Done at compile time, like the literal. + + const std::vector cloned = frob::memfrob(data, sizeof(data)); // Clone constant data at runtime into a new `std::vector`. + + unsigned char* data2 = malloc(10); + frob::memfrob(data2, 10); // Mutated in place + free(data2); + + const std::vector xvec{0xad, 0xb, 0xc}; + std::vector xfrobbed = frob::memfrob(xvec); // Cloned; + + std::vector vec{0xad, 0xb, 0xc}; + frob::memfrob(&vec); // Mutated `vec` in place. (explicit pointer is used here so you know it's not mutating when you might not expect.) +} +/// `strfrob()` +{ + const char* string= "const"; + std::string frobbed = frob::strfrob(string); // Cloned + + char* string2 = "mutated"; + frob::strfrob(string2); // Mutated in plate + + const std::string xstring = "stl const string"s; + std::string xfrobbed = frob::strfrob(xstring); // Cloned + + std::string xstring2 = "stl mutate string"; + frob::strfrob(&xstring2); // Mutated in plate (explicit pointer is used here so you know it's not mutating when you might not expect.) + + constexpr const auto ctime = frob::strfrob<>("done at comptime, like the literal `_frob`"); // Explicit template `<>` is required here otherwise it overloads to the non `constexpr` functions, even in a `constexpr` context; +} + + +``` + +# Test Run `make test` to build and run the test that ensures the original string literal does not appear anywhere in the outputted binary. # License