Ascii23 is a header-only C++ library offering ASCII-related functionality. It may be used as an alternative to the <cctype> header. Unlike cctype, ascii23 has the same behavior regardless of locale, and it behaves sensibly and predictably with UTF-8 and other Unicode text inputs. (Neither non-ASCII Unicode code points nor UTF-8 code units belonging to non-ASCII code points should ever produce false positives.)
Ascii23 is released under the permissive zlib/libpng license.
For complete API documentation, please refer either to the commented source code in src/ascii23.h or to the documentation.md Markdown file in the root directory of this repository.
Here is a summary of the functions implemented by ascii23, which are defined in the ascii namespace:
bool ascii::is_char(const int ch); // Return true if input is 0x00-0x7f.
bool ascii::is_alpha_char(const int ch); // True if a-z, A-Z.
bool ascii::is_alpha_lower_char(const int ch); // True if a-z.
bool ascii::is_alpha_upper_char(const int ch); // True if A-Z.
bool ascii::is_digit_char(const int ch); // True if 0-9.
bool ascii::is_hex_digit_char(const int ch); // True if 0-9, a-f, A-F.
bool ascii::is_hex_digit_lower_char(const int ch); // True if 0-9, a-f.
bool ascii::is_hex_digit_upper_char(const int ch); // True if 0-9, A-F.
bool ascii::is_word_char(const int ch); // True if _, 0-9, a-z, A-Z.
bool ascii::is_word_lower_char(const int ch); // True if _, 0-9, a-z.
bool ascii::is_word_upper_char(const int ch); // True if _, 0-9, A-Z.
bool ascii::is_word_start_char(const int ch); // True if _, a-z, A-Z.
bool ascii::is_word_lower_start_char(const int ch); // True if _, a-z.
bool ascii::is_word_upper_start_char(const int ch); // True if _, A-Z.
bool ascii::is_punctuation_char(const int ch); // !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
bool ascii::is_whitespace_char(const int ch); // True if \t, \r, \v, \f, \n, or space.
bool ascii::is_blank_char(const int ch); // True if \t or space.
bool ascii::is_null_char(const int ch); // True if input is 0x00.
bool ascii::is_control_char(const int ch); // True if 0x00-0x1f or 0x7f.
bool ascii::is_printable_char(const int ch); // True if 0x20-0x7e.
bool ascii::is_graphical_char(const int ch); // True if 0x21-0x7e.
int ascii::to_lower_char(const int ch); // Convert A-Z to a-z, all others unchanged.
int ascii::to_upper_char(const int ch); // Convert a-z to A-Z, all others unchanged.As a header-only library:
To use ascii23 as a header-only library (recommended):
- Copy
src/ascii23.hfrom this repository into your project's include directory. - Write
#include <ascii23.h>in your source files to include it.
Static linking:
To compile libascii23.a and link with it statically:
- Run
make release_libin this repository's root directory. - Copy the newly created
lib/libascii23.afile into your project's lib directory. - Copy
src/ascii23.hfrom this repository into your project's include directory. - Configure your project to link with
libascii23.a, e.g. by adding-lascii23to your linker flags. - Define
ASCII23_USE_COMPILED_LIBin your project before includingascii23.h, e.g. by adding-DASCII23_USE_COMPILED_LIBto your compiler flags. - Write
#include <ascii23.h>in your source files to include declarations only.
Dynamic linking on Windows:
To compile ascii23.dll and link with it dynamically:
- Run
make release_dllin this repository's root directory. - Copy the newly created
lib/ascii23.dllfile into your project's lib directory. - Copy the newly created
lib/ascii23.dllfile additionally to a path where your system will search for DLLs when running your compiled project, e.g. in the same directory as your project's compiled *.exe. - Copy
src/ascii23.hfrom this repository into your project's include directory. - Configure your project to link with
ascii23.dll, e.g. by adding-lascii23to your linker flags. - Define
ASCII23_USE_SHARED_LIBin your project before includingascii23.h, e.g. by adding-DASCII23_USE_SHARED_LIBto your compiler flags. - Write
#include <ascii23.h>in your source files to include declarations only.