SWILIB API (SG)    
Loading...
Searching...
No Matches
WSHDR

Detailed Description

Function for working with UTF-16 pascal-style strings.

Usage: #include <swilib.h> or #include <swilib/wstring.h>

Data Structures

struct  WSBODY
 Wide-string body. More...
 
struct  WSHDR
 Wide-string header. More...
 

Macros

#define wsbody(ws)   ((WSBODY *) ((ws)->wsbody))
 

Typedefs

typedef struct WSBODY WSBODY
 
typedef struct WSHDR WSHDR
 

Functions

WSHDR * AllocWS (int size)
 Create new empty WSHDR.
 
WSHDR * CreateWS (malloc_func_t malloc_func, mfree_func_t mfree_func, int size)
 Create new empty WSHDR with custom allocator.
 
WSHDR * CreateLocalWS (WSHDR *header, uint16_t *body, int size)
 Initialize new empty WSHDR with static allocation.
 
void FreeWS (WSHDR *str)
 Free WSHDR.
 
void CutWSTR (WSHDR *str, int length)
 Truncate string.
 
void wsAppendChar (WSHDR *destination, int character)
 Append a character to the end of WSHDR.
 
uint16_t wsCharAt (const WSHDR *str, short pos)
 Get charater at the given position (safe).
 
int GetUnicodeSymbolByDynIcon (int dyn_icon)
 Get character by dynamic icon id.
 
int wsInsertChar (WSHDR *destination, int character, int position)
 Insert a character at the given position of the WSHDR.
 
void wsRemoveChars (WSHDR *destination, int position, int length)
 Remove characters from the WSHDR.
 
WSHDR * wstrcpy (WSHDR *destination, WSHDR *source)
 Copy WSHDR.
 
uint16_t * wstrcopy (uint16_t *destination, const uint16_t *source)
 Copy WSHDR body.
 
WSHDR * wstrncpy (WSHDR *destination, WSHDR *source, int num)
 Copy characters from WSHDR.
 
void wstrcpybypos (WSHDR *destination, WSHDR *source, int from, int num)
 Copy characters from WSHDR.
 
WSHDR * wstrcat (WSHDR *destination, WSHDR *source)
 Concatenate two WSHDR.
 
WSHDR * wstrncat (WSHDR *destination, WSHDR *source, int num)
 Concatenate two WSHDR.
 
short wstrchr (WSHDR *str, uint32_t start, uint32_t character)
 Locate first occurrence of character in WSHDR.
 
short wstrrchr (WSHDR *str, uint32_t rstart, uint32_t character)
 Locate last occurrence of character in WSHDR.
 
int wstrcmp (const WSHDR *str1, const WSHDR *str2)
 Compare two WSHDR strings.
 
int wstrncmp (const WSHDR *ws1, const WSHDR *ws2, size_t n)
 Compare two WSHDR strings, up to a specific length.
 
int wstricmp (const WSHDR *ws1, const WSHDR *ws2)
 Compare two WSHDR strings without case sensitivity.
 
int wstrnicmp (const WSHDR *ws1, const WSHDR *ws2, size_t n)
 Compare two WSHDR strings without case sensitivity, up to a specific length.
 
uint16_t wstrlen (const WSHDR *str)
 Get WSHDR length.
 
uint16_t wstriwstr (const WSHDR *ws, const WSHDR *search, uint32_t start_pos)
 Find the first occurrence of a substring in a WSHDR string, ignoring case, starting from given position.
 
void wstrreplace (WSHDR *dest, const WSHDR *src, uint32_t pos)
 Replace substring in dest with src starting from position pos.
 

Formatting

int wsprintf (WSHDR *s, const char *format,...)
 Write formatted output to WSHDR.
 
void wstrcatprintf (WSHDR *s, const char *format,...)
 Append formatted output to the end of WSHDR.
 

Encoding converting

int ws_2utf8 (const WSHDR *source, char *destination, int *new_length, uint32_t size)
 Convert WSHDR to the UTF-8 C-string.
 
int utf8_2ws (WSHDR *destination, const char *source, uint32_t size)
 Convert UTF-8 C-string to WSHDR.
 
