mongoose/src/str.h

49 lines
2.0 KiB
C
Raw Normal View History

2020-12-05 19:26:32 +08:00
#pragma once
2022-01-11 01:30:51 +08:00
#include "arch.h"
2020-12-05 19:26:32 +08:00
struct mg_str {
2021-09-15 14:43:48 +08:00
const char *ptr; // Pointer to string data
size_t len; // String len
2020-12-05 19:26:32 +08:00
};
#define MG_NULL_STR \
{ NULL, 0 }
#define MG_C_STR(a) \
{ (a), sizeof(a) - 1 }
// Using macro to avoid shadowing C++ struct constructor, see #1298
#define mg_str(s) mg_str_s(s)
2020-12-05 19:26:32 +08:00
struct mg_str mg_str(const char *s);
2020-12-07 11:47:37 +08:00
struct mg_str mg_str_n(const char *s, size_t n);
2020-12-05 19:26:32 +08:00
int mg_lower(const char *s);
int mg_ncasecmp(const char *s1, const char *s2, size_t len);
int mg_casecmp(const char *s1, const char *s2);
int mg_vcmp(const struct mg_str *s1, const char *s2);
int mg_vcasecmp(const struct mg_str *str1, const char *str2);
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
struct mg_str mg_strstrip(struct mg_str s);
struct mg_str mg_strdup(const struct mg_str s);
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
bool mg_match(struct mg_str str, struct mg_str pattern, struct mg_str *caps);
bool mg_globmatch(const char *pattern, size_t plen, const char *s, size_t n);
bool mg_commalist(struct mg_str *s, struct mg_str *k, struct mg_str *v);
2022-05-31 17:41:14 +08:00
bool mg_split(struct mg_str *s, struct mg_str *k, struct mg_str *v, char delim);
2022-06-10 16:38:36 +08:00
size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap);
2022-06-09 05:09:11 +08:00
size_t mg_snprintf(char *, size_t, const char *fmt, ...);
2022-02-10 19:56:55 +08:00
char *mg_hex(const void *buf, size_t len, char *dst);
void mg_unhex(const char *buf, size_t len, unsigned char *to);
unsigned long mg_unhexn(const char *s, size_t len);
2022-06-09 05:09:11 +08:00
size_t mg_asprintf(char **, size_t, const char *fmt, ...);
2022-02-11 01:11:03 +08:00
size_t mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap);
2022-06-10 16:38:36 +08:00
char *mg_mprintf(const char *fmt, ...);
char *mg_vmprintf(const char *fmt, va_list ap);
2022-02-10 19:56:55 +08:00
int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip);
int64_t mg_to64(struct mg_str str);
2022-04-12 17:20:43 +08:00
uint64_t mg_tou64(struct mg_str str);
size_t mg_lld(char *buf, int64_t val, bool is_signed, bool is_hex);
2022-06-09 19:39:48 +08:00
double mg_atod(const char *buf, int len, int *numlen);
2022-06-10 16:38:36 +08:00
size_t mg_dtoa(char *buf, size_t len, double d, int width);