src/server/ucx/string.h

changeset 71
069c152f6272
parent 51
b28cf69f42e8
child 88
73b3485e96f1
equal deleted inserted replaced
70:4e6e812c1d97 71:069c152f6272
1 /* 1 /*
2 * File: sstring.h 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * Author: olaf
4 * 3 *
5 * Created on 17. Juni 2010, 13:26 4 * Copyright 2013 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
6 */ 27 */
7 28
8 #ifndef _SSTRING_H 29 #ifndef _SSTRING_H
9 #define _SSTRING_H 30 #define _SSTRING_H
10 31
32 #include "ucx.h"
33 #include "mempool.h"
34 #include "../public/nsapi.h"
11 #include <stddef.h> 35 #include <stddef.h>
12 36
13 #include "mempool.h"
14 #include "../util/pool.h"
15
16 /* use macros for literals only */ 37 /* use macros for literals only */
17 #define S(s) { s, sizeof(s)-1 } 38 #define S(s) { (char*)s, sizeof(s)-1 }
18 #define ST(s) sstrn(s, sizeof(s)-1) 39 #define ST(s) sstrn((char*)s, sizeof(s)-1)
19 40
20 #ifdef __cplusplus 41 #ifdef __cplusplus
21 extern "C" { 42 extern "C" {
22 #endif 43 #endif
23 44
29 /* 50 /*
30 * creates a new sstr_t from a null terminated string 51 * creates a new sstr_t from a null terminated string
31 * 52 *
32 * s null terminated string 53 * s null terminated string
33 */ 54 */
34 sstr_t sstr (char *s); 55 sstr_t sstr(char *s);
35 56
36 /* 57 /*
37 * creates a new sstr_t from a string and length 58 * creates a new sstr_t from a string and length
38 * 59 *
39 * s string 60 * s string
40 * n length of string 61 * n length of string
41 */ 62 */
42 sstr_t sstrn (char *s, size_t n); 63 sstr_t sstrn(char *s, size_t n);
43 64
44 65
45 /* 66 /*
46 * gets the length of n sstr_t strings 67 * gets the length of n sstr_t strings
47 * 68 *
48 * n number of strings 69 * n number of strings
49 * s string 70 * s string
50 * ... strings 71 * ... strings
51 */ 72 */
52 size_t sstrnlen (size_t n, sstr_t s, ...); 73 size_t sstrnlen(size_t n, sstr_t s, ...);
53 74
54 75
55 /* 76 /*
56 * concatenates n strings 77 * concatenates n strings
57 * 78 *
58 * n number of strings 79 * n number of strings
59 * s new string with enough memory allocated 80 * s new string with enough memory allocated
60 * ... strings 81 * ... strings
61 */ 82 */
62 sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...); 83 sstr_t sstrncat(size_t n, sstr_t s, sstr_t c1, ...);
63 84
64 85
65 /* 86 /*
66 * 87 *
67 */ 88 */
68 sstr_t sstrsubs (sstr_t s, size_t start); 89 sstr_t sstrsubs(sstr_t s, size_t start);
69 90
70 /* 91 /*
71 * 92 *
72 */ 93 */
73 sstr_t sstrsubsl (sstr_t s, size_t start, size_t length); 94 sstr_t sstrsubsl(sstr_t s, size_t start, size_t length);
74 95
75 /* 96 /*
76 * splits s into n parts 97 * splits s into n parts
77 * 98 *
78 * s the string to split 99 * s the string to split
92 113
93 int sstrcmp(sstr_t s1, sstr_t s2); 114 int sstrcmp(sstr_t s1, sstr_t s2);
94 115
95 sstr_t sstrdup(sstr_t s); 116 sstr_t sstrdup(sstr_t s);
96 117
118 sstr_t sstrtrim(sstr_t string);
119
97 // webserver extension 120 // webserver extension
98 int sstr_startswith(sstr_t string, sstr_t cmp); 121 int sstr_startswith(sstr_t string, sstr_t cmp);
99 sstr_t sstrtrim(sstr_t string);
100 sstr_t sstrdup_mp(UcxMempool *pool, sstr_t s); 122 sstr_t sstrdup_mp(UcxMempool *pool, sstr_t s);
101 sstr_t sstrdup_pool(pool_handle_t *pool, sstr_t s); 123 sstr_t sstrdup_pool(pool_handle_t *pool, sstr_t s);
102 124
103 #ifdef __cplusplus 125 #ifdef __cplusplus
104 } 126 }

mercurial