int str_2ws (WSHDR *destination, const char *source, uint32_t size)
 Convert CP1252 (Latin) C-string to WSHDR.
 
void ws_2str (const WSHDR *source, char *destination, uint32_t size)
 Convert WSHDR to the UTF-8 C-string with special mark.
 
void wstrtoupper (WSHDR *ws)
 Convert WSHDR string to uppercase in-place.
 
void wstrtolower (WSHDR *ws)
 Convert WSHDR string to lowercase in-place.
 
void wstrcapitalize (WSHDR *ws)
 Convert WSHDR string to capitalized form in-place (first character uppercase, rest lowercase)
 

Data Structure Documentation

◆ WSBODY

struct WSBODY

◆ WSHDR

struct WSHDR

Macro Definition Documentation

◆ wsbody

#define wsbody ( ws)    ((WSBODY *) ((ws)->wsbody))

Definition at line 30 of file wstring.h.

Typedef Documentation

◆ WSBODY

typedef struct WSBODY WSBODY

Definition at line 17 of file wstring.h.

◆ WSHDR

typedef struct WSHDR WSHDR

Definition at line 18 of file wstring.h.

Function Documentation

◆ AllocWS()

WSHDR * AllocWS ( int size)

Create new empty WSHDR.

Parameters
sizemaximum length of the WSHDR
Returns
pointer to the new allocated WSHDR

◆ CreateWS()

WSHDR * CreateWS ( malloc_func_t malloc_func,
mfree_func_t mfree_func,
int size )

Create new empty WSHDR with custom allocator.

Parameters
malloc_funcpointer to the custom malloc() function
mfree_funcpointer to the custom free() function
sizemaximum length of the WSHDR
Returns
pointer to the new allocated WSHDR

◆ CreateLocalWS()

WSHDR * CreateLocalWS ( WSHDR * header,
uint16_t * body,
int size )

Initialize new empty WSHDR with static allocation.

Parameters
headerpointer to storage for header
bodypointer to storage for body (size + 1)
sizemaximum length of the WSHDR
Returns
pointer to the WSHDR

◆ FreeWS()

void FreeWS ( WSHDR * str)

Free WSHDR.

Parameters
strpointer to the WSHDR allocated by AllocWS

◆ CutWSTR()

void CutWSTR ( WSHDR * str,
int length )

Truncate string.

Parameters
strpointer to the destination WSHDR
lengthlength to which the string should be reduced

◆ wsAppendChar()

void wsAppendChar ( WSHDR * destination,
int character )

Append a character to the end of WSHDR.

Parameters
destinationpointer to the destination WSHDR
charactercharacter to be appended

◆ wsCharAt()

uint16_t wsCharAt ( const WSHDR * str,
short pos )

Get charater at the given position (safe).

Parameters
strpointer to the WSHDR
posposition
Returns
charater

◆ GetUnicodeSymbolByDynIcon()

int GetUnicodeSymbolByDynIcon ( int dyn_icon)

Get character by dynamic icon id.

Parameters
dyn_icondynamic icon id, more than 2000
Returns
character

◆ wsInsertChar()

int wsInsertChar ( WSHDR * destination,
int character,
int position )

Insert a character at the given position of the WSHDR.

Parameters
destinationpointer to the destination WSHDR
charactercharacter to be inserted
positionposition where to be inserted
Returns
new length of the destination WSHDR.

◆ wsRemoveChars()

void wsRemoveChars ( WSHDR * destination,
int position,
int length )

Remove characters from the WSHDR.

Parameters
destinationpointer to the destination WSHDR
positionone-based position of the first character to remove
lengthnumber of characters to remove

◆ wstrcpy()

WSHDR * wstrcpy ( WSHDR * destination,
WSHDR * source )

Copy WSHDR.

Parameters
destinationpointer to the destination WSHDR where the content is to be copied
sourcestring to be copied
Returns
destination is returned.

◆ wstrcopy()

uint16_t * wstrcopy ( uint16_t * destination,
const uint16_t * source )

Copy WSHDR body.

