myMPD
Internal API documentation
Loading...
Searching...
No Matches
sds_extras.h File Reference

Extra functions for sds strings. More...

#include "dist/sds/sds.h"
#include <stdbool.h>
#include <stdio.h>
Include dependency graph for sds_extras.h:

Go to the source code of this file.

Macros

#define FREE_SDS(SDS_PTR)
 

Functions

sds sds_basename (sds s)
 
sds sds_dirname (sds s)
 
sds * sds_split_comma_trim (sds s, int *count)
 
void sds_utf8_tolower (sds s)
 
sds sds_catjson_plain (sds s, const char *p, size_t len)
 
sds sds_catjson (sds s, const char *p, size_t len)
 
sds sds_catjsonchar (sds s, const char c)
 
sds sds_catchar (sds s, const char c)
 
bool sds_json_unescape (const char *src, size_t slen, sds *dst)
 
sds sds_urldecode (sds s, const char *p, size_t len, bool is_form_url_encoded)
 
sds sds_urlencode (sds s, const char *p, size_t len)
 
sds sds_replacelen (sds s, const char *p, size_t len)
 
sds sds_replace (sds s, const char *p)
 
sds sds_catbool (sds s, bool v)
 
sds sds_hash_md5 (const char *p)
 
sds sds_hash_sha1 (const char *p)
 
sds sds_hash_sha1_sds (sds s)
 
sds sds_hash_sha256 (const char *p)
 
sds sds_hash_sha256_sds (sds s)
 
sds sds_pad_int (int64_t value, sds buffer)
 
void sds_free_void (void *p)
 

Detailed Description

Extra functions for sds strings.

Macro Definition Documentation

◆ FREE_SDS

#define FREE_SDS (   SDS_PTR)
Value:
do { \
sdsfree(SDS_PTR); \
SDS_PTR = NULL; \
} while (0)

Frees an sds string and sets it to NULL

Function Documentation

◆ sds_basename()

sds sds_basename ( sds  s)

Replacement for basename function. Modifies the sds string in place.

Parameters
ssds string to apply basename function
Returns
new pointer to s

◆ sds_catbool()

sds sds_catbool ( sds  s,
bool  v 
)

Converts a bool value to a sds string

Parameters
sstring to append the value
vbool value to convert
Returns
modified sds string

◆ sds_catchar()

sds sds_catchar ( sds  s,
const char  c 
)

Appends a char to sds string s, this is faster than using sdscatfmt

Parameters
ssds string
cchar to append
Returns
modified sds string

◆ sds_catjson()

sds sds_catjson ( sds  s,
const char *  p,
size_t  len 
)

Append to the sds string "s" a quoted json escaped string After the call, the modified sds string is no longer valid and all the references must be substituted with the new pointer returned by the call.

Parameters
ssds string
pstring to append json escaped
lenlength of the string to append
Returns
modified sds string

◆ sds_catjson_plain()

sds sds_catjson_plain ( sds  s,
const char *  p,
size_t  len 
)

Append to the sds string "s" a json escaped string After the call, the modified sds string is no longer valid and all the references must be substituted with the new pointer returned by the call.

Parameters
ssds string
pstring to append json escaped
lenlength of the string to append
Returns
modified sds string

◆ sds_catjsonchar()

sds sds_catjsonchar ( sds  s,
const char  c 
)

Append to the sds string "s" an json escaped character After the call, the modified sds string is no longer valid and all the references must be substituted with the new pointer returned by the call.

Parameters
ssds string
cchar to escape and append
Returns
modified sds string

◆ sds_dirname()

sds sds_dirname ( sds  s)

Replacement for dirname function. Modifies the sds string in place.

Parameters
ssds string to apply dirname function
Returns
new pointer to s

◆ sds_free_void()

void sds_free_void ( void *  p)

Frees an sds string pointed by void pointer

Parameters
pVoid pointer to sds string

◆ sds_hash_md5()

sds sds_hash_md5 ( const char *  p)

Hashes a string with md5

Parameters
pstring to hash
Returns
the hash as a newly allocated sds string

◆ sds_hash_sha1()

sds sds_hash_sha1 ( const char *  p)

Hashes a string with sha1

Parameters
pstring to hash
Returns
the hash as a newly allocated sds string

◆ sds_hash_sha1_sds()

sds sds_hash_sha1_sds ( sds  s)

Hashes a sds string with sha1 inplace

Parameters
sstring to hash
Returns
pointer to s

◆ sds_hash_sha256()

sds sds_hash_sha256 ( const char *  p)

Hashes a string with sha256

Parameters
pstring to hash
Returns
the hash as a newly allocated sds string

◆ sds_hash_sha256_sds()

sds sds_hash_sha256_sds ( sds  s)

Hashes a sds string with sha256 inplace

Parameters
sstring to hash
Returns
pointer to s

◆ sds_json_unescape()

bool sds_json_unescape ( const char *  src,
size_t  slen,
sds *  dst 
)

Json unescapes "src" and appends the result to the sds string "dst" "dst" must be a pointer to a allocated sds string.

Parameters
srcstring to unescape
slenstring length to unescape
dstpointer to sds string to append the unescaped string
Returns
true on success, false on error

◆ sds_pad_int()

sds sds_pad_int ( int64_t  value,
sds  buffer 
)

Prints a zero padded value

Parameters
valuempd song struct
bufferalready allocated sds string to append
Returns
pointer to buffer

◆ sds_replace()

sds sds_replace ( sds  s,
const char *  p 
)

Replaces a sds string with a new value, allocates the string if it is NULL

Parameters
ssds string to replace
preplacement string
Returns
modified sds string

◆ sds_replacelen()

sds sds_replacelen ( sds  s,
const char *  p,
size_t  len 
)

Replaces a sds string with a new value, allocates the string if it is NULL

Parameters
ssds string to replace
preplacement string
lenreplacement string length
Returns
modified sds string

◆ sds_split_comma_trim()

sds * sds_split_comma_trim ( sds  s,
int *  count 
)

Splits a comma separated string and trims whitespaces from single values

Parameters
sstring to split
countpointer to int representing the count of values
Returns
array of sds strings

◆ sds_urldecode()

sds sds_urldecode ( sds  s,
const char *  p,
size_t  len,
bool  is_form_url_encoded 
)

Url decodes a string

Parameters
ssds string to append the url decoded string
pstring to url decode
lenstring length to url decode
is_form_url_encodedtrue decodes + chars to spaces
Returns
modified sds string

◆ sds_urlencode()

sds sds_urlencode ( sds  s,
const char *  p,
size_t  len 
)

Url encodes a string

Parameters
ssds string to append the encoded string
pstring to url encode
lenstring length to url encode
Returns
modified sds string

◆ sds_utf8_tolower()

void sds_utf8_tolower ( sds  s)

Makes the string lower case (utf8 aware)

Parameters
ssds string to modify in place