tetengo 1.8.1
A multipurpose library set
Loading...
Searching...
No Matches
graphemeSplitter.h File Reference

A grapheme splitter. More...

#include <stddef.h>
+ Include dependency graph for graphemeSplitter.h:

Go to the source code of this file.

Classes

struct  tetengo_text_grapheme_tag
 A grapheme. More...
 

Typedefs

typedef struct tetengo_text_grapheme_tag tetengo_text_grapheme_t
 A grapheme.
 

Functions

tetengo_text_graphemeSplitter_t * tetengo_text_graphemeSplitter_create ()
 Creates a grapheme splitter.
 
void tetengo_text_graphemeSplitter_destroy (const tetengo_text_graphemeSplitter_t *p_grapheme_splitter)
 Destroys a grapheme splitter.
 
size_t tetengo_text_graphemeSplitter_split (const tetengo_text_graphemeSplitter_t *p_grapheme_splitter, const char *string, tetengo_text_grapheme_t *p_graphemes)
 Split a string to graphemes.
 

Detailed Description

A grapheme splitter.

Copyright (C) 2019-2023 kaoru https://www.tetengo.org/

Function Documentation

◆ tetengo_text_graphemeSplitter_create()

tetengo_text_graphemeSplitter_t * tetengo_text_graphemeSplitter_create ( )

Creates a grapheme splitter.

Call setlocale(LC_CTYPE, [your locale]) before calling this function. The locale affects the result of the grapheme splitter.

Returns
A pointer to a grapheme splitter.

◆ tetengo_text_graphemeSplitter_destroy()

void tetengo_text_graphemeSplitter_destroy ( const tetengo_text_graphemeSplitter_t *  p_grapheme_splitter)

Destroys a grapheme splitter.

Parameters
p_grapheme_splitterA pointer to a grapheme splitter.

◆ tetengo_text_graphemeSplitter_split()

size_t tetengo_text_graphemeSplitter_split ( const tetengo_text_graphemeSplitter_t *  p_grapheme_splitter,
const char *  string,
tetengo_text_grapheme_t p_graphemes 
)

Split a string to graphemes.

For emoji defined as "neutral" width in the Unicode standard, this function returns a character width of 2 in the East Asian (Chinese, Japanese or Korean) locale, or 1 in the other locale.

The returned graphemes include a sentinel at the tail. Its offset is the length of the string and its width is 0.

Parameters
p_grapheme_splitterA pointer to a grapheme splitter.
stringA string.
p_graphemesThe storage for graphemes. Can be NULL.
Returns
A grapheme count. Or 0 when p_grapheme_splitter is NULL or string is NULL.