gstring.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_STRING_H__
  24. #define __G_STRING_H__
  25. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #include <glib/gtypes.h>
  29. #include <glib/gunicode.h>
  30. #include <glib/gbytes.h>
  31. #include <glib/gutils.h> /* for G_CAN_INLINE */
  32. G_BEGIN_DECLS
  33. typedef struct _GString GString;
  34. struct _GString
  35. {
  36. gchar *str;
  37. gsize len;
  38. gsize allocated_len;
  39. };
  40. GLIB_AVAILABLE_IN_ALL
  41. GString* g_string_new (const gchar *init);
  42. GLIB_AVAILABLE_IN_ALL
  43. GString* g_string_new_len (const gchar *init,
  44. gssize len);
  45. GLIB_AVAILABLE_IN_ALL
  46. GString* g_string_sized_new (gsize dfl_size);
  47. GLIB_AVAILABLE_IN_ALL
  48. gchar* g_string_free (GString *string,
  49. gboolean free_segment);
  50. GLIB_AVAILABLE_IN_2_34
  51. GBytes* g_string_free_to_bytes (GString *string);
  52. GLIB_AVAILABLE_IN_ALL
  53. gboolean g_string_equal (const GString *v,
  54. const GString *v2);
  55. GLIB_AVAILABLE_IN_ALL
  56. guint g_string_hash (const GString *str);
  57. GLIB_AVAILABLE_IN_ALL
  58. GString* g_string_assign (GString *string,
  59. const gchar *rval);
  60. GLIB_AVAILABLE_IN_ALL
  61. GString* g_string_truncate (GString *string,
  62. gsize len);
  63. GLIB_AVAILABLE_IN_ALL
  64. GString* g_string_set_size (GString *string,
  65. gsize len);
  66. GLIB_AVAILABLE_IN_ALL
  67. GString* g_string_insert_len (GString *string,
  68. gssize pos,
  69. const gchar *val,
  70. gssize len);
  71. GLIB_AVAILABLE_IN_ALL
  72. GString* g_string_append (GString *string,
  73. const gchar *val);
  74. GLIB_AVAILABLE_IN_ALL
  75. GString* g_string_append_len (GString *string,
  76. const gchar *val,
  77. gssize len);
  78. GLIB_AVAILABLE_IN_ALL
  79. GString* g_string_append_c (GString *string,
  80. gchar c);
  81. GLIB_AVAILABLE_IN_ALL
  82. GString* g_string_append_unichar (GString *string,
  83. gunichar wc);
  84. GLIB_AVAILABLE_IN_ALL
  85. GString* g_string_prepend (GString *string,
  86. const gchar *val);
  87. GLIB_AVAILABLE_IN_ALL
  88. GString* g_string_prepend_c (GString *string,
  89. gchar c);
  90. GLIB_AVAILABLE_IN_ALL
  91. GString* g_string_prepend_unichar (GString *string,
  92. gunichar wc);
  93. GLIB_AVAILABLE_IN_ALL
  94. GString* g_string_prepend_len (GString *string,
  95. const gchar *val,
  96. gssize len);
  97. GLIB_AVAILABLE_IN_ALL
  98. GString* g_string_insert (GString *string,
  99. gssize pos,
  100. const gchar *val);
  101. GLIB_AVAILABLE_IN_ALL
  102. GString* g_string_insert_c (GString *string,
  103. gssize pos,
  104. gchar c);
  105. GLIB_AVAILABLE_IN_ALL
  106. GString* g_string_insert_unichar (GString *string,
  107. gssize pos,
  108. gunichar wc);
  109. GLIB_AVAILABLE_IN_ALL
  110. GString* g_string_overwrite (GString *string,
  111. gsize pos,
  112. const gchar *val);
  113. GLIB_AVAILABLE_IN_ALL
  114. GString* g_string_overwrite_len (GString *string,
  115. gsize pos,
  116. const gchar *val,
  117. gssize len);
  118. GLIB_AVAILABLE_IN_ALL
  119. GString* g_string_erase (GString *string,
  120. gssize pos,
  121. gssize len);
  122. GLIB_AVAILABLE_IN_ALL
  123. GString* g_string_ascii_down (GString *string);
  124. GLIB_AVAILABLE_IN_ALL
  125. GString* g_string_ascii_up (GString *string);
  126. GLIB_AVAILABLE_IN_ALL
  127. void g_string_vprintf (GString *string,
  128. const gchar *format,
  129. va_list args)
  130. G_GNUC_PRINTF(2, 0);
  131. GLIB_AVAILABLE_IN_ALL
  132. void g_string_printf (GString *string,
  133. const gchar *format,
  134. ...) G_GNUC_PRINTF (2, 3);
  135. GLIB_AVAILABLE_IN_ALL
  136. void g_string_append_vprintf (GString *string,
  137. const gchar *format,
  138. va_list args)
  139. G_GNUC_PRINTF(2, 0);
  140. GLIB_AVAILABLE_IN_ALL
  141. void g_string_append_printf (GString *string,
  142. const gchar *format,
  143. ...) G_GNUC_PRINTF (2, 3);
  144. GLIB_AVAILABLE_IN_ALL
  145. GString* g_string_append_uri_escaped (GString *string,
  146. const gchar *unescaped,
  147. const gchar *reserved_chars_allowed,
  148. gboolean allow_utf8);
  149. /* -- optimize g_strig_append_c --- */
  150. #ifdef G_CAN_INLINE
  151. static inline GString*
  152. g_string_append_c_inline (GString *gstring,
  153. gchar c)
  154. {
  155. if (gstring->len + 1 < gstring->allocated_len)
  156. {
  157. gstring->str[gstring->len++] = c;
  158. gstring->str[gstring->len] = 0;
  159. }
  160. else
  161. g_string_insert_c (gstring, -1, c);
  162. return gstring;
  163. }
  164. #define g_string_append_c(gstr,c) g_string_append_c_inline (gstr, c)
  165. #endif /* G_CAN_INLINE */
  166. GLIB_DEPRECATED
  167. GString *g_string_down (GString *string);
  168. GLIB_DEPRECATED
  169. GString *g_string_up (GString *string);
  170. #ifndef G_DISABLE_DEPRECATED
  171. #define g_string_sprintf g_string_printf
  172. #define g_string_sprintfa g_string_append_printf
  173. #endif
  174. G_END_DECLS
  175. #endif /* __G_STRING_H__ */