Extra functions for sds strings.
More...
#include "dist/sds/sds.h"
#include <stdbool.h>
#include <stdio.h>
Go to the source code of this file.
|
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) |
|
Extra functions for sds strings.
◆ 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
◆ sds_basename()
sds sds_basename |
( |
sds |
s | ) |
|
Replacement for basename function. Modifies the sds string in place.
- Parameters
-
s | sds 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
-
s | string to append the value |
v | bool 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
-
s | sds string |
c | char 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
-
s | sds string |
p | string to append json escaped |
len | length 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
-
s | sds string |
p | string to append json escaped |
len | length 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
-
s | sds string |
c | char to escape and append |
- Returns
- modified sds string
◆ sds_dirname()
Replacement for dirname function. Modifies the sds string in place.
- Parameters
-
s | sds 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
-
p | Void pointer to sds string |
◆ sds_hash_md5()
sds sds_hash_md5 |
( |
const char * |
p | ) |
|
Hashes a string with md5
- Parameters
-
- 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
-
- 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
-
- Returns
- pointer to s
◆ sds_hash_sha256()
sds sds_hash_sha256 |
( |
const char * |
p | ) |
|
Hashes a string with sha256
- Parameters
-
- 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
-
- 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
-
src | string to unescape |
slen | string length to unescape |
dst | pointer 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
-
value | mpd song struct |
buffer | already 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
-
s | sds string to replace |
p | replacement 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
-
s | sds string to replace |
p | replacement string |
len | replacement 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
-
s | string to split |
count | pointer 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
-
s | sds string to append the url decoded string |
p | string to url decode |
len | string length to url decode |
is_form_url_encoded | true 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
-
s | sds string to append the encoded string |
p | string to url encode |
len | string 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
-
s | sds string to modify in place |