xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / src / utils / utf8.h (c2b8d6e806293f7d6b39d3afbedbe3e59726a3a6) (4,393B) (mode 100644) [raw]
/* vifm
 * Copyright (C) 2011 xaizek.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifndef VIFM__UTILS__UTF8_H__
#define VIFM__UTILS__UTF8_H__

#include <stddef.h> /* size_t wchar_t */

/* Abbreviations:
 *  - "n"  -- "normal", excluding incomplete (broken) utf-8 sequences;
 *  - "sn" -- "screen number", screen width limit;
 *  - "w"  -- "width", in bytes;
 *  - "o"  -- "overhead";
 *  - "sw" -- "screen width", i.e. number of character positions taken on the
 *            screen;
 *  - "so" -- "screen overhead". */

/* Calculates real width of valid and complete utf-8 character in bytes.
 * Returns the width. */
size_t utf8_chrw(const char str[]);

/* Counts number of utf-8 characters excluding incomplete utf-8 characters.
 * Returns the count. */
size_t utf8_nstrlen(const char str[]);

/* Calculates count of bytes of whole str or of the first max_screen_width utf-8
 * characters (so one character which takes several positions on the screen is
 * counted as several positions).  Returns the count. */
size_t utf8_strsnlen(const char str[], size_t max_screen_width);

/* Same as utf8_strsnlen(), but ignores trailing incomplete utf-8 characters. */
size_t utf8_nstrsnlen(const char str[], size_t max_screen_width);

/* Counts number of screen characters in a utf-8 encoded str.  Returns the
 * number. */
size_t utf8_strsw(const char str[]);

/* Counts number of screen characters in a utf-8 encoded str of the specified
 * length (or less if NUL byte is found earlier).  If length ends in the middle
 * of a utf-8 character, the character's screen width is counted as well.
 * Returns the number. */
size_t utf8_nstrsw(const char str[], int len);

/* Counts number of screen characters in a utf-8 encoded str expanding
 * tabulation according to specified tab stops.  tab_stops must be positive.
 * Returns the number. */
size_t utf8_strsw_with_tabs(const char str[], int tab_stops);

/* Gets screen width of the first character in the string.  Returns the
 * width or (size_t)-1 for unknown/broken characters. */
size_t utf8_chrsw(const char str[]);

/* Calculates string overhead (string_bytes - string_chars).  Returns the
 * overhead. */
size_t utf8_stro(const char str[]);

/* Calculates string screen overhead (string_bytes - string_screen_chars).
 * Returns the overhead. */
size_t utf8_strso(const char str[]);

/* Copies as many full utf-8 characters from source to destination as size of
 * destination buffer permits.  Returns number of actually copied bytes
 * including terminating null character. */
size_t utf8_strcpy(char dst[], const char src[], size_t dst_len);

/* Extracts first utf-8 character from the string converting it to wide
 * character representation.  Returns the wide character and sets *len to width
 * of input character, which can be 0. */
wchar_t utf8_first_char(const char utf8[], int *len);

/* Converts UTF-8 string into UTF-8 string that uses predictable encoding forms
 * of symbols, thus making it possible to compare differently encoded but
 * otherwise identical symbols.  Returns a newly allocated string or NULL. */
char * utf8_normalize(const char str[], int ignore_case);

#ifdef _WIN32

/* Converts utf-8 to utf-16 string.  Returns newly allocated utf-8 string. */
wchar_t * utf8_to_utf16(const char utf8[]);

/* Calculates how many utf-16 chars are needed to store given utf-8 string.
 * Returns the number. */
size_t utf8_widen_len(const char utf8[]);

/* Converts utf-16 to utf-8 string.  Returns newly allocated utf-16 string. */
char * utf8_from_utf16(const wchar_t utf16[]);

#endif

#endif /* VIFM__UTILS__UTF8_H__ */

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master