BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

string.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_STRING_H__
20#define __PJ_STRING_H__
21
27#include <pj/types.h>
28#include <pj/compat/string.h>
29
31
80#define PJ_CHECK_TRUNC_STR(ret, str, len) \
81 if ((ret) >= (len) || (ret) < 0) pj_ansi_strcpy((str) + (len) - 3, "..")
82
91
100PJ_INLINE(const pj_str_t*) pj_cstr(pj_str_t *str, const char *s)
101{
102 str->ptr = (char*)s;
103 str->slen = s ? (pj_ssize_t)strlen(s) : 0;
104 return str;
105}
106
116PJ_INLINE(pj_str_t*) pj_strset( pj_str_t *str, char *ptr, pj_size_t length)
117{
118 str->ptr = ptr;
119 str->slen = (pj_ssize_t)length;
120 return str;
121}
122
133{
134 str->ptr = src;
135 str->slen = src ? (pj_ssize_t)strlen(src) : 0;
136 return str;
137}
138
148PJ_INLINE(pj_str_t*) pj_strset3( pj_str_t *str, char *begin, char *end )
149{
150 str->ptr = begin;
151 str->slen = (pj_ssize_t)(end-begin);
152 return str;
153}
154
164
174
183PJ_IDECL(pj_str_t*) pj_strcpy2(pj_str_t *dst, const char *src);
184
195 pj_ssize_t max);
196
209 pj_ssize_t max);
210
221 pj_str_t *dst,
222 const pj_str_t *src);
223
234 pj_str_t *dst,
235 const pj_str_t *src);
236
247 pj_str_t *dst,
248 const char *src);
249
260 pj_str_t *dst,
261 const char *src);
262
263
272PJ_IDECL(pj_str_t) pj_strdup3(pj_pool_t *pool, const char *src);
273
282{
283 return str->slen;
284}
285
293PJ_INLINE(const char*) pj_strbuf( const pj_str_t *str )
294{
295 return str->ptr;
296}
297
309PJ_IDECL(int) pj_strcmp( const pj_str_t *str1, const pj_str_t *str2);
310
322PJ_IDECL(int) pj_strcmp2( const pj_str_t *str1, const char *str2 );
323
336PJ_IDECL(int) pj_strncmp( const pj_str_t *str1, const pj_str_t *str2,
337 pj_size_t len);
338
351PJ_IDECL(int) pj_strncmp2( const pj_str_t *str1, const char *str2,
352 pj_size_t len);
353
365PJ_IDECL(int) pj_stricmp(const pj_str_t *str1, const pj_str_t *str2);
366
383#if defined(PJ_HAS_STRICMP_ALNUM) && PJ_HAS_STRICMP_ALNUM!=0
384PJ_IDECL(int) strnicmp_alnum(const char *str1, const char *str2,
385 int len);
386#else
387#define strnicmp_alnum pj_ansi_strnicmp
388#endif
389
405#if defined(PJ_HAS_STRICMP_ALNUM) && PJ_HAS_STRICMP_ALNUM!=0
406PJ_IDECL(int) pj_stricmp_alnum(const pj_str_t *str1, const pj_str_t *str2);
407#else
408#define pj_stricmp_alnum pj_stricmp
409#endif
410
422PJ_IDECL(int) pj_stricmp2( const pj_str_t *str1, const char *str2);
423
436PJ_IDECL(int) pj_strnicmp( const pj_str_t *str1, const pj_str_t *str2,
437 pj_size_t len);
438
451PJ_IDECL(int) pj_strnicmp2( const pj_str_t *str1, const char *str2,
452 pj_size_t len);
453
460PJ_IDECL(void) pj_strcat(pj_str_t *dst, const pj_str_t *src);
461
462
469PJ_IDECL(void) pj_strcat2(pj_str_t *dst, const char *src);
470
471
480PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr)
481{
482 if (str->slen == 0)
483 return NULL;
484 return (char*) memchr((char*)str->ptr, chr, str->slen);
485}
486
487
498PJ_DECL(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char);
499
500
511PJ_DECL(pj_ssize_t) pj_strspn2(const pj_str_t *str, const char *set_char);
512
513
524PJ_DECL(pj_ssize_t) pj_strcspn(const pj_str_t *str, const pj_str_t *set_char);
525
526
537PJ_DECL(pj_ssize_t) pj_strcspn2(const pj_str_t *str, const char *set_char);
538
539
553PJ_DECL(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim,
554 pj_str_t *tok, pj_size_t start_idx);
555
556
570PJ_DECL(pj_ssize_t) pj_strtok2(const pj_str_t *str, const char *delim,
571 pj_str_t *tok, pj_size_t start_idx);
572
573
584PJ_DECL(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr);
585
597PJ_DECL(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr);
598
606PJ_DECL(pj_str_t*) pj_strltrim( pj_str_t *str );
607
615PJ_DECL(pj_str_t*) pj_strrtrim( pj_str_t *str );
616
625
635PJ_DECL(char*) pj_create_random_string(char *str, pj_size_t length);
636
646PJ_DECL(long) pj_strtol(const pj_str_t *str);
647
668PJ_DECL(pj_status_t) pj_strtol2(const pj_str_t *str, long *value);
669
670
680PJ_DECL(unsigned long) pj_strtoul(const pj_str_t *str);
681
696PJ_DECL(unsigned long) pj_strtoul2(const pj_str_t *str, pj_str_t *endptr,
697 unsigned base);
698
717PJ_DECL(pj_status_t) pj_strtoul3(const pj_str_t *str, unsigned long *value,
718 unsigned base);
719
727PJ_DECL(float) pj_strtof(const pj_str_t *str);
728
738PJ_DECL(int) pj_utoa(unsigned long val, char *buf);
739
753PJ_DECL(int) pj_utoa_pad( unsigned long val, char *buf, int min_dig, int pad);
754
755
762PJ_INLINE(void) pj_bzero(void *dst, pj_size_t size)
763{
764#if defined(PJ_HAS_BZERO) && PJ_HAS_BZERO!=0
765 bzero(dst, size);
766#else
767 memset(dst, 0, size);
768#endif
769}
770
771
781PJ_INLINE(void*) pj_memset(void *dst, int c, pj_size_t size)
782{
783 return memset(dst, c, size);
784}
785
795PJ_INLINE(void*) pj_memcpy(void *dst, const void *src, pj_size_t size)
796{
797 return memcpy(dst, src, size);
798}
799
809PJ_INLINE(void*) pj_memmove(void *dst, const void *src, pj_size_t size)
810{
811 return memmove(dst, src, size);
812}
813
823PJ_INLINE(int) pj_memcmp(const void *buf1, const void *buf2, pj_size_t size)
824{
825 return memcmp(buf1, buf2, size);
826}
827
838PJ_INLINE(void*) pj_memchr(const void *buf, int c, pj_size_t size)
839{
840 return (void*)memchr((void*)buf, c, size);
841}
842
847#if PJ_FUNCTIONS_ARE_INLINED
848# include <pj/string_i.h>
849#endif
850
852
853#endif /* __PJ_STRING_H__ */
854
long pj_ssize_t
Definition: types.h:64
size_t pj_size_t
Definition: types.h:58
int pj_status_t
Definition: types.h:68
pj_ssize_t pj_strcspn(const pj_str_t *str, const pj_str_t *set_char)
pj_str_t * pj_strrtrim(pj_str_t *str)
pj_ssize_t pj_strspn2(const pj_str_t *str, const char *set_char)
unsigned long pj_strtoul(const pj_str_t *str)
void * pj_memcpy(void *dst, const void *src, pj_size_t size)
Definition: string.h:795
void pj_strcat2(pj_str_t *dst, const char *src)
pj_str_t * pj_strassign(pj_str_t *dst, pj_str_t *src)
pj_ssize_t pj_strtok2(const pj_str_t *str, const char *delim, pj_str_t *tok, pj_size_t start_idx)
const char * pj_strbuf(const pj_str_t *str)
Definition: string.h:293
pj_str_t pj_str(char *str)
pj_str_t * pj_strset3(pj_str_t *str, char *begin, char *end)
Definition: string.h:148
pj_str_t * pj_strdup2(pj_pool_t *pool, pj_str_t *dst, const char *src)
int pj_strnicmp(const pj_str_t *str1, const pj_str_t *str2, pj_size_t len)
int pj_strcmp2(const pj_str_t *str1, const char *str2)
int pj_utoa_pad(unsigned long val, char *buf, int min_dig, int pad)
pj_str_t * pj_strset(pj_str_t *str, char *ptr, pj_size_t length)
Definition: string.h:116
void * pj_memmove(void *dst, const void *src, pj_size_t size)
Definition: string.h:809
int pj_stricmp2(const pj_str_t *str1, const char *str2)
int pj_strcmp(const pj_str_t *str1, const pj_str_t *str2)
pj_str_t * pj_strncpy_with_null(pj_str_t *dst, const pj_str_t *src, pj_ssize_t max)
int pj_strncmp2(const pj_str_t *str1, const char *str2, pj_size_t len)
char * pj_stristr(const pj_str_t *str, const pj_str_t *substr)
pj_str_t * pj_strncpy(pj_str_t *dst, const pj_str_t *src, pj_ssize_t max)
int pj_utoa(unsigned long val, char *buf)
void * pj_memchr(const void *buf, int c, pj_size_t size)
Definition: string.h:838
void pj_strcat(pj_str_t *dst, const pj_str_t *src)
int pj_strnicmp2(const pj_str_t *str1, const char *str2, pj_size_t len)
pj_str_t * pj_strdup_with_null(pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src)
int pj_memcmp(const void *buf1, const void *buf2, pj_size_t size)
Definition: string.h:823
char * pj_strstr(const pj_str_t *str, const pj_str_t *substr)
pj_str_t * pj_strcpy(pj_str_t *dst, const pj_str_t *src)
unsigned long pj_strtoul2(const pj_str_t *str, pj_str_t *endptr, unsigned base)
#define strnicmp_alnum
Definition: string.h:387
pj_str_t * pj_strcpy2(pj_str_t *dst, const char *src)
pj_str_t * pj_strtrim(pj_str_t *str)
char * pj_create_random_string(char *str, pj_size_t length)
pj_status_t pj_strtol2(const pj_str_t *str, long *value)
pj_status_t pj_strtoul3(const pj_str_t *str, unsigned long *value, unsigned base)
#define pj_stricmp_alnum
Definition: string.h:408
int pj_strncmp(const pj_str_t *str1, const pj_str_t *str2, pj_size_t len)
pj_size_t pj_strlen(const pj_str_t *str)
Definition: string.h:281
long pj_strtol(const pj_str_t *str)
pj_str_t * pj_strdup2_with_null(pj_pool_t *pool, pj_str_t *dst, const char *src)
const pj_str_t * pj_cstr(pj_str_t *str, const char *s)
Definition: string.h:100
pj_str_t pj_strdup3(pj_pool_t *pool, const char *src)
int pj_stricmp(const pj_str_t *str1, const pj_str_t *str2)
pj_ssize_t pj_strspn(const pj_str_t *str, const pj_str_t *set_char)
pj_str_t * pj_strset2(pj_str_t *str, char *src)
Definition: string.h:132
float pj_strtof(const pj_str_t *str)
char * pj_strchr(const pj_str_t *str, int chr)
Definition: string.h:480
pj_str_t * pj_strdup(pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src)
pj_ssize_t pj_strcspn2(const pj_str_t *str, const char *set_char)
pj_str_t * pj_strltrim(pj_str_t *str)
void * pj_memset(void *dst, int c, pj_size_t size)
Definition: string.h:781
void pj_bzero(void *dst, pj_size_t size)
Definition: string.h:762
pj_ssize_t pj_strtok(const pj_str_t *str, const pj_str_t *delim, pj_str_t *tok, pj_size_t start_idx)
#define PJ_BEGIN_DECL
Definition: config.h:1284
#define PJ_IDECL(type)
Definition: config.h:1333
#define PJ_INLINE(type)
Definition: config.h:1178
#define PJ_END_DECL
Definition: config.h:1285
Definition: pool.h:310
Definition: types.h:120
pj_ssize_t slen
Definition: types.h:125
char * ptr
Definition: types.h:122
Declaration of basic types and utility.

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.