1 /* $Id$ */
2 /*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 #ifndef __PJ_STRING_H__
21 #define __PJ_STRING_H__
22
23 /**
24 * @file string.h
25 * @brief PJLIB String Operations.
26 */
27
28 #include <pj/types.h>
29 #include <pj/compat/string.h>
30
31 PJ_BEGIN_DECL
32
33 /**
34 * @defgroup PJ_PSTR String Operations
35 * @ingroup PJ_DS
36 * @{
37 * This module provides string manipulation API.
38 *
39 * \section pj_pstr_not_null_sec PJLIB String is NOT Null Terminated!
40 *
41 * That is the first information that developers need to know. Instead
42 * of using normal C string, strings in PJLIB are represented as
43 * pj_str_t structure below:
44 *
45 * <pre>
46 * typedef struct pj_str_t
47 * {
48 * char *ptr;
49 * pj_size_t slen;
50 * } pj_str_t;
51 * </pre>
52 *
53 * There are some advantages of using this approach:
54 * - the string can point to arbitrary location in memory even
55 * if the string in that location is not null terminated. This is
56 * most usefull for text parsing, where the parsed text can just
57 * point to the original text in the input. If we use C string,
58 * then we will have to copy the text portion from the input
59 * to a string variable.
60 * - because the length of the string is known, string copy operation
61 * can be made more efficient.
62 *
63 * Most of APIs in PJLIB that expect or return string will represent
64 * the string as pj_str_t instead of normal C string.
65 *
66 * \section pj_pstr_examples_sec Examples
67 *
68 * For some examples, please see:
69 * - @ref page_pjlib_string_test
70 */
71
72 /**
73 * Check if a string is truncated and if yes, put a suffix of ".."
74 * to indicate the truncation.
75 * This macro is used to check the result of pj_ansi_snprintf().
76 *
77 * @param ret The return value of pj_ansi_snprintf().
78 * @param str The string.
79 * @param len The length of the string buffer.
80 */
81 #define PJ_CHECK_TRUNC_STR(ret, str, len) \
82 if ((ret) >= (len) || (ret) < 0) pj_ansi_strcpy((str) + (len) - 3, "..")
83
84 /**
85 * Create string initializer from a normal C string.
86 *
87 * @param str Null terminated string to be stored.
88 *
89 * @return pj_str_t.
90 */
91 PJ_IDECL(pj_str_t) pj_str(char *str);
92
93 /**
94 * Create constant string from normal C string.
95 *
96 * @param str The string to be initialized.
97 * @param s Null terminated string.
98 *
99 * @return pj_str_t.
100 */
pj_cstr(pj_str_t * str,const char * s)101 PJ_INLINE(const pj_str_t*) pj_cstr(pj_str_t *str, const char *s)
102 {
103 str->ptr = (char*)s;
104 str->slen = s ? (pj_ssize_t)strlen(s) : 0;
105 return str;
106 }
107
108 /**
109 * Set the pointer and length to the specified value.
110 *
111 * @param str the string.
112 * @param ptr pointer to set.
113 * @param length length to set.
114 *
115 * @return the string.
116 */
pj_strset(pj_str_t * str,char * ptr,pj_size_t length)117 PJ_INLINE(pj_str_t*) pj_strset( pj_str_t *str, char *ptr, pj_size_t length)
118 {
119 str->ptr = ptr;
120 str->slen = (pj_ssize_t)length;
121 return str;
122 }
123
124 /**
125 * Set the pointer and length of the string to the source string, which
126 * must be NULL terminated.
127 *
128 * @param str the string.
129 * @param src pointer to set.
130 *
131 * @return the string.
132 */
pj_strset2(pj_str_t * str,char * src)133 PJ_INLINE(pj_str_t*) pj_strset2( pj_str_t *str, char *src)
134 {
135 str->ptr = src;
136 str->slen = src ? (pj_ssize_t)strlen(src) : 0;
137 return str;
138 }
139
140 /**
141 * Set the pointer and the length of the string.
142 *
143 * @param str The target string.
144 * @param begin The start of the string.
145 * @param end The end of the string.
146 *
147 * @return the target string.
148 */
pj_strset3(pj_str_t * str,char * begin,char * end)149 PJ_INLINE(pj_str_t*) pj_strset3( pj_str_t *str, char *begin, char *end )
150 {
151 str->ptr = begin;
152 str->slen = (pj_ssize_t)(end-begin);
153 return str;
154 }
155
156 /**
157 * Assign string.
158 *
159 * @param dst The target string.
160 * @param src The source string.
161 *
162 * @return the target string.
163 */
164 PJ_IDECL(pj_str_t*) pj_strassign( pj_str_t *dst, pj_str_t *src );
165
166 /**
167 * Copy string contents.
168 *
169 * @param dst The target string.
170 * @param src The source string.
171 *
172 * @return the target string.
173 */
174 PJ_IDECL(pj_str_t*) pj_strcpy(pj_str_t *dst, const pj_str_t *src);
175
176 /**
177 * Copy string contents.
178 *
179 * @param dst The target string.
180 * @param src The source string.
181 *
182 * @return the target string.
183 */
184 PJ_IDECL(pj_str_t*) pj_strcpy2(pj_str_t *dst, const char *src);
185
186 /**
187 * Copy source string to destination up to the specified max length.
188 *
189 * @param dst The target string.
190 * @param src The source string.
191 * @param max Maximum characters to copy.
192 *
193 * @return the target string.
194 */
195 PJ_IDECL(pj_str_t*) pj_strncpy(pj_str_t *dst, const pj_str_t *src,
196 pj_ssize_t max);
197
198 /**
199 * Copy source string to destination up to the specified max length,
200 * and NULL terminate the destination. If source string length is
201 * greater than or equal to max, then max-1 will be copied.
202 *
203 * @param dst The target string.
204 * @param src The source string.
205 * @param max Maximum characters to copy.
206 *
207 * @return the target string.
208 */
209 PJ_IDECL(pj_str_t*) pj_strncpy_with_null(pj_str_t *dst, const pj_str_t *src,
210 pj_ssize_t max);
211
212 /**
213 * Duplicate string.
214 *
215 * @param pool The pool.
216 * @param dst The string result.
217 * @param src The string to duplicate.
218 *
219 * @return the string result.
220 */
221 PJ_IDECL(pj_str_t*) pj_strdup(pj_pool_t *pool,
222 pj_str_t *dst,
223 const pj_str_t *src);
224
225 /**
226 * Duplicate string and NULL terminate the destination string.
227 *
228 * @param pool The pool.
229 * @param dst The string result.
230 * @param src The string to duplicate.
231 *
232 * @return The string result.
233 */
234 PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool,
235 pj_str_t *dst,
236 const pj_str_t *src);
237
238 /**
239 * Duplicate string.
240 *
241 * @param pool The pool.
242 * @param dst The string result.
243 * @param src The string to duplicate.
244 *
245 * @return the string result.
246 */
247 PJ_IDECL(pj_str_t*) pj_strdup2(pj_pool_t *pool,
248 pj_str_t *dst,
249 const char *src);
250
251 /**
252 * Duplicate string and NULL terminate the destination string.
253 *
254 * @param pool The pool.
255 * @param dst The string result.
256 * @param src The string to duplicate.
257 *
258 * @return The string result.
259 */
260 PJ_IDECL(pj_str_t*) pj_strdup2_with_null(pj_pool_t *pool,
261 pj_str_t *dst,
262 const char *src);
263
264
265 /**
266 * Duplicate string.
267 *
268 * @param pool The pool.
269 * @param src The string to duplicate.
270 *
271 * @return the string result.
272 */
273 PJ_IDECL(pj_str_t) pj_strdup3(pj_pool_t *pool, const char *src);
274
275 /**
276 * Return the length of the string.
277 *
278 * @param str The string.
279 *
280 * @return the length of the string.
281 */
pj_strlen(const pj_str_t * str)282 PJ_INLINE(pj_size_t) pj_strlen( const pj_str_t *str )
283 {
284 return str->slen;
285 }
286
287 /**
288 * Return the pointer to the string data.
289 *
290 * @param str The string.
291 *
292 * @return the pointer to the string buffer.
293 */
pj_strbuf(const pj_str_t * str)294 PJ_INLINE(const char*) pj_strbuf( const pj_str_t *str )
295 {
296 return str->ptr;
297 }
298
299 /**
300 * Compare strings.
301 *
302 * @param str1 The string to compare.
303 * @param str2 The string to compare.
304 *
305 * @return
306 * - < 0 if str1 is less than str2
307 * - 0 if str1 is identical to str2
308 * - > 0 if str1 is greater than str2
309 */
310 PJ_IDECL(int) pj_strcmp( const pj_str_t *str1, const pj_str_t *str2);
311
312 /**
313 * Compare strings.
314 *
315 * @param str1 The string to compare.
316 * @param str2 The string to compare.
317 *
318 * @return
319 * - < 0 if str1 is less than str2
320 * - 0 if str1 is identical to str2
321 * - > 0 if str1 is greater than str2
322 */
323 PJ_IDECL(int) pj_strcmp2( const pj_str_t *str1, const char *str2 );
324
325 /**
326 * Compare strings.
327 *
328 * @param str1 The string to compare.
329 * @param str2 The string to compare.
330 * @param len The maximum number of characters to compare.
331 *
332 * @return
333 * - < 0 if str1 is less than str2
334 * - 0 if str1 is identical to str2
335 * - > 0 if str1 is greater than str2
336 */
337 PJ_IDECL(int) pj_strncmp( const pj_str_t *str1, const pj_str_t *str2,
338 pj_size_t len);
339
340 /**
341 * Compare strings.
342 *
343 * @param str1 The string to compare.
344 * @param str2 The string to compare.
345 * @param len The maximum number of characters to compare.
346 *
347 * @return
348 * - < 0 if str1 is less than str2
349 * - 0 if str1 is identical to str2
350 * - > 0 if str1 is greater than str2
351 */
352 PJ_IDECL(int) pj_strncmp2( const pj_str_t *str1, const char *str2,
353 pj_size_t len);
354
355 /**
356 * Perform case-insensitive comparison to the strings.
357 *
358 * @param str1 The string to compare.
359 * @param str2 The string to compare.
360 *
361 * @return
362 * - < 0 if str1 is less than str2
363 * - 0 if str1 is equal to str2
364 * - > 0 if str1 is greater than str2
365 */
366 PJ_IDECL(int) pj_stricmp(const pj_str_t *str1, const pj_str_t *str2);
367
368 /**
369 * Perform lowercase comparison to the strings which consists of only
370 * alnum characters. More over, it will only return non-zero if both
371 * strings are not equal, not the usual negative or positive value.
372 *
373 * If non-alnum inputs are given, then the function may mistakenly
374 * treat two strings as equal.
375 *
376 * @param str1 The string to compare.
377 * @param str2 The string to compare.
378 * @param len The length to compare.
379 *
380 * @return
381 * - 0 if str1 is equal to str2
382 * - (-1) if not equal.
383 */
384 #if defined(PJ_HAS_STRICMP_ALNUM) && PJ_HAS_STRICMP_ALNUM!=0
385 PJ_IDECL(int) strnicmp_alnum(const char *str1, const char *str2,
386 int len);
387 #else
388 #define strnicmp_alnum pj_ansi_strnicmp
389 #endif
390
391 /**
392 * Perform lowercase comparison to the strings which consists of only
393 * alnum characters. More over, it will only return non-zero if both
394 * strings are not equal, not the usual negative or positive value.
395 *
396 * If non-alnum inputs are given, then the function may mistakenly
397 * treat two strings as equal.
398 *
399 * @param str1 The string to compare.
400 * @param str2 The string to compare.
401 *
402 * @return
403 * - 0 if str1 is equal to str2
404 * - (-1) if not equal.
405 */
406 #if defined(PJ_HAS_STRICMP_ALNUM) && PJ_HAS_STRICMP_ALNUM!=0
407 PJ_IDECL(int) pj_stricmp_alnum(const pj_str_t *str1, const pj_str_t *str2);
408 #else
409 #define pj_stricmp_alnum pj_stricmp
410 #endif
411
412 /**
413 * Perform case-insensitive comparison to the strings.
414 *
415 * @param str1 The string to compare.
416 * @param str2 The string to compare.
417 *
418 * @return
419 * - < 0 if str1 is less than str2
420 * - 0 if str1 is identical to str2
421 * - > 0 if str1 is greater than str2
422 */
423 PJ_IDECL(int) pj_stricmp2( const pj_str_t *str1, const char *str2);
424
425 /**
426 * Perform case-insensitive comparison to the strings.
427 *
428 * @param str1 The string to compare.
429 * @param str2 The string to compare.
430 * @param len The maximum number of characters to compare.
431 *
432 * @return
433 * - < 0 if str1 is less than str2
434 * - 0 if str1 is identical to str2
435 * - > 0 if str1 is greater than str2
436 */
437 PJ_IDECL(int) pj_strnicmp( const pj_str_t *str1, const pj_str_t *str2,
438 pj_size_t len);
439
440 /**
441 * Perform case-insensitive comparison to the strings.
442 *
443 * @param str1 The string to compare.
444 * @param str2 The string to compare.
445 * @param len The maximum number of characters to compare.
446 *
447 * @return
448 * - < 0 if str1 is less than str2
449 * - 0 if str1 is identical to str2
450 * - > 0 if str1 is greater than str2
451 */
452 PJ_IDECL(int) pj_strnicmp2( const pj_str_t *str1, const char *str2,
453 pj_size_t len);
454
455 /**
456 * Concatenate strings.
457 *
458 * @param dst The destination string.
459 * @param src The source string.
460 */
461 PJ_IDECL(void) pj_strcat(pj_str_t *dst, const pj_str_t *src);
462
463
464 /**
465 * Concatenate strings.
466 *
467 * @param dst The destination string.
468 * @param src The source string.
469 */
470 PJ_IDECL(void) pj_strcat2(pj_str_t *dst, const char *src);
471
472
473 /**
474 * Finds a character in a string.
475 *
476 * @param str The string.
477 * @param chr The character to find.
478 *
479 * @return the pointer to first character found, or NULL.
480 */
pj_strchr(const pj_str_t * str,int chr)481 PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr)
482 {
483 if (str->slen == 0)
484 return NULL;
485 return (char*) memchr((char*)str->ptr, chr, str->slen);
486 }
487
488
489 /**
490 * Find the first index of character, in a string, that does not belong to a
491 * set of characters.
492 *
493 * @param str The string.
494 * @param set_char The string containing the set of characters.
495 *
496 * @return the index of the first character in the str that doesn't belong to
497 * set_char. If str starts with a character not in set_char, return 0.
498 */
499 PJ_DECL(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char);
500
501
502 /**
503 * Find the first index of character, in a string, that does not belong to a
504 * set of characters.
505 *
506 * @param str The string.
507 * @param set_char The string containing the set of characters.
508 *
509 * @return the index of the first character in the str that doesn't belong to
510 * set_char. If str starts with a character not in set_char, return 0.
511 */
512 PJ_DECL(pj_ssize_t) pj_strspn2(const pj_str_t *str, const char *set_char);
513
514
515 /**
516 * Find the first index of character, in a string, that belong to a set of
517 * characters.
518 *
519 * @param str The string.
520 * @param set_char The string containing the set of characters.
521 *
522 * @return the index of the first character in the str that belong to
523 * set_char. If no match is found, return the length of str.
524 */
525 PJ_DECL(pj_ssize_t) pj_strcspn(const pj_str_t *str, const pj_str_t *set_char);
526
527
528 /**
529 * Find the first index of character, in a string, that belong to a set of
530 * characters.
531 *
532 * @param str The string.
533 * @param set_char The string containing the set of characters.
534 *
535 * @return the index of the first character in the str that belong to
536 * set_char. If no match is found, return the length of str.
537 */
538 PJ_DECL(pj_ssize_t) pj_strcspn2(const pj_str_t *str, const char *set_char);
539
540
541 /**
542 * Find tokens from a string using the delimiter.
543 *
544 * @param str The string.
545 * @param delim The string containing the delimiter. It might contain
546 * multiple character treated as unique set. If same character
547 * was found on the set, it will be skipped.
548 * @param tok The string containing the token.
549 * @param start_idx The search will start from this index.
550 *
551 * @return the index of token from the str, or the length of the str
552 * if the token is not found.
553 */
554 PJ_DECL(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim,
555 pj_str_t *tok, pj_size_t start_idx);
556
557
558 /**
559 * Find tokens from a string using the delimiter.
560 *
561 * @param str The string.
562 * @param delim The string containing the delimiter. It might contain
563 * multiple character treated as unique set. If same character
564 * was found on the set, it will be skipped.
565 * @param tok The string containing the token.
566 * @param start_idx The search will start from this index.
567 *
568 * @return the index of token from the str, or the length of the str
569 * if the token is not found.
570 */
571 PJ_DECL(pj_ssize_t) pj_strtok2(const pj_str_t *str, const char *delim,
572 pj_str_t *tok, pj_size_t start_idx);
573
574
575 /**
576 * Find the occurence of a substring substr in string str.
577 *
578 * @param str The string to search.
579 * @param substr The string to search fo.
580 *
581 * @return the pointer to the position of substr in str, or NULL. Note
582 * that if str is not NULL terminated, the returned pointer
583 * is pointing to non-NULL terminated string.
584 */
585 PJ_DECL(char*) pj_strstr(const pj_str_t *str, const pj_str_t *substr);
586
587 /**
588 * Performs substring lookup like pj_strstr() but ignores the case of
589 * both strings.
590 *
591 * @param str The string to search.
592 * @param substr The string to search fo.
593 *
594 * @return the pointer to the position of substr in str, or NULL. Note
595 * that if str is not NULL terminated, the returned pointer
596 * is pointing to non-NULL terminated string.
597 */
598 PJ_DECL(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr);
599
600 /**
601 * Remove (trim) leading whitespaces from the string.
602 *
603 * @param str The string.
604 *
605 * @return the string.
606 */
607 PJ_DECL(pj_str_t*) pj_strltrim( pj_str_t *str );
608
609 /**
610 * Remove (trim) the trailing whitespaces from the string.
611 *
612 * @param str The string.
613 *
614 * @return the string.
615 */
616 PJ_DECL(pj_str_t*) pj_strrtrim( pj_str_t *str );
617
618 /**
619 * Remove (trim) leading and trailing whitespaces from the string.
620 *
621 * @param str The string.
622 *
623 * @return the string.
624 */
625 PJ_IDECL(pj_str_t*) pj_strtrim( pj_str_t *str );
626
627 /**
628 * Initialize the buffer with some random string. Note that the
629 * generated string is not NULL terminated.
630 *
631 * @param str the string to store the result.
632 * @param length the length of the random string to generate.
633 *
634 * @return the string.
635 */
636 PJ_DECL(char*) pj_create_random_string(char *str, pj_size_t length);
637
638 /**
639 * Convert string to signed integer. The conversion will stop as
640 * soon as non-digit character is found or all the characters have
641 * been processed.
642 *
643 * @param str the string.
644 *
645 * @return the integer.
646 */
647 PJ_DECL(long) pj_strtol(const pj_str_t *str);
648
649 /**
650 * Convert string to signed long integer. The conversion will stop as
651 * soon as non-digit character is found or all the characters have
652 * been processed.
653 *
654 * @param str the string.
655 * @param value Pointer to a long to receive the value.
656 *
657 * @return PJ_SUCCESS if successful. Otherwise:
658 * PJ_ETOOSMALL if the value was an impossibly long negative number.
659 * In this case *value will be set to LONG_MIN.
660 * \n
661 * PJ_ETOOBIG if the value was an impossibly long positive number.
662 * In this case, *value will be set to LONG_MAX.
663 * \n
664 * PJ_EINVAL if the input string was NULL, the value pointer was NULL
665 * or the input string could not be parsed at all such as starting with
666 * a character other than a '+', '-' or not in the '0' - '9' range.
667 * In this case, *value will be left untouched.
668 */
669 PJ_DECL(pj_status_t) pj_strtol2(const pj_str_t *str, long *value);
670
671
672 /**
673 * Convert string to unsigned integer. The conversion will stop as
674 * soon as non-digit character is found or all the characters have
675 * been processed.
676 *
677 * @param str the string.
678 *
679 * @return the unsigned integer.
680 */
681 PJ_DECL(unsigned long) pj_strtoul(const pj_str_t *str);
682
683 /**
684 * Convert strings to an unsigned long-integer value.
685 * This function stops reading the string input either when the number
686 * of characters has exceeded the length of the input or it has read
687 * the first character it cannot recognize as part of a number, that is
688 * a character greater than or equal to base.
689 *
690 * @param str The input string.
691 * @param endptr Optional pointer to receive the remainder/unparsed
692 * portion of the input.
693 * @param base Number base to use.
694 *
695 * @return the unsigned integer number.
696 */
697 PJ_DECL(unsigned long) pj_strtoul2(const pj_str_t *str, pj_str_t *endptr,
698 unsigned base);
699
700 /**
701 * Convert string to unsigned long integer. The conversion will stop as
702 * soon as non-digit character is found or all the characters have
703 * been processed.
704 *
705 * @param str The input string.
706 * @param value Pointer to an unsigned long to receive the value.
707 * @param base Number base to use.
708 *
709 * @return PJ_SUCCESS if successful. Otherwise:
710 * PJ_ETOOBIG if the value was an impossibly long positive number.
711 * In this case, *value will be set to ULONG_MAX.
712 * \n
713 * PJ_EINVAL if the input string was NULL, the value pointer was NULL
714 * or the input string could not be parsed at all such as starting
715 * with a character outside the base character range. In this case,
716 * *value will be left untouched.
717 */
718 PJ_DECL(pj_status_t) pj_strtoul3(const pj_str_t *str, unsigned long *value,
719 unsigned base);
720
721 /**
722 * Convert string to float.
723 *
724 * @param str the string.
725 *
726 * @return the value.
727 */
728 PJ_DECL(float) pj_strtof(const pj_str_t *str);
729
730 /**
731 * Utility to convert unsigned integer to string. Note that the
732 * string will be NULL terminated.
733 *
734 * @param val the unsigned integer value.
735 * @param buf the buffer
736 *
737 * @return the number of characters written
738 */
739 PJ_DECL(int) pj_utoa(unsigned long val, char *buf);
740
741 /**
742 * Convert unsigned integer to string with minimum digits. Note that the
743 * string will be NULL terminated.
744 *
745 * @param val The unsigned integer value.
746 * @param buf The buffer.
747 * @param min_dig Minimum digits to be printed, or zero to specify no
748 * minimum digit.
749 * @param pad The padding character to be put in front of the string
750 * when the digits is less than minimum.
751 *
752 * @return the number of characters written.
753 */
754 PJ_DECL(int) pj_utoa_pad( unsigned long val, char *buf, int min_dig, int pad);
755
756
757 /**
758 * Fill the memory location with zero.
759 *
760 * @param dst The destination buffer.
761 * @param size The number of bytes.
762 */
pj_bzero(void * dst,pj_size_t size)763 PJ_INLINE(void) pj_bzero(void *dst, pj_size_t size)
764 {
765 #if defined(PJ_HAS_BZERO) && PJ_HAS_BZERO!=0
766 bzero(dst, size);
767 #else
768 memset(dst, 0, size);
769 #endif
770 }
771
772
773 /**
774 * Fill the memory location with value.
775 *
776 * @param dst The destination buffer.
777 * @param c Character to set.
778 * @param size The number of characters.
779 *
780 * @return the value of dst.
781 */
pj_memset(void * dst,int c,pj_size_t size)782 PJ_INLINE(void*) pj_memset(void *dst, int c, pj_size_t size)
783 {
784 return memset(dst, c, size);
785 }
786
787 /**
788 * Copy buffer.
789 *
790 * @param dst The destination buffer.
791 * @param src The source buffer.
792 * @param size The size to copy.
793 *
794 * @return the destination buffer.
795 */
pj_memcpy(void * dst,const void * src,pj_size_t size)796 PJ_INLINE(void*) pj_memcpy(void *dst, const void *src, pj_size_t size)
797 {
798 return memcpy(dst, src, size);
799 }
800
801 /**
802 * Move memory.
803 *
804 * @param dst The destination buffer.
805 * @param src The source buffer.
806 * @param size The size to copy.
807 *
808 * @return the destination buffer.
809 */
pj_memmove(void * dst,const void * src,pj_size_t size)810 PJ_INLINE(void*) pj_memmove(void *dst, const void *src, pj_size_t size)
811 {
812 return memmove(dst, src, size);
813 }
814
815 /**
816 * Compare buffers.
817 *
818 * @param buf1 The first buffer.
819 * @param buf2 The second buffer.
820 * @param size The size to compare.
821 *
822 * @return negative, zero, or positive value.
823 */
pj_memcmp(const void * buf1,const void * buf2,pj_size_t size)824 PJ_INLINE(int) pj_memcmp(const void *buf1, const void *buf2, pj_size_t size)
825 {
826 return memcmp(buf1, buf2, size);
827 }
828
829 /**
830 * Find character in the buffer.
831 *
832 * @param buf The buffer.
833 * @param c The character to find.
834 * @param size The size to check.
835 *
836 * @return the pointer to location where the character is found, or NULL if
837 * not found.
838 */
pj_memchr(const void * buf,int c,pj_size_t size)839 PJ_INLINE(void*) pj_memchr(const void *buf, int c, pj_size_t size)
840 {
841 return (void*)memchr((void*)buf, c, size);
842 }
843
844 /**
845 * @}
846 */
847
848 #if PJ_FUNCTIONS_ARE_INLINED
849 # include <pj/string_i.h>
850 #endif
851
852 PJ_END_DECL
853
854 #endif /* __PJ_STRING_H__ */
855
856