You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

179 lines
6.3 KiB

  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, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  21. * file for a list of people on the GLib Team. See the ChangeLog
  22. * files for a list of changes. These files are distributed with
  23. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  24. */
  25. #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #ifndef __G_STRING_H__
  29. #define __G_STRING_H__
  30. #include <glib/gtypes.h>
  31. #include <glib/gunicode.h>
  32. #include <glib/gutils.h> /* for G_CAN_INLINE */
  33. G_BEGIN_DECLS
  34. typedef struct _GString GString;
  35. typedef struct _GStringChunk GStringChunk;
  36. struct _GString
  37. {
  38. gchar *str;
  39. gsize len;
  40. gsize allocated_len;
  41. };
  42. /* String Chunks
  43. */
  44. GStringChunk* g_string_chunk_new (gsize size);
  45. void g_string_chunk_free (GStringChunk *chunk);
  46. void g_string_chunk_clear (GStringChunk *chunk);
  47. gchar* g_string_chunk_insert (GStringChunk *chunk,
  48. const gchar *string);
  49. gchar* g_string_chunk_insert_len (GStringChunk *chunk,
  50. const gchar *string,
  51. gssize len);
  52. gchar* g_string_chunk_insert_const (GStringChunk *chunk,
  53. const gchar *string);
  54. /* Strings
  55. */
  56. GString* g_string_new (const gchar *init);
  57. GString* g_string_new_len (const gchar *init,
  58. gssize len);
  59. GString* g_string_sized_new (gsize dfl_size);
  60. gchar* g_string_free (GString *string,
  61. gboolean free_segment);
  62. gboolean g_string_equal (const GString *v,
  63. const GString *v2);
  64. guint g_string_hash (const GString *str);
  65. GString* g_string_assign (GString *string,
  66. const gchar *rval);
  67. GString* g_string_truncate (GString *string,
  68. gsize len);
  69. GString* g_string_set_size (GString *string,
  70. gsize len);
  71. GString* g_string_insert_len (GString *string,
  72. gssize pos,
  73. const gchar *val,
  74. gssize len);
  75. GString* g_string_append (GString *string,
  76. const gchar *val);
  77. GString* g_string_append_len (GString *string,
  78. const gchar *val,
  79. gssize len);
  80. GString* g_string_append_c (GString *string,
  81. gchar c);
  82. GString* g_string_append_unichar (GString *string,
  83. gunichar wc);
  84. GString* g_string_prepend (GString *string,
  85. const gchar *val);
  86. GString* g_string_prepend_c (GString *string,
  87. gchar c);
  88. GString* g_string_prepend_unichar (GString *string,
  89. gunichar wc);
  90. GString* g_string_prepend_len (GString *string,
  91. const gchar *val,
  92. gssize len);
  93. GString* g_string_insert (GString *string,
  94. gssize pos,
  95. const gchar *val);
  96. GString* g_string_insert_c (GString *string,
  97. gssize pos,
  98. gchar c);
  99. GString* g_string_insert_unichar (GString *string,
  100. gssize pos,
  101. gunichar wc);
  102. GString* g_string_overwrite (GString *string,
  103. gsize pos,
  104. const gchar *val);
  105. GString* g_string_overwrite_len (GString *string,
  106. gsize pos,
  107. const gchar *val,
  108. gssize len);
  109. GString* g_string_erase (GString *string,
  110. gssize pos,
  111. gssize len);
  112. GString* g_string_ascii_down (GString *string);
  113. GString* g_string_ascii_up (GString *string);
  114. void g_string_vprintf (GString *string,
  115. const gchar *format,
  116. va_list args);
  117. void g_string_printf (GString *string,
  118. const gchar *format,
  119. ...) G_GNUC_PRINTF (2, 3);
  120. void g_string_append_vprintf (GString *string,
  121. const gchar *format,
  122. va_list args);
  123. void g_string_append_printf (GString *string,
  124. const gchar *format,
  125. ...) G_GNUC_PRINTF (2, 3);
  126. GString * g_string_append_uri_escaped(GString *string,
  127. const char *unescaped,
  128. const char *reserved_chars_allowed,
  129. gboolean allow_utf8);
  130. /* -- optimize g_strig_append_c --- */
  131. #ifdef G_CAN_INLINE
  132. static inline GString*
  133. g_string_append_c_inline (GString *gstring,
  134. gchar c)
  135. {
  136. if (gstring->len + 1 < gstring->allocated_len)
  137. {
  138. gstring->str[gstring->len++] = c;
  139. gstring->str[gstring->len] = 0;
  140. }
  141. else
  142. g_string_insert_c (gstring, -1, c);
  143. return gstring;
  144. }
  145. #define g_string_append_c(gstr,c) g_string_append_c_inline (gstr, c)
  146. #endif /* G_CAN_INLINE */
  147. #ifndef G_DISABLE_DEPRECATED
  148. /* The following two functions are deprecated and will be removed in
  149. * the next major release. They use the locale-specific tolower and
  150. * toupper, which is almost never the right thing.
  151. */
  152. GString* g_string_down (GString *string);
  153. GString* g_string_up (GString *string);
  154. /* These aliases are included for compatibility. */
  155. #define g_string_sprintf g_string_printf
  156. #define g_string_sprintfa g_string_append_printf
  157. #endif /* G_DISABLE_DEPRECATED */
  158. G_END_DECLS
  159. #endif /* __G_STRING_H__ */