From d2d550216340198d734335215eb0019fbeaa6269 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Mon, 8 Jun 2020 10:14:07 +0100 Subject: [PATCH] Updated code slightly. Updated README.md to have examples. --- .gitignore | 2 ++ README.md | 36 ++++++++++++++++++++++++++++++++++++ utf8.h | 7 ++++--- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..285d10a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +test.cpp +a.out diff --git a/README.md b/README.md index 6f79469..00bf102 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,39 @@ I expect the performance to be abysmally slow and for it to not really be worth To use it, just include "utf8.h" or whatever the file name is at the current moment in time. I'll /probably (not)?/ update this in the future. CC0 because I don't deserve credit for how awful this is. + +Some example code because why not. + +Printing a string: +```cpp +#include +#include "utf8.h" + +int main() { + string32 test = "こんにちは!"; + std::cout << test << "\n"; +} +``` + +Getting the third character of a string, without breaking UTF-8 strings. +```cpp +#include +#include "utf8.h" + +int main() { + string32 test = "こんにちは!"; + std::cout << "The third character of `" << test << "` is: " << test[2] << "\n"; +} +``` + +Iterating over a string: +```cpp +#include +#include "utf8.h" + +int main() { + string32 test = "こんにちは!"; + for (int i(0);i