OpenTTD Source 20250426-master-gbb1d561369
utf8.hpp File Reference

Handling of UTF-8 encoded data. More...

#include <iterator>
#include "bitmath_func.hpp"

Go to the source code of this file.

Data Structures

class  Utf8View
 Constant span of UTF-8 encoded data. More...
 
class  Utf8View::iterator
 Bidirectional input iterator over codepoints. More...
 

Functions

std::pair< char[4], size_t > EncodeUtf8 (char32_t c)
 Encode a character to UTF-8.
 
std::pair< size_t, char32_t > DecodeUtf8 (std::string_view buf)
 Decode a character from UTF-8.
 
bool IsUtf8Part (char c)
 

Detailed Description

Handling of UTF-8 encoded data.

Definition in file utf8.hpp.

Function Documentation

◆ DecodeUtf8()

std::pair< size_t, char32_t > DecodeUtf8 ( std::string_view  buf)

Decode a character from UTF-8.

Parameters
bufBinary data.
Returns
Length and character. Length is zero, if the input data is invalid.

Definition at line 48 of file utf8.cpp.

References GB(), and HasBit().

Referenced by GlobalVarChangeInfo(), StringConsumer::PeekUtf8(), and VideoDriver_SDL_Base::PollEvent().

◆ EncodeUtf8()

std::pair< char[4], size_t > EncodeUtf8 ( char32_t  c)

Encode a character to UTF-8.

Parameters
cCharacter
Returns
Binary data and length. Length is zero, if "c" is out of range.

Definition at line 21 of file utf8.cpp.

References GB().

Referenced by StringConsumer::FindUtf8(), Textbuf::InsertChar(), StringConsumer::PeekUntilUtf8(), BaseStringBuilder::PutUtf8(), StringConsumer::ReadUntilUtf8(), and StringConsumer::SkipUntilUtf8().

◆ IsUtf8Part()

bool IsUtf8Part ( char  c)
inline

Definition at line 22 of file utf8.hpp.