Turnstone Operating System
Loading...
Searching...
No Matches
strings.xx.c File Reference

Strings library. More...

#include <strings.h>
#include <memory.h>
#include <utils.h>
#include <buffer.h>

Functions

 MODULE ("turnstone.lib.strings")
 
size_t strlen (const char_t *string)
 calculates null ended string's length More...
 
int8_t strcmp (const char_t *string1, const char_t *string2)
 compares two string More...
 
int8_t strcpy (const char_t *source, char_t *destination)
 copies source string to destination string More...
 
char_tstrrev (const char_t *source)
 reverse a string More...
 
number_t ato_base (const char_t *source, number_t base)
 converts string into number More...
 
unumber_t atou_base (const char_t *source, number_t base)
 converts string into number More...
 
char_tito_base (number_t number, number_t base)
 convers number to its string representation More...
 
char_tuto_base (unumber_t number, number_t base)
 convers unsigned number to its string representation More...
 
char_tstrndup_at_heap (memory_heap_t *heap, const char_t *src, size_t l)
 duplicate string at heap More...
 
int8_t strstarts (const char_t *str, const char_t *prefix)
 checks str starts with prefix More...
 
int8_t strends (const char_t *str, const char_t *suffix)
 checks str ends with suffix More...
 
char_tstrchr (const char_t *s, int32_t c)
 finds first occurance of char in string More...
 
char_tstrrchr (const char_t *s, int32_t c)
 finds first occurance of char in string More...
 
char_tstrstr (const char_t *haystack, const char_t *needle)
 finds first occurance of char in string More...
 
char_tstrcat_at_heap (memory_heap_t *heap, const char_t *string1, const char_t *string2)
 concanates two string and returns new one More...
 
int8_t strncmp (const char_t *string1, const char_t *string2, size_t n)
 compares two string with first n bytes More...
 
char_t ** strsplit (const char_t *str, const char_t token, int64_t **lengths, int64_t *count)
 splits string into array More...
 
char_tstrupper (char_t *str)
 converts string to upper case More...
 
char_tstruppercopy (const char_t *str)
 duplicates string and converts it to upper case More...
 
char_tstrlower (char_t *str)
 converts string to lower case More...
 
char_tstrlowercopy (const char_t *str)
 duplicates string and converts it to lower case More...
 
int64_t wchar_size (const wchar_t *str)
 
char_twchar_to_char (wchar_t *src)
 
wchar_tchar_to_wchar (const char_t *str)
 
int64_t lchar_size (const lchar_t *str)
 
char_tlchar_to_char (lchar_t *src)
 
lchar_tchar_to_lchar (char_t *str)
 
char_tstrtrim_right (char_t *str)
 
int8_t str_is_upper (char_t *str)
 
uint64_t strhash (const char_t *input)
 
char_tsprintf (const char_t *format,...)
 
char_tvsprintf (const char_t *format, va_list args)
 

Detailed Description

Strings library.

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Function Documentation

◆ ato_base()

number_t ato_base ( const char_t source,
number_t  base 
)

converts string into number

Parameters
[in]sourcestring represents number in base
[in]basebase of number inside string
Returns
number

◆ atou_base()

unumber_t atou_base ( const char_t source,
number_t  base 
)

converts string into number

Parameters
[in]sourcestring represents number in base
[in]basebase of number inside string
Returns
number

◆ ito_base()

char_t * ito_base ( number_t  number,
number_t  base 
)

convers number to its string representation

Parameters
[in]numbernumber to be converted string
[in]basebase value of conversion
Returns
string represents number

return value should be freed or memory leak will be happened

◆ strcat_at_heap()

char_t * strcat_at_heap ( memory_heap_t heap,
const char_t string1,
const char_t string2 
)

concanates two string and returns new one

Parameters
string1first string
string2second string
Returns
new string, needs freeing or memory leak

◆ strchr()

char_t * strchr ( const char_t s,
int32_t  c 
)

finds first occurance of char in string

Parameters
sstring for look
cchar to find
Returns
pointer to first occurance of char in string

◆ strcmp()

int8_t strcmp ( const char_t string1,
const char_t string2 
)

compares two string

Parameters
string1first string
string2second string
Returns
<0 if string1>string2, 0 string1=string2, >0 string1<string2

◆ strcpy()

int8_t strcpy ( const char_t source,
char_t destination 
)

copies source string to destination string

Parameters
sourcesource string
destinationdestination string
Returns
0 on success

NULL will not be copied. destination should be equal or greater then source. destination should have space for NULL.

◆ strends()

int8_t strends ( const char_t str,
const char_t suffix 
)

checks str ends with suffix

Parameters
strstring for look
suffixto compare
Returns
0 if str ends with suffix, else -1

◆ strlen()

size_t strlen ( const char_t string)

calculates null ended string's length

Parameters
[in]stringstring to calculate length
Returns
length

◆ strlower()

char_t * strlower ( char_t str)

converts string to lower case

Parameters
[in]strstring to lower case
Returns
input string

◆ strlowercopy()

char_t * strlowercopy ( const char_t str)

duplicates string and converts it to lower case

Parameters
[in]strstring to lower case
Returns
new lowercased string

◆ strncmp()

int8_t strncmp ( const char_t string1,
const char_t string2,
size_t  n 
)

compares two string with first n bytes

Parameters
string1first string
string2second string
nfirst n bytes
Returns
<0 if string1>string2, 0 string1=string2, >0 string1<string2

◆ strndup_at_heap()

char_t * strndup_at_heap ( memory_heap_t heap,
const char_t src,
size_t  n 
)

duplicate string at heap

Parameters
[in]heapdestination heap
[in]srcsource string
[in]lengthof destination string
Returns
duplicate at heap

◆ strrchr()

char_t * strrchr ( const char_t s,
int32_t  c 
)

finds first occurance of char in string

Parameters
sstring for look
cchar to find
Returns
pointer to first occurance of char in string

◆ strrev()

char_t * strrev ( const char_t source)

reverse a string

Parameters
[in]sourcestring to be reversed
Returns
reversed string

allocates new space, hence return value needs be freed, else leak will be happened

◆ strsplit()

char_t ** strsplit ( const char_t str,
const char_t  token,
int64_t **  lengths,
int64_t count 
)

splits string into array

Parameters
[in]strstring to tokinize
[in]tokensplit char
[out]lengthsarray of each splitted part's length
[out]countsplitted array length
Returns
array of starts of each part

◆ strstarts()

int8_t strstarts ( const char_t str,
const char_t prefix 
)

checks str starts with prefix

Parameters
strstring for look
prefixto compare
Returns
0 if str starts with prefix, else -1

◆ strstr()

char_t * strstr ( const char_t haystack,
const char_t needle 
)

finds first occurance of char in string

Parameters
sstring for look
cchar to find
Returns
pointer to first occurance of char in string

◆ strupper()

char_t * strupper ( char_t str)

converts string to upper case

Parameters
[in]strstring to upper case
Returns
input string

◆ struppercopy()

char_t * struppercopy ( const char_t str)

duplicates string and converts it to upper case

Parameters
[in]strstring to upper case
Returns
new uppercased string

◆ uto_base()

char_t * uto_base ( unumber_t  number,
number_t  base 
)

convers unsigned number to its string representation

Parameters
[in]numberunsigned number to be converted string
[in]basebase value of conversion
Returns
string represents number

return value should be freed or memory leak will be happened