lsquic_str.h revision 50aadb33
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov/* 350aadb33SDmitri Tikhonov * lsquic_str.h -- Some string routines. 450aadb33SDmitri Tikhonov */ 550aadb33SDmitri Tikhonov 650aadb33SDmitri Tikhonov#ifndef LSQUIC_STR_H 750aadb33SDmitri Tikhonov#define LSQUIC_STR_H 1 850aadb33SDmitri Tikhonov 950aadb33SDmitri Tikhonovstruct lsquic_str 1050aadb33SDmitri Tikhonov{ 1150aadb33SDmitri Tikhonov char *str; 1250aadb33SDmitri Tikhonov size_t len; 1350aadb33SDmitri Tikhonov}; 1450aadb33SDmitri Tikhonov 1550aadb33SDmitri Tikhonov 1650aadb33SDmitri Tikhonovtypedef struct lsquic_str lsquic_str_t; 1750aadb33SDmitri Tikhonov 1850aadb33SDmitri Tikhonov 1950aadb33SDmitri Tikhonovlsquic_str_t * 2050aadb33SDmitri Tikhonovlsquic_str_new (const char *, size_t); 2150aadb33SDmitri Tikhonov 2250aadb33SDmitri Tikhonov#define lsquic_str_len(lstr) (+(lstr)->len) 2350aadb33SDmitri Tikhonov 2450aadb33SDmitri Tikhonov#define lsquic_str_setlen(lstr, len_) do { \ 2550aadb33SDmitri Tikhonov (lstr)->len = len_; \ 2650aadb33SDmitri Tikhonov} while (0) 2750aadb33SDmitri Tikhonov 2850aadb33SDmitri Tikhonovvoid 2950aadb33SDmitri Tikhonovlsquic_str_setto (lsquic_str_t *, const void *, size_t); 3050aadb33SDmitri Tikhonov 3150aadb33SDmitri Tikhonovvoid 3250aadb33SDmitri Tikhonovlsquic_str_append (lsquic_str_t *, const char *, size_t); 3350aadb33SDmitri Tikhonov 3450aadb33SDmitri Tikhonovvoid 3550aadb33SDmitri Tikhonovlsquic_str_d (lsquic_str_t *); 3650aadb33SDmitri Tikhonov 3750aadb33SDmitri Tikhonovvoid 3850aadb33SDmitri Tikhonovlsquic_str_delete (lsquic_str_t *); 3950aadb33SDmitri Tikhonov 4050aadb33SDmitri Tikhonovchar * 4150aadb33SDmitri Tikhonovlsquic_str_prealloc (lsquic_str_t *, size_t); 4250aadb33SDmitri Tikhonov 4350aadb33SDmitri Tikhonov#define lsquic_str_buf(lstr) ((char *) (lstr)->str) 4450aadb33SDmitri Tikhonov 4550aadb33SDmitri Tikhonov#define lsquic_str_cstr(lstr) ((const char *) (lstr)->str) 4650aadb33SDmitri Tikhonov 4750aadb33SDmitri Tikhonov#define lsquic_str_blank(lstr) do { \ 4850aadb33SDmitri Tikhonov (lstr)->str = NULL; \ 4950aadb33SDmitri Tikhonov (lstr)->len = 0; \ 5050aadb33SDmitri Tikhonov} while (0) 5150aadb33SDmitri Tikhonov 5250aadb33SDmitri Tikhonovint 5350aadb33SDmitri Tikhonovlsquic_str_bcmp (const void *, const void *); 5450aadb33SDmitri Tikhonov 5550aadb33SDmitri Tikhonovlsquic_str_t * 5650aadb33SDmitri Tikhonovlsquic_str_copy (lsquic_str_t *, const lsquic_str_t *); 5750aadb33SDmitri Tikhonov 5850aadb33SDmitri Tikhonov#define lsquic_str_set(lstr, src, len_) do { \ 5950aadb33SDmitri Tikhonov (lstr)->str = src; \ 6050aadb33SDmitri Tikhonov (lstr)->len = len_; \ 6150aadb33SDmitri Tikhonov} while (0) 6250aadb33SDmitri Tikhonov 6350aadb33SDmitri Tikhonov#endif 64