GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
gp_utf_pos.h File Reference

An iterator for an UTF-8 string. More...

#include <utils/gp_utf.h>
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  gp_utf8_pos
 Position in an UTF-8 string. More...
 

Typedefs

typedef struct gp_utf8_pos gp_utf8_pos
 Position in an UTF-8 string.
 

Functions

static gp_utf8_pos gp_utf8_pos_first (void)
 Moves the position to the start of the string.
 
static gp_utf8_pos gp_utf8_pos_last (const char *str)
 Moves the position to the end of the string.
 
static int gp_utf8_pos_at_end (const char *str, gp_utf8_pos pos)
 Returns true if the position points to the end of the string.
 
static int gp_utf8_pos_at_home (gp_utf8_pos pos)
 Returns true if the position points to the start of the string.
 
static int gp_utf8_pos_eq (gp_utf8_pos a, gp_utf8_pos b)
 Returns true if two positions are equal.
 
static int gp_utf8_pos_gt (gp_utf8_pos a, gp_utf8_pos b)
 Returns true if position a is greater than position b.
 
static int gp_utf8_pos_ge (gp_utf8_pos a, gp_utf8_pos b)
 Returns true if position a is greater or equal to position b.
 
static gp_utf8_pos gp_utf8_pos_sub (gp_utf8_pos a, gp_utf8_pos b)
 Substracts two positions.
 
static gp_utf8_pos gp_utf8_pos_add (gp_utf8_pos a, gp_utf8_pos b)
 Adds two positions.
 
static gp_utf8_pos gp_utf8_pos_min (gp_utf8_pos a, gp_utf8_pos b)
 Returns smaller of two positions.
 
static gp_utf8_pos gp_utf8_pos_max (gp_utf8_pos a, gp_utf8_pos b)
 Returns bigger of two positions.
 
static ssize_t gp_utf8_pos_move (const char *str, gp_utf8_pos *cur_pos, ssize_t dir)
 Moves a position in a string by dir characters.
 
static uint32_t gp_utf8_pos_prev (const char *str, gp_utf8_pos *pos)
 Moves a single character towards the string start and returns current character.
 
static uint32_t gp_utf8_pos_next (const char *str, gp_utf8_pos *pos)
 Moves a single character towards the string end and returns current character.
 

Detailed Description

An iterator for an UTF-8 string.

Helper functions to move by whole characters in an UTF-8 string. This is mainly used for maitaining cursor position in an UTF-8 strings.

Definition in file gp_utf_pos.h.

Function Documentation

◆ gp_utf8_pos_add()

static gp_utf8_pos gp_utf8_pos_add ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Adds two positions.

Parameters
aA position in a string.
bA position in a string.
Returns
Position a plust the position b.

Definition at line 149 of file gp_utf_pos.h.

References gp_utf8_pos::bytes, and gp_utf8_pos::chars.

◆ gp_utf8_pos_at_end()

static int gp_utf8_pos_at_end ( const char *  str,
gp_utf8_pos  pos 
)
inlinestatic

Returns true if the position points to the end of the string.

Parameters
strAn UTF-8 string.
posA position in the string.
Returns
True if the position points to the end of the string.

Definition at line 73 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_at_home()

static int gp_utf8_pos_at_home ( gp_utf8_pos  pos)
inlinestatic

Returns true if the position points to the start of the string.

Parameters
posA position in the string.
Returns
True if the position points to the start of the string.

Definition at line 84 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_eq()

static int gp_utf8_pos_eq ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Returns true if two positions are equal.

Parameters
aA position in a string.
bA position in a string.
Returns
True if two positions are equal.

Definition at line 96 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_first()

static gp_utf8_pos gp_utf8_pos_first ( void  )
inlinestatic

Moves the position to the start of the string.

Returns
A position at the start of the string.

Definition at line 37 of file gp_utf_pos.h.

◆ gp_utf8_pos_ge()

static int gp_utf8_pos_ge ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Returns true if position a is greater or equal to position b.

Parameters
aA position in a string.
bA position in a string.
Returns
True if position a is greater or equal to position b.

Definition at line 120 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_gt()

static int gp_utf8_pos_gt ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Returns true if position a is greater than position b.

Parameters
aA position in a string.
bA position in a string.
Returns
True if position a is greater than position b.

Definition at line 108 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_last()

static gp_utf8_pos gp_utf8_pos_last ( const char *  str)
inlinestatic

Moves the position to the end of the string.

The position bytes will point exactly to the null byte at the end of the string. The chars counter will be less or equal to bytes.

Parameters
strAn UTF-8 string.
Returns
A position at the end of the string.

Definition at line 51 of file gp_utf_pos.h.

References gp_utf8_next_chsz().

◆ gp_utf8_pos_max()

static gp_utf8_pos gp_utf8_pos_max ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Returns bigger of two positions.

Parameters
aA position in a string.
bA position in a string.
Returns
A bigger of two positions.

Definition at line 181 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_min()

static gp_utf8_pos gp_utf8_pos_min ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Returns smaller of two positions.

Parameters
aA position in a string.
bA position in a string.
Returns
A smaller of two positions.

Definition at line 166 of file gp_utf_pos.h.

References gp_utf8_pos::bytes.

◆ gp_utf8_pos_move()

static ssize_t gp_utf8_pos_move ( const char *  str,
gp_utf8_pos cur_pos,
ssize_t  dir 
)
inlinestatic

Moves a position in a string by dir characters.

Parameters
strAn UTF-8 string.
cur_posPointer to a current position in the UTF-8 string that is going to move.
dirA number of characters to move. Negative number moves towards the start, positive towards the end.
Returns
The remider of characters that we were unable to move because we reached start/end of the string.

Definition at line 200 of file gp_utf_pos.h.

References gp_utf8_pos::bytes, gp_utf8_pos::chars, gp_utf8_next_chsz(), and gp_utf8_prev_chsz().

◆ gp_utf8_pos_next()

static uint32_t gp_utf8_pos_next ( const char *  str,
gp_utf8_pos pos 
)
inlinestatic

Moves a single character towards the string end and returns current character.

Parameters
strAn UTF-8 string.
posPointer to a current position in the UTF-8 string that is going to move.
Returns
Current character the position is pointing to after it moved or 0 if the position points to the end of the string.

Definition at line 277 of file gp_utf_pos.h.

References gp_utf8_pos::bytes, gp_utf8_pos::chars, gp_utf8_next(), and gp_utf8_next_chsz().

◆ gp_utf8_pos_prev()

static uint32_t gp_utf8_pos_prev ( const char *  str,
gp_utf8_pos pos 
)
inlinestatic

Moves a single character towards the string start and returns current character.

Parameters
strAn UTF-8 string.
posPointer to a current position in the UTF-8 string that is going to move.
Returns
Current character the position is pointing to after it moved or 0 if the position points to the start of the string.

Definition at line 249 of file gp_utf_pos.h.

References gp_utf8_pos::bytes, gp_utf8_pos::chars, gp_utf8_next(), and gp_utf8_prev_chsz().

◆ gp_utf8_pos_sub()

static gp_utf8_pos gp_utf8_pos_sub ( gp_utf8_pos  a,
gp_utf8_pos  b 
)
inlinestatic

Substracts two positions.

Parameters
aA position in a string.
bA position in a string.
Returns
Position a minus the position b.

Definition at line 132 of file gp_utf_pos.h.

References gp_utf8_pos::bytes, and gp_utf8_pos::chars.