I’ve been working on a project in C++ recently, and in so doing I realized that I could not find a good standardized C++ library for dealing with ASCII text. At least not besides the cctype header, which features some surprising and usually unwanted behavior.

So I recently wrote and published my first C++ library, named ascii23. It’s a small header-only library which provides some ASCII-related functions, such as checking whether an input is an ASCII whitespace character, or converting upper-case ASCII characters to their lower-case equivalents and vice versa. Unlike cctype, ascii23’s behavior is the same regardless of locale. Also unlike cctype, it behaves sensibly with Unicode code points and UTF-8 code units, correctly recognizing and handling non-ASCII inputs.

The library includes a benchmarking tool, which was used to write very performant implementations of these ASCII functions, as well as comprehensive unit tests. You can find it on GitHub here, and you can quickly make use of it in your own project by copying the file “src/ascii23.h” into an include directory and including that header in your project: