All Projects β†’ sheredom β†’ Utf8.h

sheredom / Utf8.h

Licence: unlicense
πŸ“š single header utf8 string functions for C and C++

Programming Languages

c
50402 projects - #5 most used programming language
cpp
1120 projects

Labels

Projects that are alternatives of or similar to Utf8.h

Urlify
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.
Stars: ✭ 633 (-27.66%)
Mutual labels:  unicode
Unicode Types
Basic Unicode Types of a Ruby String
Stars: ✭ 5 (-99.43%)
Mutual labels:  unicode
Alfred Unicode
Preview Unicode characters and emoji in Alfred
Stars: ✭ 23 (-97.37%)
Mutual labels:  unicode
Ecoji
Encodes (and decodes) data as emojis
Stars: ✭ 671 (-23.31%)
Mutual labels:  unicode
Slug Generator
Slug Generator Library for PHP, based on Unicode’s CLDR data
Stars: ✭ 740 (-15.43%)
Mutual labels:  unicode
Unicopy
Unicode command-line codepoint dumper
Stars: ✭ 16 (-98.17%)
Mutual labels:  unicode
Weird Fonts
𝑨 π‘±π’‚π’—π’‚π‘Ίπ’„π’“π’Šπ’‘π’• π’‘π’‚π’„π’Œπ’‚π’ˆπ’† 𝒕𝒉𝒂𝒕 𝒕𝒖𝒓𝒏 π’‚π’π’‘π’‰π’‚π’π’–π’Žπ’†π’“π’Šπ’„ 𝒄𝒉𝒂𝒓𝒂𝒄𝒕𝒆𝒓𝒔 π’Šπ’π’•π’ π’˜π’†π’Šπ’“π’… 𝒇𝒐𝒏𝒕 π’”π’•π’šπ’π’†.
Stars: ✭ 602 (-31.2%)
Mutual labels:  unicode
Crx Jtrans
jTransliter - the roman to unicode transliter as Google chrome extension
Stars: ✭ 13 (-98.51%)
Mutual labels:  unicode
Zws
Shorten URLs using invisible spaces.
Stars: ✭ 780 (-10.86%)
Mutual labels:  unicode
Lexical Sort
Sort Unicode strings lexicographically
Stars: ✭ 23 (-97.37%)
Mutual labels:  unicode
Awesome Unicode
πŸ˜‚ πŸ‘Œ A curated list of delightful Unicode tidbits, packages and resources.
Stars: ✭ 693 (-20.8%)
Mutual labels:  unicode
Unicodeplots.jl
Unicode-based scientific plotting for working in the terminal
Stars: ✭ 724 (-17.26%)
Mutual labels:  unicode
Nepali Romanized Pro
Nepali Romanized Keyboard Layout with installer for macOS
Stars: ✭ 18 (-97.94%)
Mutual labels:  unicode
Uni
Query the Unicode database from the commandline, with good support for emojis
Stars: ✭ 633 (-27.66%)
Mutual labels:  unicode
Git Praise
A nicer git blame.
Stars: ✭ 24 (-97.26%)
Mutual labels:  unicode
Ugrep
πŸ”NEW ugrep v3.1: ultra fast grep with interactive query UI and fuzzy search: search file systems, source code, text, binary files, archives (cpio/tar/pax/zip), compressed files (gz/Z/bz2/lzma/xz/lz4), documents and more. A faster, user-friendly and compatible grep replacement.
Stars: ✭ 626 (-28.46%)
Mutual labels:  unicode
Pragmatapro
PragmataPro font is designed to help pros to work better
Stars: ✭ 887 (+1.37%)
Mutual labels:  unicode
Myanmar Unicode Fonts
Fonts preview for list of Myanmar Unicode fonts
Stars: ✭ 14 (-98.4%)
Mutual labels:  unicode
Idutf8lib
Idiot's UTF-8 Library
Stars: ✭ 12 (-98.63%)
Mutual labels:  unicode
Nim Unicodedb
Unicode Character Database (UCD, tr44) for Nim
Stars: ✭ 19 (-97.83%)
Mutual labels:  unicode

πŸ“š utf8.h

Actions Status Build status Sponsor

A simple one header solution to supporting utf8 strings in C and C++.

Functions provided from the C header string.h but with a utf8* prefix instead of the str* prefix:

API function docs

string.h utf8.h complete
strcat utf8cat βœ”
strchr utf8chr βœ”
strcmp utf8cmp βœ”
strcoll utf8coll
strcpy utf8cpy βœ”
strcspn utf8cspn βœ”
strdup utf8dup βœ”
strfry utf8fry
strlen utf8len βœ”
strnlen utf8nlen βœ”
strncat utf8ncat βœ”
strncmp utf8ncmp βœ”
strncpy utf8ncpy βœ”
strndup utf8ndup βœ”
strpbrk utf8pbrk βœ”
strrchr utf8rchr βœ”
strsep utf8sep
strspn utf8spn βœ”
strstr utf8str βœ”
strtok utf8tok
strxfrm utf8xfrm

Functions provided from the C header strings.h but with a utf8* prefix instead of the str* prefix:

strings.h utf8.h complete
strcasecmp utf8casecmp βœ”
strncasecmp utf8ncasecmp βœ”
strcasestr utf8casestr βœ”

Functions provided that are unique to utf8.h:

utf8.h complete
utf8codepoint βœ”
utf8rcodepoint βœ”
utf8size βœ”
utf8size_lazy βœ”
utf8nsize_lazy βœ”
utf8valid βœ”
utf8nvalid βœ”
utf8makevalid βœ”
utf8codepointsize βœ”
utf8catcodepoint βœ”
utf8isupper βœ”
utf8islower βœ”
utf8lwr βœ”
utf8upr βœ”
utf8lwrcodepoint βœ”
utf8uprcodepoint βœ”

Usage

Just #include "utf8.h" in your code!

The current supported platforms are Linux, macOS and Windows.

The current supported compilers are gcc, clang, MSVC's cl.exe, and clang-cl.exe.

Design

The utf8.h API matches the string.h API as much as possible by design. There are a few major differences though.

I use void* instead of char* when passing around utf8 strings. My reasoning is that I really don't want people accidentally thinking they can use integer arthimetic on the pointer and always get a valid character like you would with an ASCII string. Having it as a void* forces a user to explicitly cast the utf8 string to char* such that the onus is on them not to break the code anymore!

Anywhere in the string.h or strings.h documentation where it refers to 'bytes' I have changed that to utf8 codepoints. For instance, utf8len will return the number of utf8 codepoints in a utf8 string - which does not necessarily equate to the number of bytes.

API function docs

int utf8casecmp(const void *src1, const void *src2);

Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > src2 respectively, case insensitive.

void *utf8cat(void *dst, const void *src);

Append the utf8 string src onto the utf8 string dst.

void *utf8chr(const void *src, utf8_int32_t chr);

Find the first match of the utf8 codepoint chr in the utf8 string src.

int utf8cmp(const void *src1, const void *src2);

Return less than 0, 0, greater than 0 if src1 < src2,
src1 == src2, src1 > src2 respectively.

void *utf8cpy(void *dst, const void *src);

Copy the utf8 string src onto the memory allocated in dst.

size_t utf8cspn(const void *src, const void *reject);

Number of utf8 codepoints in the utf8 string src that consists entirely
of utf8 codepoints not from the utf8 string reject.

void *utf8dup(const void *src);

Duplicate the utf8 string src by getting its size, mallocing a new buffer
copying over the data, and returning that. Or 0 if malloc failed.

size_t utf8len(const void *str);

Number of utf8 codepoints in the utf8 string str,
excluding the null terminating byte.

size_t utf8nlen(const void *str, size_t n);

Similar to utf8len, except that only at most n bytes of src are looked.

