Fcitx
Classes | Functions | Variables
utf8.h File Reference

C++ Utility functions for handling utf8 strings. More...

#include <sys/types.h>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <fcitx-utils/cutf8.h>
#include <fcitx-utils/fcitxutils_export.h>
#include <fcitx-utils/macros.h>
#include <fcitx-utils/misc.h>
Include dependency graph for utf8.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  fcitx::utf8::UTF8CharIterator< Iter >
 Helper class to iterate character, you need to validate the string before using it. More...
 
class  fcitx::utf8::UTF8StringViewIter< Iter >
 

Functions

template<typename Iter >
size_t fcitx::utf8::length (Iter start, Iter end)
 Return the number UTF-8 characters in the string iterator range. More...
 
template<typename T >
size_t fcitx::utf8::length (const T &s)
 Return the number UTF-8 characters in the string. More...
 
template<typename T >
size_t fcitx::utf8::length (const T &s, size_t start, size_t end)
 Return the number UTF-8 characters in the string.
 
template<typename Iter >
size_t fcitx::utf8::lengthValidated (Iter start, Iter end)
 Validate and return the number UTF-8 characters in the string iterator range. More...
 
template<typename T >
size_t fcitx::utf8::lengthValidated (const T &s)
 Validate and return the number UTF-8 characters in the string. More...
 
template<typename Iter >
bool fcitx::utf8::validate (Iter start, Iter end)
 Check if the string iterator range is valid utf8 string.
 
template<typename T >
bool fcitx::utf8::validate (const T &s)
 Check if the string is valid utf8 string.
 
std::string fcitx::utf8::UCS4ToUTF8 (uint32_t code)
 Convert UCS4 to UTF8 string.
 
bool fcitx::utf8::UCS4IsValid (uint32_t code)
 Check if a ucs4 is valid.
 
bool fcitx::utf8::isValidChar (uint32_t c)
 Check the chr value is not two invalid value above.
 
template<typename Iter >
uint32_t fcitx::utf8::getChar (Iter iter, Iter end)
 Get next UCS4 char from iter, do not cross end. More...
 
template<typename T >
uint32_t fcitx::utf8::getChar (const T &s)
 Get next UCS4 char, may return INVALID_CHAR or NOT_ENOUGH_SPACE.
 
template<typename Iter >
Iter fcitx::utf8::getNextChar (Iter iter, Iter end, uint32_t *chr)
 
template<typename Iter >
ssize_t fcitx::utf8::ncharByteLength (Iter iter, size_t n)
 get the byte length of next N utf-8 character. More...
 
template<typename Iter >
Iter fcitx::utf8::nextNChar (Iter iter, size_t n)
 Move iter over next n character.
 
template<typename Iter >
Iter fcitx::utf8::nextChar (Iter iter)
 Move iter over next one character.
 
template<typename Iter >
uint32_t fcitx::utf8::getLastChar (Iter iter, Iter end)
 
template<typename T >
uint32_t fcitx::utf8::getLastChar (const T &str)
 
template<typename Iter >
auto fcitx::utf8::MakeUTF8CharIterator (Iter iter, Iter end)
 
template<typename T >
auto fcitx::utf8::MakeUTF8CharRange (const T &str)
 
template<typename Iter >
auto fcitx::utf8::MakeUTF8StringViewIterator (Iter iter, Iter end)
 
template<typename T >
auto fcitx::utf8::MakeUTF8StringViewRange (const T &str)
 

Variables

constexpr size_t fcitx::utf8::INVALID_LENGTH = static_cast<size_t>(-1)
 Possible return value of lengthValidated if the string is not valid. More...
 
constexpr uint32_t fcitx::utf8::INVALID_CHAR = static_cast<uint32_t>(-1)
 Possible return value for getChar.
 
constexpr uint32_t fcitx::utf8::NOT_ENOUGH_SPACE = static_cast<uint32_t>(-2)
 Possible return value for getChar.
 

Detailed Description

C++ Utility functions for handling utf8 strings.

Definition in file utf8.h.