gstrfuncs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  19. * file for a list of people on the GLib Team. See the ChangeLog
  20. * files for a list of changes. These files are distributed with
  21. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  22. */
  23. #ifndef __G_STRFUNCS_H__
  24. #define __G_STRFUNCS_H__
  25. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #include <stdarg.h>
  29. #include <glib/gmacros.h>
  30. #include <glib/gtypes.h>
  31. G_BEGIN_DECLS
  32. /* Functions like the ones in <ctype.h> that are not affected by locale. */
  33. typedef enum {
  34. G_ASCII_ALNUM = 1 << 0,
  35. G_ASCII_ALPHA = 1 << 1,
  36. G_ASCII_CNTRL = 1 << 2,
  37. G_ASCII_DIGIT = 1 << 3,
  38. G_ASCII_GRAPH = 1 << 4,
  39. G_ASCII_LOWER = 1 << 5,
  40. G_ASCII_PRINT = 1 << 6,
  41. G_ASCII_PUNCT = 1 << 7,
  42. G_ASCII_SPACE = 1 << 8,
  43. G_ASCII_UPPER = 1 << 9,
  44. G_ASCII_XDIGIT = 1 << 10
  45. } GAsciiType;
  46. GLIB_VAR const guint16 * const g_ascii_table;
  47. #define g_ascii_isalnum(c) \
  48. ((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
  49. #define g_ascii_isalpha(c) \
  50. ((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
  51. #define g_ascii_iscntrl(c) \
  52. ((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
  53. #define g_ascii_isdigit(c) \
  54. ((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
  55. #define g_ascii_isgraph(c) \
  56. ((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
  57. #define g_ascii_islower(c) \
  58. ((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
  59. #define g_ascii_isprint(c) \
  60. ((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
  61. #define g_ascii_ispunct(c) \
  62. ((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
  63. #define g_ascii_isspace(c) \
  64. ((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
  65. #define g_ascii_isupper(c) \
  66. ((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
  67. #define g_ascii_isxdigit(c) \
  68. ((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
  69. GLIB_AVAILABLE_IN_ALL
  70. gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
  71. GLIB_AVAILABLE_IN_ALL
  72. gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
  73. GLIB_AVAILABLE_IN_ALL
  74. gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
  75. GLIB_AVAILABLE_IN_ALL
  76. gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST;
  77. /* String utility functions that modify a string argument or
  78. * return a constant string that must not be freed.
  79. */
  80. #define G_STR_DELIMITERS "_-|> <."
  81. GLIB_AVAILABLE_IN_ALL
  82. gchar* g_strdelimit (gchar *string,
  83. const gchar *delimiters,
  84. gchar new_delimiter);
  85. GLIB_AVAILABLE_IN_ALL
  86. gchar* g_strcanon (gchar *string,
  87. const gchar *valid_chars,
  88. gchar substitutor);
  89. GLIB_AVAILABLE_IN_ALL
  90. const gchar * g_strerror (gint errnum) G_GNUC_CONST;
  91. GLIB_AVAILABLE_IN_ALL
  92. const gchar * g_strsignal (gint signum) G_GNUC_CONST;
  93. GLIB_AVAILABLE_IN_ALL
  94. gchar * g_strreverse (gchar *string);
  95. GLIB_AVAILABLE_IN_ALL
  96. gsize g_strlcpy (gchar *dest,
  97. const gchar *src,
  98. gsize dest_size);
  99. GLIB_AVAILABLE_IN_ALL
  100. gsize g_strlcat (gchar *dest,
  101. const gchar *src,
  102. gsize dest_size);
  103. GLIB_AVAILABLE_IN_ALL
  104. gchar * g_strstr_len (const gchar *haystack,
  105. gssize haystack_len,
  106. const gchar *needle);
  107. GLIB_AVAILABLE_IN_ALL
  108. gchar * g_strrstr (const gchar *haystack,
  109. const gchar *needle);
  110. GLIB_AVAILABLE_IN_ALL
  111. gchar * g_strrstr_len (const gchar *haystack,
  112. gssize haystack_len,
  113. const gchar *needle);
  114. GLIB_AVAILABLE_IN_ALL
  115. gboolean g_str_has_suffix (const gchar *str,
  116. const gchar *suffix);
  117. GLIB_AVAILABLE_IN_ALL
  118. gboolean g_str_has_prefix (const gchar *str,
  119. const gchar *prefix);
  120. /* String to/from double conversion functions */
  121. GLIB_AVAILABLE_IN_ALL
  122. gdouble g_strtod (const gchar *nptr,
  123. gchar **endptr);
  124. GLIB_AVAILABLE_IN_ALL
  125. gdouble g_ascii_strtod (const gchar *nptr,
  126. gchar **endptr);
  127. GLIB_AVAILABLE_IN_ALL
  128. guint64 g_ascii_strtoull (const gchar *nptr,
  129. gchar **endptr,
  130. guint base);
  131. GLIB_AVAILABLE_IN_ALL
  132. gint64 g_ascii_strtoll (const gchar *nptr,
  133. gchar **endptr,
  134. guint base);
  135. /* 29 bytes should enough for all possible values that
  136. * g_ascii_dtostr can produce.
  137. * Then add 10 for good measure */
  138. #define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
  139. GLIB_AVAILABLE_IN_ALL
  140. gchar * g_ascii_dtostr (gchar *buffer,
  141. gint buf_len,
  142. gdouble d);
  143. GLIB_AVAILABLE_IN_ALL
  144. gchar * g_ascii_formatd (gchar *buffer,
  145. gint buf_len,
  146. const gchar *format,
  147. gdouble d);
  148. /* removes leading spaces */
  149. GLIB_AVAILABLE_IN_ALL
  150. gchar* g_strchug (gchar *string);
  151. /* removes trailing spaces */
  152. GLIB_AVAILABLE_IN_ALL
  153. gchar* g_strchomp (gchar *string);
  154. /* removes leading & trailing spaces */
  155. #define g_strstrip( string ) g_strchomp (g_strchug (string))
  156. GLIB_AVAILABLE_IN_ALL
  157. gint g_ascii_strcasecmp (const gchar *s1,
  158. const gchar *s2);
  159. GLIB_AVAILABLE_IN_ALL
  160. gint g_ascii_strncasecmp (const gchar *s1,
  161. const gchar *s2,
  162. gsize n);
  163. GLIB_AVAILABLE_IN_ALL
  164. gchar* g_ascii_strdown (const gchar *str,
  165. gssize len) G_GNUC_MALLOC;
  166. GLIB_AVAILABLE_IN_ALL
  167. gchar* g_ascii_strup (const gchar *str,
  168. gssize len) G_GNUC_MALLOC;
  169. GLIB_AVAILABLE_IN_2_40
  170. gboolean g_str_is_ascii (const gchar *str);
  171. GLIB_DEPRECATED
  172. gint g_strcasecmp (const gchar *s1,
  173. const gchar *s2);
  174. GLIB_DEPRECATED
  175. gint g_strncasecmp (const gchar *s1,
  176. const gchar *s2,
  177. guint n);
  178. GLIB_DEPRECATED
  179. gchar* g_strdown (gchar *string);
  180. GLIB_DEPRECATED
  181. gchar* g_strup (gchar *string);
  182. /* String utility functions that return a newly allocated string which
  183. * ought to be freed with g_free from the caller at some point.
  184. */
  185. GLIB_AVAILABLE_IN_ALL
  186. gchar* g_strdup (const gchar *str) G_GNUC_MALLOC;
  187. GLIB_AVAILABLE_IN_ALL
  188. gchar* g_strdup_printf (const gchar *format,
  189. ...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
  190. GLIB_AVAILABLE_IN_ALL
  191. gchar* g_strdup_vprintf (const gchar *format,
  192. va_list args) G_GNUC_PRINTF(1, 0) G_GNUC_MALLOC;
  193. GLIB_AVAILABLE_IN_ALL
  194. gchar* g_strndup (const gchar *str,
  195. gsize n) G_GNUC_MALLOC;
  196. GLIB_AVAILABLE_IN_ALL
  197. gchar* g_strnfill (gsize length,
  198. gchar fill_char) G_GNUC_MALLOC;
  199. GLIB_AVAILABLE_IN_ALL
  200. gchar* g_strconcat (const gchar *string1,
  201. ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
  202. GLIB_AVAILABLE_IN_ALL
  203. gchar* g_strjoin (const gchar *separator,
  204. ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
  205. /* Make a copy of a string interpreting C string -style escape
  206. * sequences. Inverse of g_strescape. The recognized sequences are \b
  207. * \f \n \r \t \\ \" and the octal format.
  208. */
  209. GLIB_AVAILABLE_IN_ALL
  210. gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;
  211. /* Copy a string escaping nonprintable characters like in C strings.
  212. * Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
  213. * to a string containing characters that are not to be escaped.
  214. *
  215. * Deprecated API: gchar* g_strescape (const gchar *source);
  216. * Luckily this function wasn't used much, using NULL as second parameter
  217. * provides mostly identical semantics.
  218. */
  219. GLIB_AVAILABLE_IN_ALL
  220. gchar* g_strescape (const gchar *source,
  221. const gchar *exceptions) G_GNUC_MALLOC;
  222. GLIB_AVAILABLE_IN_ALL
  223. gpointer g_memdup (gconstpointer mem,
  224. guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
  225. /* NULL terminated string arrays.
  226. * g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
  227. * at delim and return a newly allocated string array.
  228. * g_strjoinv() concatenates all of str_array's strings, sliding in an
  229. * optional separator, the returned string is newly allocated.
  230. * g_strfreev() frees the array itself and all of its strings.
  231. * g_strdupv() copies a NULL-terminated array of strings
  232. * g_strv_length() returns the length of a NULL-terminated array of strings
  233. */
  234. GLIB_AVAILABLE_IN_ALL
  235. gchar** g_strsplit (const gchar *string,
  236. const gchar *delimiter,
  237. gint max_tokens) G_GNUC_MALLOC;
  238. GLIB_AVAILABLE_IN_ALL
  239. gchar ** g_strsplit_set (const gchar *string,
  240. const gchar *delimiters,
  241. gint max_tokens) G_GNUC_MALLOC;
  242. GLIB_AVAILABLE_IN_ALL
  243. gchar* g_strjoinv (const gchar *separator,
  244. gchar **str_array) G_GNUC_MALLOC;
  245. GLIB_AVAILABLE_IN_ALL
  246. void g_strfreev (gchar **str_array);
  247. GLIB_AVAILABLE_IN_ALL
  248. gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC;
  249. GLIB_AVAILABLE_IN_ALL
  250. guint g_strv_length (gchar **str_array);
  251. GLIB_AVAILABLE_IN_ALL
  252. gchar* g_stpcpy (gchar *dest,
  253. const char *src);
  254. GLIB_AVAILABLE_IN_2_40
  255. gchar * g_str_to_ascii (const gchar *str,
  256. const gchar *from_locale);
  257. GLIB_AVAILABLE_IN_2_40
  258. gchar ** g_str_tokenize_and_fold (const gchar *string,
  259. const gchar *translit_locale,
  260. gchar ***ascii_alternates);
  261. GLIB_AVAILABLE_IN_2_40
  262. gboolean g_str_match_string (const gchar *search_term,
  263. const gchar *potential_hit,
  264. gboolean accept_alternates);
  265. G_END_DECLS
  266. #endif /* __G_STRFUNCS_H__ */