int utf8ncasecmp(const void *src1, const void *src2, size_t n);

Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2,
src1 > src2 respectively, case insensitive. Checking at most n
bytes of each utf8 string.

void *utf8ncat(void *dst, const void *src, size_t n);

Append the utf8 string src onto the utf8 string dst,
writing at most n+1 bytes. Can produce an invalid utf8
string if n falls partway through a utf8 codepoint.

int utf8ncmp(const void *src1, const void *src2, size_t n);

Return less than 0, 0, greater than 0 if src1 < src2,
src1 == src2, src1 > src2 respectively. Checking at most n
bytes of each utf8 string.

void *utf8ncpy(void *dst, const void *src, size_t n);

Copy the utf8 string src onto the memory allocated in dst.
Copies at most n bytes. If n falls partway through a utf8 codepoint, or if dst doesn't have enough room for a null terminator, the final string will be cut short to preserve utf8 validity.

void *utf8pbrk(const void *str, const void *accept);

Locates the first occurrence in the utf8 string str of any byte in the
utf8 string accept, or 0 if no match was found.

void *utf8rchr(const void *src, utf8_int32_t chr);

Find the last match of the utf8 codepoint chr in the utf8 string src.

size_t utf8size(const void *str);

Number of bytes in the utf8 string str,
including the null terminating byte.

size_t utf8size_lazy(const void *str);

Similar to utf8size, except that the null terminating byte is excluded.

size_t utf8nsize_lazy(const void *str, size_t n);

Similar to utf8size, except that only at most n bytes of src are looked and the null terminating byte is excluded.

size_t utf8spn(const void *src, const void *accept);

Number of utf8 codepoints in the utf8 string src that consists entirely
of utf8 codepoints from the utf8 string accept.

void *utf8str(const void *haystack, const void *needle);

The position of the utf8 string needle in the utf8 string haystack.

void *utf8casestr(const void *haystack, const void *needle);

The position of the utf8 string needle in the utf8 string haystack, case insensitive.

void *utf8valid(const void *str);

Return 0 on success, or the position of the invalid utf8 codepoint on failure.

void *utf8nvalid(const void *str, size_t n);

Similar to utf8valid, except that only at most n bytes of src are looked.

int utf8makevalid(void *str, utf8_int32_t replacement);

Return 0 on success. Makes the str valid by replacing invalid sequences with the 1-byte replacement codepoint.

void *utf8codepoint(const void *str, utf8_int32_t *out_codepoint);

Sets out_codepoint to the current utf8 codepoint in str, and returns the address of the next utf8 codepoint after the current one in str.

void *utf8rcodepoint(const void *str, utf8_int32_t *out_codepoint);

Sets out_codepoint to the current utf8 codepoint in str, and returns the address of the previous utf8 codepoint before the current one in str.

size_t utf8codepointsize(utf8_int32_t chr);

Returns the size of the given codepoint in bytes.

void *utf8catcodepoint(void *utf8_restrict str, utf8_int32_t chr, size_t n);

Write a codepoint to the given string, and return the address to the next place after the written codepoint. Pass how many bytes left in the buffer to n. If there is not enough space for the codepoint, this function returns null.

int utf8islower(utf8_int32_t chr);

Returns 1 if the given character is lowercase, or 0 if it is not.

int utf8isupper(utf8_int32_t chr);

Returns 1 if the given character is uppercase, or 0 if it is not.

void utf8lwr(void *utf8_restrict str);

Transform the given string into all lowercase codepoints.

void utf8upr(void *utf8_restrict str);

Transform the given string into all uppercase codepoints.

utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp);

Make a codepoint lower case if possible.

utf8_int32_t utf8uprcodepoint(utf8_int32_t cp);

Make a codepoint upper case if possible.

Codepoint Case

Various functions provided will do case insensitive compares, or transform utf8 strings from one case to another. Given the vastness of unicode, and the authors lack of understanding beyond latin codepoints on whether case means anything, the following categories are the only ones that will be checked in case insensitive code:

Todo

License

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].