lsquic_str.h revision a74702c6
1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_str.h -- Some string routines. 4 */ 5 6#ifndef LSQUIC_STR_H 7#define LSQUIC_STR_H 1 8 9struct lsquic_str 10{ 11 char *str; 12 size_t len; 13}; 14 15 16typedef struct lsquic_str lsquic_str_t; 17 18 19lsquic_str_t * 20lsquic_str_new (const char *, size_t); 21 22#define lsquic_str_len(lstr) (+(lstr)->len) 23 24#define lsquic_str_setlen(lstr, len_) do { \ 25 (lstr)->len = len_; \ 26} while (0) 27 28void 29lsquic_str_setto (lsquic_str_t *, const void *, size_t); 30 31int 32lsquic_str_append (lsquic_str_t *, const char *, size_t); 33 34void 35lsquic_str_d (lsquic_str_t *); 36 37void 38lsquic_str_delete (lsquic_str_t *); 39 40char * 41lsquic_str_prealloc (lsquic_str_t *, size_t); 42 43#define lsquic_str_buf(lstr) ((char *) (lstr)->str) 44 45#define lsquic_str_cstr(lstr) ((const char *) (lstr)->str) 46 47#define lsquic_str_blank(lstr) do { \ 48 (lstr)->str = NULL; \ 49 (lstr)->len = 0; \ 50} while (0) 51 52int 53lsquic_str_bcmp (const void *, const void *); 54 55lsquic_str_t * 56lsquic_str_copy (lsquic_str_t *, const lsquic_str_t *); 57 58#define lsquic_str_set(lstr, src, len_) do { \ 59 (lstr)->str = src; \ 60 (lstr)->len = len_; \ 61} while (0) 62 63#endif 64