utf8.c File Reference

#include "utf8.h"
#include <string.h>
Include dependency graph for utf8.c:

Go to the source code of this file.

Functions

int UTF8_delete_char (char *s, int pos)
 Delete a whole (possibly multibyte) character from a string.
int UTF8_insert_char (char *s, int n, int pos, int c)
 Insert a (possibly multibyte) UTF-8 character into a string.
int UTF8_char_len (unsigned char c)
 length of UTF-8 character starting with this byte.
int UTF8_encoded_len (int c)
size_t UTF8_strlen (const char *str)
 Count the number of character (not the number of bytes) of a zero termination string.
char * UTF8_strncpyz (char *dest, const char *src, size_t limit)
 UTF8 capable string copy function.

Detailed Description

Definition in file utf8.c.


Function Documentation

int UTF8_char_len ( unsigned char  c  ) 

length of UTF-8 character starting with this byte.

Returns:
length of character encoding, or 0 if not start of a UTF-8 sequence
Todo:
Using this does not solve the truncation problem in case of decomposed characters. For example a code for "a" followed by a code for "put dots above previous character: the "a" will be reported as a character of length 1 by this function, even though the code that follows is part of its visual appearance and should not be cut off separately. Fortunately decomposed characters are rarely used.

Definition at line 103 of file utf8.c.

Referenced by Com_sprintf(), R_FontMakeChunks(), UTF8_strlen(), and UTF8_strncpyz().

int UTF8_delete_char ( char *  s,
int  pos 
)

Delete a whole (possibly multibyte) character from a string.

Parameters:
[in] s Start of the string
[in] pos Offset from the start
Returns:
position where deleted character started

Definition at line 35 of file utf8.c.

References next, and UTF8_CONTINUATION_BYTE.

Referenced by Key_Message(), and UI_TextEntryNodeEdit().

int UTF8_encoded_len ( int  c  ) 

Calculate how long a Unicode code point (such as returned by SDL key events in unicode mode) would be in UTF-8 encoding.

Definition at line 124 of file utf8.c.

Referenced by Key_Message(), UI_TextEntryNodeEdit(), and UTF8_insert_char().

int UTF8_insert_char ( char *  s,
int  n,
int  pos,
int  c 
)

Insert a (possibly multibyte) UTF-8 character into a string.

Parameters:
[in] s Start of the string
[in] n Buffer size of the string
[in] pos Offset from the start
[in] c Unicode code as 32-bit integer
Returns:
Number of bytes added

Definition at line 60 of file utf8.c.

References UTF8_encoded_len().

Referenced by Key_Message(), and UI_TextEntryNodeEdit().

size_t UTF8_strlen ( const char *  str  ) 

Count the number of character (not the number of bytes) of a zero termination string.

Note:
the \0 termination characted is not counted
to count the number of bytes, use strlen
See also:
strlen

Definition at line 143 of file utf8.c.

References UTF8_char_len().

Referenced by UI_TextEntryNodeDraw().

char* UTF8_strncpyz ( char *  dest,
const char *  src,
size_t  limit 
)

UTF8 capable string copy function.

Parameters:
[out] dest Pointer to the output string
[in] src Pointer to the input string
[in] limit Maximum number of bytes to copy
Returns:
dest pointer

Definition at line 162 of file utf8.c.

References i, and UTF8_char_len().

Referenced by Q_strncpyz(), and testStringCopiers().


Generated by  doxygen 1.6.2