95 |
96 |
96 memcpy(newstring.ptr, s.ptr, s.length); |
97 memcpy(newstring.ptr, s.ptr, s.length); |
97 |
98 |
98 return newstring; |
99 return newstring; |
99 } |
100 } |
|
101 |
|
102 |
|
103 // webserver extension |
|
104 sstr_t sstrtrim(sstr_t string) { |
|
105 sstr_t newstr = string; |
|
106 int nsoff = 0; |
|
107 int l = 1; |
|
108 for(int i=0;i<string.length;i++) { |
|
109 char c = string.ptr[i]; |
|
110 if(l) { |
|
111 /* leading whitespace */ |
|
112 if(c > 32) { |
|
113 l = 0; |
|
114 nsoff = i; |
|
115 newstr.ptr = &string.ptr[i]; |
|
116 newstr.length = string.length - nsoff; |
|
117 } |
|
118 } else { |
|
119 /* trailing whitespace */ |
|
120 if(c > 32) { |
|
121 newstr.length = (i - nsoff) + 1; |
|
122 } |
|
123 } |
|
124 } |
|
125 return newstr; |
|
126 } |
|
127 |
|
128 sstr_t sstrdub_mp(UcxMempool *mp, sstr_t s) { |
|
129 sstr_t newstring; |
|
130 newstring.ptr = ucx_mempool_malloc(mp, s.length + 1); |
|
131 newstring.length = s.length; |
|
132 newstring.ptr[newstring.length] = 0; |
|
133 |
|
134 memcpy(newstring.ptr, s.ptr, s.length); |
|
135 |
|
136 return newstring; |
|
137 } |