picox  0.1
xstring.h
[詳解]
1 
14 /*
15  * License: MIT license
16  * Copyright (c) <2016> <MaskedW [maskedw00@gmail.com]>
17  *
18  * Permission is hereby granted, free of charge, to any person
19  * obtaining a copy of this software and associated documentation
20  * files (the "Software"), to deal in the Software without
21  * restriction, including without limitation the rights to use, copy,
22  * modify, merge, publish, distribute, sublicense, and/or sell copies
23  * of the Software, and to permit persons to whom the Software is
24  * furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be
27  * included in all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36  * SOFTWARE.
37  */
38 
39 
40 #ifndef picox_core_detail_xstring_h_
41 #define picox_core_detail_xstring_h_
42 
43 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 
66 bool x_strequal(const char* s1, const char* s2);
67 
68 
71 bool x_strcaseequal(const char* s1, const char* s2);
72 
73 
78 int x_strcasecmp(const char* s1, const char* s2);
79 
80 
85 int x_strncasecmp(const char* s1, const char* s2, size_t n);
86 
87 
92 char* x_strnstr(const char* s1, const char* s2, size_t n);
93 
94 
99 char* x_strcasestr(const char* s1, const char* s2);
100 
101 
106 char* x_strncasestr(const char* s1, const char* s2, size_t n);
107 
108 
115 char* x_strdup(const char* str);
116 
117 
123 char* x_strdup2(const char* str, XMallocFunc malloc_func);
124 
125 
130 char* x_strndup(const char* str, size_t n);
131 
132 
139 char* x_strndup2(const char* str, size_t n, XMallocFunc malloc_func);
140 
141 
146 char* x_strreverse(char* str);
147 
148 
154 char* x_strstrip(char* str, const char* space);
155 
156 
162 char* x_strlstrip(char* str, const char* space);
163 
164 
170 char* x_strrstrip(char* str, const char* space);
171 
172 
185 int32_t x_strtoint32(const char* str, int32_t def, bool* ok);
186 
187 
193 uint32_t x_strtouint32(const char* str, uint32_t def, bool* ok);
194 
195 
200 float x_strtofloat(const char* str, float def, bool* ok);
201 
202 
207 double x_strtodouble(const char* str, double def, bool* ok);
208 
209 
215 bool x_strtobool(const char* str, bool def, bool* ok);
216 
217 
220 char* x_strrpbrk(const char* str, const char* accept);
221 
222 
225 char* x_strcasepbrk(const char* str, const char* accept);
226 
227 
230 char* x_strcaserpbrk(const char* str, const char* accept);
231 
232 
237 char* x_strtolower(char* str);
238 
239 
244 char* x_strtoupper(char* str);
245 
246 
261 size_t x_strlcpy(char* dst, const char* src, size_t n);
262 
263 
279 size_t x_strlcat(char* dst, const char* src, size_t dsize);
280 
281 
284 size_t x_strcountequal(const char* a, const char* b);
285 
286 
289 size_t x_strcountcaseequal(const char* a, const char* b);
290 
291 
299 char* x_stpcpy(char* dst, const char* src);
300 
301 
304 char* x_stprcpy(char* dst, const char* src);
305 
306 
311 char* x_stpncpy(char* dst, const char* src, size_t n);
312 
313 
319 char* x_stpncpy2(char* dst, const char* src, size_t n);
320 
321 
329 char* x_strncpy2(char* dst, const char* src, size_t n);
330 
331 
339 char* x_strchrnul(const char* s, int c);
340 
341 
344 size_t x_strnlen(const char* s, size_t n);
345 
346 
349 XOpenMode x_strtomode(const char* modestr);
350 
351 
354 char* x_strskipchr(const char* s, int c);
355 
356 
361 void* x_memmem(const void* p1, size_t n1, const void* p2, size_t n2);
362 
363 
368 void* x_memrchr(const void* p, int c, size_t n);
369 
370 
373 void x_memswap(void *a, void *b, size_t size);
374 
375 
378 void x_memreverse(void *p, size_t size, size_t n);
379 
380 
383 void x_memrrot(void *p, size_t shift, size_t size, size_t n);
384 
385 
388 void x_memlrot(void *p, size_t shift, size_t size, size_t n);
389 
390 
403 void x_memblt(void* dst, const void* src,
404  size_t width, size_t height,
405  size_t dstride, size_t sstride);
406 
407 
410 bool x_memequal(const void* p1, const void* p2, size_t n);
411 
412 
424 char* x_strreplace(char* dst, size_t size, size_t len, size_t dn, const char* src, size_t sn);
425 
426 
429 void x_memrandom(void* p, size_t n);
430 
431 
434 void x_memrandom_alpha(void* p, size_t n);
435 
436 
439 static inline const char* x_btos(bool cond)
440 {
441  return cond ? "true" : "false";
442 }
443 
444 
445 #ifdef __cplusplus
446 }
447 #endif
448 
449 
454 #endif /* picox_core_detail_xstring_h_ */
uint32_t x_strtouint32(const char *str, uint32_t def, bool *ok)
文字列をuint32_tに変換して返します。
Definition: xstring.c:254
void * x_memrchr(const void *p, int c, size_t n)
memchr()の逆走査版です
Definition: xstring.c:545
XOpenMode
ファイルオープン等のモードです
Definition: xstddef.h:435
char * x_strskipchr(const char *s, int c)
文字列sの先頭にcが続く間読み飛ばし、そのポインタを返します
Definition: xstring.c:750
char * x_strreplace(char *dst, size_t size, size_t len, size_t dn, const char *src, size_t sn)
sizeバイトの領域を持つ長さlenのdstの先頭からdnバイトをsnバイトのsrcで上書きします ...
Definition: xstring.c:758
char * x_strrstrip(char *str, const char *space)
文字列の後ろからspaceに含まれる文字列を取り除いた結果を返します。
Definition: xstring.c:233
char * x_strlstrip(char *str, const char *space)
文字列の前からspaceに含まれる文字列を取り除いた結果を返します。
Definition: xstring.c:225
char * x_strcasepbrk(const char *str, const char *accept)
大文字小文字の違いを無視したstrpbrk()です。
Definition: xstring.c:361
void x_memrandom(void *p, size_t n)
nバイトの領域を持つpをランダムな値で埋めます
Definition: xstring.c:782
float x_strtofloat(const char *str, float def, bool *ok)
文字列をfloatに変換して返します。
Definition: xstring.c:267
void *(* XMallocFunc)(size_t size)
malloc()互換のメモリ確保関数ポインタ型です
Definition: xstddef.h:300
void x_memswap(void *a, void *b, size_t size)
aとbからsizeバイトを入れ替えます。
Definition: xstring.c:562
size_t x_strcountequal(const char *a, const char *b)
a,bを比較し、一致するバイト数を返します
Definition: xstring.c:492
void x_memrandom_alpha(void *p, size_t n)
nバイトの領域を持つpをランダムなアルファベット[a-zA-Z]で埋めます
Definition: xstring.c:792
char * x_strncasestr(const char *s1, const char *s2, size_t n)
大文字小文字の違いを無視したx_strnstr()です
Definition: xstring.c:110
char * x_stpncpy(char *dst, const char *src, size_t n)
長さ制限付きのx_stpcpy()です
Definition: xstring.c:654
char * x_strndup2(const char *str, size_t n, XMallocFunc malloc_func)
メモリ確保関数と最大バイト数を指定して複製した文字列を返します
Definition: xstring.c:180
char * x_strdup2(const char *str, XMallocFunc malloc_func)
指定のメモリ確保関数を使用して複製した文字列を返します
Definition: xstring.c:168
void x_memblt(void *dst, const void *src, size_t width, size_t height, size_t dstride, size_t sstride)
srcからdstにメモリの矩形コピーを行います。
Definition: xstring.c:604
char * x_strreverse(char *str)
文字列を逆転させた結果を返します。
Definition: xstring.c:196
void * x_memmem(const void *p1, size_t n1, const void *p2, size_t n2)
n1バイトの大きさを持つp1からn2バイトのp2が最初に現れた位置のポインタを返します
Definition: xstring.c:520
char * x_strcaserpbrk(const char *str, const char *accept)
大文字小文字の違いを無視したx_strrpbrk()です。
Definition: xstring.c:392
bool x_memequal(const void *p1, const void *p2, size_t n)
(memcmp(p1, p2) == 0)と同じです
Definition: xstring.c:621
char * x_stpcpy(char *dst, const char *src)
srcをdstにコピーし、コピーした文字列の終端のポインタを返します
Definition: xstring.c:627
char * x_stprcpy(char *dst, const char *src)
dstにsrcを逆順でコピーし、コピーした文字列の終端のポインタを返します
Definition: xstring.c:634
size_t x_strlcat(char *dst, const char *src, size_t dsize)
srcから最大でdsize - strlen(dst) - 1バイトの文字列をdstに連結します
Definition: xstring.c:463
size_t x_strcountcaseequal(const char *a, const char *b)
大文字小文字の違いを無視したx_strcountequal()です。
Definition: xstring.c:506
char * x_strnstr(const char *s1, const char *s2, size_t n)
長さ制限付きのstrstr()です
Definition: xstring.c:86
int x_strcasecmp(const char *s1, const char *s2)
大文字小文字の違いを無視したstrcmp()です。
Definition: xstring.c:61
char * x_strdup(const char *str)
文字列の複製をヒープから生成して返します
Definition: xstring.c:162
static const char * x_btos(bool cond)
真偽値に対応する"true" or "false"の文字列を返します
Definition: xstring.h:439
bool x_strcaseequal(const char *s1, const char *s2)
大文字小文字の違いを無視したx_strequal()です
Definition: xstring.c:55
char * x_strrpbrk(const char *str, const char *accept)
strpbrk()の逆走査版です。
Definition: xstring.c:330
char * x_strcasestr(const char *s1, const char *s2)
大文字小文字の違いを無視したstrstr()です。
Definition: xstring.c:136
size_t x_strnlen(const char *s, size_t n)
長さ指定付きのstrlen()です
Definition: xstring.c:706
void x_memreverse(void *p, size_t size, size_t n)
sizeバイトの要素n個からなる配列pの要素を逆順に並べ替えます。
Definition: xstring.c:576
char * x_strstrip(char *str, const char *space)
文字列の前後からspaceに含まれる文字列を取り除いた結果を返します。
Definition: xstring.c:211
void x_memrrot(void *p, size_t shift, size_t size, size_t n)
sizeバイトの要素n個からなる配列pの要素を右方向にshift個分回転移動させます。
Definition: xstring.c:588
char * x_strtoupper(char *str)
strに含まれるアルファベットを全て大文字に変換して返します
Definition: xstring.c:436
int32_t x_strtoint32(const char *str, int32_t def, bool *ok)
文字列をint32_tに変換して返します。
Definition: xstring.c:241
char * x_strncpy2(char *dst, const char *src, size_t n)
0埋め無し版のx_strncpy()です
Definition: xstring.c:685
char * x_strchrnul(const char *s, int c)
文字列s中にはじめに文字cが現れた位置へのポインタを返します
Definition: xstring.c:693
char * x_strndup(const char *str, size_t n)
複製する最大バイト数を指定できるstrdup()です
Definition: xstring.c:174
bool x_strtobool(const char *str, bool def, bool *ok)
文字列をboolに変換して返します。
Definition: xstring.c:301
void x_memlrot(void *p, size_t shift, size_t size, size_t n)
sizeバイトの要素n個からなる配列pの要素を左方向にshift個分回転移動させます。
Definition: xstring.c:596
bool x_strequal(const char *s1, const char *s2)
文字列s1とs2が一致するかどうかを返します。
Definition: xstring.c:49
char * x_stpncpy2(char *dst, const char *src, size_t n)
0埋め無し版のx_stpncpy()です
Definition: xstring.c:672
double x_strtodouble(const char *str, double def, bool *ok)
文字列をdoubleに変換して返します。
Definition: xstring.c:287
int x_strncasecmp(const char *s1, const char *s2, size_t n)
大文字小文字の違いを無視したstrncmp()です。
Definition: xstring.c:70
XOpenMode x_strtomode(const char *modestr)
"r", "r+"等のfopen()で使用するモード指定文字列をXOpenModeに変換して返します
Definition: xstring.c:719
char * x_strtolower(char *str)
strに含まれるアルファベットを全て小文字に変換して返します
Definition: xstring.c:423
size_t x_strlcpy(char *dst, const char *src, size_t n)
srcから最大でn - 1バイトをdstにコピーします
Definition: xstring.c:449