string.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 __PJLIB_UTIL_STRING_H__
  20. #define __PJLIB_UTIL_STRING_H__
  21. /**
  22. * @file string.h
  23. * @brief More string functions.
  24. */
  25. #include <pj/types.h>
  26. #include <pjlib-util/scanner.h>
  27. /**
  28. * @defgroup PJLIB_UTIL_STRING String Escaping Utilities
  29. * @ingroup PJLIB_TEXT
  30. * @{
  31. */
  32. PJ_BEGIN_DECL
  33. /**
  34. * Unescape string. If source string does not contain any escaped
  35. * characters, the function would simply return the original string.
  36. * Otherwise a new string will be allocated.
  37. *
  38. * @param pool Pool to allocate the string.
  39. * @param src Source string to unescape.
  40. *
  41. * @return String with no escaped characters.
  42. */
  43. PJ_DECL(pj_str_t) pj_str_unescape( pj_pool_t *pool, const pj_str_t *src);
  44. /**
  45. * Unescape string to destination.
  46. *
  47. * @param dst Target string.
  48. * @param src Source string.
  49. *
  50. * @return Target string.
  51. */
  52. PJ_DECL(pj_str_t*) pj_strcpy_unescape(pj_str_t *dst, const pj_str_t *src);
  53. /**
  54. * Copy string to destination while escaping reserved characters, up to
  55. * the specified maximum length.
  56. *
  57. * @param dst Target string.
  58. * @param src Source string.
  59. * @param max Maximum length to copy to target string.
  60. * @param unres Unreserved characters, which are allowed to appear
  61. * unescaped.
  62. *
  63. * @return The target string if all characters have been copied
  64. * successfully, or NULL if there's not enough buffer to
  65. * escape the strings.
  66. */
  67. PJ_DECL(pj_str_t*) pj_strncpy_escape(pj_str_t *dst, const pj_str_t *src,
  68. pj_ssize_t max, const pj_cis_t *unres);
  69. /**
  70. * Copy string to destination while escaping reserved characters, up to
  71. * the specified maximum length.
  72. *
  73. * @param dst Target string.
  74. * @param src Source string.
  75. * @param max Maximum length to copy to target string.
  76. * @param unres Unreserved characters, which are allowed to appear
  77. * unescaped.
  78. *
  79. * @return The length of the destination, or -1 if there's not
  80. * enough buffer.
  81. */
  82. PJ_DECL(pj_ssize_t) pj_strncpy2_escape(char *dst, const pj_str_t *src,
  83. pj_ssize_t max, const pj_cis_t *unres);
  84. PJ_END_DECL
  85. /**
  86. * @}
  87. */
  88. #endif /* __PJLIB_UTIL_STRING_H__ */