Parameters
destinationpointer to the destination WSHDR body where the content is to be copied
sourceWSHDR body to be copied
Returns
destination is returned.

◆ wstrncpy()

WSHDR * wstrncpy ( WSHDR * destination,
WSHDR * source,
int num )

Copy characters from WSHDR.

Parameters
destinationpointer to the destination WSHDR where the content is to be copied
sourcestring to be copied
nummaximum number of characters to be copied from source
Returns
destination is returned.

◆ wstrcpybypos()

void wstrcpybypos ( WSHDR * destination,
WSHDR * source,
int from,
int num )

Copy characters from WSHDR.

Parameters
destinationpointer to the destination WSHDR where the content is to be copied
sourcestring to be copied
fromoffset in the source string
nummaximum number of characters to be copied from source

◆ wstrcat()

WSHDR * wstrcat ( WSHDR * destination,
WSHDR * source )

Concatenate two WSHDR.

Parameters
destinationpointer to the destination WSHDR, which should be large enough to contain the concatenated resulting string
sourcestring to be appended
Returns
destination is returned.

◆ wstrncat()

WSHDR * wstrncat ( WSHDR * destination,
WSHDR * source,
int num )

Concatenate two WSHDR.

Parameters
destinationpointer to the destination WSHDR, which should be large enough to contain the concatenated resulting string
sourcestring to be appended
nummaximum number of characters to be appended
Returns
destination is returned.

◆ wstrchr()

short wstrchr ( WSHDR * str,
uint32_t start,
uint32_t character )

Locate first occurrence of character in WSHDR.

Parameters
strWSHDR string
startone-based position from which to start searching
charactercharacter to be located
Returns
position of the found character or -1

◆ wstrrchr()

short wstrrchr ( WSHDR * str,
uint32_t rstart,
uint32_t character )

Locate last occurrence of character in WSHDR.

Parameters
strWSHDR string
rstartone-based position from which to search backwards
charactercharacter to be located
Returns
position of the found character or -1

◆ wstrcmp()

int wstrcmp ( const WSHDR * str1,
const WSHDR * str2 )

Compare two WSHDR strings.

Parameters
str1WSHDR to be compared.
str2WSHDR to be compared.
Returns
<0 - the first character that does not match has a lower value in ptr1 than in ptr2
0 - the contents of both strings are equal
>0 - the first character that does not match has a greater value in ptr1 than in ptr2

◆ wstrncmp()

int wstrncmp ( const WSHDR * ws1,
const WSHDR * ws2,
size_t n )

Compare two WSHDR strings, up to a specific length.

Parameters
ws1WSHDR to be compared
ws2WSHDR to be compared
nlength
Returns
<0 - the first character that does not match has a lower value in ws1 than in ws2
0 - the contents of both strings are equal
>0 - the first character that does not match has a greater value in ws1 than in ws2

◆ wstricmp()

int wstricmp ( const WSHDR * ws1,
const WSHDR * ws2 )

Compare two WSHDR strings without case sensitivity.

Parameters
ws1WSHDR to be compared
ws2WSHDR to be compared
Returns
<0 - ws1 is less than ws2 (case-insensitive)
0 - ws1 is equal to ws2 (case-insensitive)
>0 - ws1 is greater than ws2 (case-insensitive)

◆ wstrnicmp()

int wstrnicmp ( const WSHDR * ws1,
const WSHDR * ws2,
size_t n )

Compare two WSHDR strings without case sensitivity, up to a specific length.

Parameters
ws1WSHDR to be compared
ws2WSHDR to be compared
nmaximum number of characters to compare
Returns
<0 - ws1 is less than ws2 (case-insensitive)
0 - ws1 is equal to ws2 (case-insensitive)
0 - ws1 is equal to ws2 (case-insensitive)

◆ wstrlen()

uint16_t wstrlen ( const WSHDR * str)

Get WSHDR length.

Parameters
strpointer to the WSHDR
Returns
The length of WSHDR string

◆ wstriwstr()

uint16_t wstriwstr ( const WSHDR * ws,
const WSHDR * search,
uint32_t start_pos )

