Github Repo | C Header | C source | JS source |
---|---|---|---|
cesanta/mongoose-os | mg_str.h | mg_str.c |
struct mg_str mg_mk_str(const char *s);
Helper function for creating mg_str struct from plain C string.
NULL
is allowed and becomes{NULL, 0}
.
struct mg_str mg_mk_str_n(const char *s, size_t len);
Like
mg_mk_str
, but takes string length explicitly.
#define MG_MK_STR(str_literal) \
{ str_literal, sizeof(str_literal) - 1 }
#define MG_MK_STR_N(str_literal, len) \
{ str_literal, len }
#define MG_NULL_STR \
{ NULL, 0 }
Macro for initializing mg_str.
int mg_vcmp(const struct mg_str *str2, const char *str1);
Cross-platform version of
strcmp()
where where first string is specified bystruct mg_str
.
int mg_vcasecmp(const struct mg_str *str2, const char *str1);
Cross-platform version of
strncasecmp()
where first string is specified bystruct mg_str
.
struct mg_str mg_strdup(const struct mg_str s);
Creates a copy of s (heap-allocated).
struct mg_str mg_strdup_nul(const struct mg_str s);
Creates a copy of s (heap-allocated). Resulting string is NUL-terminated (but NUL is not included in len).
const char *mg_strchr(const struct mg_str s, int c);
Locates character in a string.
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
Compare two
mg_str
s; return value is the same asstrcmp
.
int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
Like
mg_strcmp
, but compares at mostn
characters.
int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2);
Compare two
mg_str
s ignoreing case; return value is the same asstrcmp
.
void mg_strfree(struct mg_str *s);
Free the string (assuming it was heap allocated).
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
Finds the first occurrence of a substring
needle
in thehaystack
.
struct mg_str mg_strstrip(struct mg_str s);
Strip whitespace at the start and the end of s
int mg_str_starts_with(struct mg_str s, struct mg_str prefix);
edit this docReturns 1 if s starts with the given prefix.