Find the first occurrence of a substring in a WSHDR string, ignoring case, starting from given position.

Parameters
wsWSHDR string to search in
searchWSHDR substring to search for (case-insensitive)
start_posstarting position in ws
Returns
position of first occurrence of search at or after start_pos, or 0xFFFF if not found

◆ wstrreplace()

void wstrreplace ( WSHDR * dest,
const WSHDR * src,
uint32_t pos )

Replace substring in dest with src starting from position pos.

Parameters
destWSHDR string to modify (destination)
srcWSHDR string to replace with (source)
posstarting position in dest

◆ wsprintf()

int wsprintf ( WSHDR * s,
const char * format,
... )

Write formatted output to WSHDR.

Additional placeholders:

  • %t - CP1251 string (cyrillic)
  • %s - CP1252 string (latin)
  • %w - UTF-16 string (WSHDR)
Parameters
[out]spointer to a WSHDR where the resulting string is stored, the buffer should be large enough to contain the resulting string
formatC-string that contains a format string that follows the same specifications as standart format in any sprintf/printf (CP1252, latin)
Returns
The number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.
If an encoding error occurs, a negative number is returned.
Notice that only when this returned value is non-negative and less than n, the string has been completely written.

◆ wstrcatprintf()

void wstrcatprintf ( WSHDR * s,
const char * format,
... )

Append formatted output to the end of WSHDR.

Additional placeholders:

  • %t - CP1251 string (cyrillic)
  • %s - CP1252 string (latin)
  • %w - UTF-16 string (WSHDR)
Parameters
[out]spointer to a WSHDR where the resulting string is stored, the buffer should be large enough to contain the resulting string
formatC-string that contains a format string that follows the same specifications as standart format in any sprintf/printf (CP1252, latin)

◆ ws_2utf8()

int ws_2utf8 ( const WSHDR * source,
char * destination,
int * new_length,
uint32_t size )

Convert WSHDR to the UTF-8 C-string.

Parameters
sourceinput WSHDR to be converted to C-string
destinationpointer to the destination C-string, which should be large enough to contain the source WSHDR
new_lengthpointer to which to write the length of the destination string
sizesize of the destination buffer, including space for the terminating null
Returns
1 on success, 0 if the destination buffer is too small

◆ utf8_2ws()

int utf8_2ws ( WSHDR * destination,
const char * source,
uint32_t size )

Convert UTF-8 C-string to WSHDR.

Parameters
destinationpointer to the destination WSHDR, which should be large enough to contain the source string
sourceinput C-string to be converted to WSHDR
sizemaximum number of source bytes to read
Returns
1 on success, 0 on invalid or incomplete UTF-8 or insufficient destination capacity

◆ str_2ws()

int str_2ws ( WSHDR * destination,
const char * source,
uint32_t size )

Convert CP1252 (Latin) C-string to WSHDR.

Parameters
destinationpointer to the destination WSHDR, which should be large enough to contain the source string
sourceinput C-string to be converted to WSHDR
sizemaximum number of characters to be converted
Returns
destination string length

◆ ws_2str()

void ws_2str ( const WSHDR * source,
char * destination,
uint32_t size )

Convert WSHDR to the UTF-8 C-string with special mark.

Parameters
sourceinput WSHDR to be converted to C-string
destinationpointer to the destination C-string, which should be large enough to contain the source WSHDR
sizemaximum number of characters to be converted (+1)

Also, 0x1F (mark of UTF-8 string) will be added at the beginning of the string. This is useful for filesystem functions.

◆ wstrtoupper()

void wstrtoupper ( WSHDR * ws)

Convert WSHDR string to uppercase in-place.

Parameters
wsWSHDR to be converted

◆ wstrtolower()

void wstrtolower ( WSHDR * ws)

Convert WSHDR string to lowercase in-place.

Parameters
wsWSHDR to be converted

◆ wstrcapitalize()

void wstrcapitalize ( WSHDR * ws)

Convert WSHDR string to capitalized form in-place (first character uppercase, rest lowercase)

Parameters
wsWSHDR to be converted