gstring.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 /*
00022  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00023  * file for a list of people on the GLib Team.  See the ChangeLog
00024  * files for a list of changes.  These files are distributed with
00025  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00026  */
00027 
00028 #ifndef __G_STRING_H__
00029 #define __G_STRING_H__
00030 
00031 #include <_ansi.h>
00032 #include <glib/gtypes.h>
00033 #include <glib/gunicode.h>
00034 #include <glib/gutils.h>  /* for G_CAN_INLINE */
00035 
00036 G_BEGIN_DECLS
00037 
00038 typedef struct _GString         GString;
00039 typedef struct _GStringChunk    GStringChunk;
00040 
00041 struct _GString
00042 {
00043   gchar  *str;
00044   gsize len;    
00045   gsize allocated_len;
00046 };
00047 
00048 /* String Chunks
00049  */
00050 IMPORT_C GStringChunk* g_string_chunk_new          (gsize size);  
00051 IMPORT_C void         g_string_chunk_free          (GStringChunk *chunk);
00052 IMPORT_C gchar*       g_string_chunk_insert        (GStringChunk *chunk,
00053                                             const gchar  *string);
00054 IMPORT_C gchar*       g_string_chunk_insert_len    (GStringChunk *chunk,
00055                                             const gchar  *string,
00056                                             gssize        len);
00057 IMPORT_C gchar*       g_string_chunk_insert_const  (GStringChunk *chunk,
00058                                             const gchar  *string);
00059 
00060 
00061 /* Strings
00062  */
00063 IMPORT_C GString*     g_string_new              (const gchar     *init);
00064 IMPORT_C GString*     g_string_new_len           (const gchar     *init,
00065                                          gssize           len);   
00066 IMPORT_C GString*     g_string_sized_new         (gsize            dfl_size);  
00067 IMPORT_C gchar*      g_string_free              (GString         *string,
00068                                          gboolean         free_segment);
00069 IMPORT_C gboolean     g_string_equal             (const GString  *v,
00070                                          const GString   *v2);
00071 IMPORT_C guint        g_string_hash              (const GString   *str);
00072 IMPORT_C GString*     g_string_assign            (GString        *string,
00073                                          const gchar     *rval);
00074 IMPORT_C GString*     g_string_truncate          (GString        *string,
00075                                          gsize            len);    
00076 IMPORT_C GString*     g_string_set_size          (GString         *string,
00077                                          gsize            len);
00078 IMPORT_C GString*     g_string_insert_len        (GString         *string,
00079                                          gssize           pos,   
00080                                          const gchar     *val,
00081                                          gssize           len);  
00082 IMPORT_C GString*     g_string_append            (GString        *string,
00083                                          const gchar     *val);
00084 IMPORT_C GString*     g_string_append_len        (GString        *string,
00085                                          const gchar     *val,
00086                                          gssize           len);  
00087 IMPORT_C GString*     g_string_append_c          (GString        *string,
00088                                          gchar            c);
00089 IMPORT_C GString*     g_string_append_unichar    (GString        *string,
00090                                          gunichar         wc);
00091 IMPORT_C GString*     g_string_prepend           (GString        *string,
00092                                          const gchar     *val);
00093 IMPORT_C GString*     g_string_prepend_c         (GString        *string,
00094                                          gchar            c);
00095 IMPORT_C GString*     g_string_prepend_unichar   (GString        *string,
00096                                          gunichar         wc);
00097 IMPORT_C GString*     g_string_prepend_len       (GString        *string,
00098                                          const gchar     *val,
00099                                          gssize           len);  
00100 IMPORT_C GString*     g_string_insert            (GString        *string,
00101                                          gssize           pos,    
00102                                          const gchar     *val);
00103 IMPORT_C GString*     g_string_insert_c          (GString        *string,
00104                                          gssize           pos,    
00105                                          gchar            c);
00106 IMPORT_C GString*     g_string_insert_unichar    (GString        *string,
00107                                          gssize           pos,    
00108                                          gunichar         wc);
00109 IMPORT_C GString*     g_string_erase            (GString         *string,
00110                                          gssize           pos,
00111                                          gssize           len);
00112 IMPORT_C GString*     g_string_ascii_down        (GString        *string);
00113 IMPORT_C GString*     g_string_ascii_up          (GString        *string);
00114 IMPORT_C void         g_string_printf            (GString        *string,
00115                                          const gchar     *format,
00116                                          ...) G_GNUC_PRINTF (2, 3);
00117 IMPORT_C void         g_string_append_printf     (GString        *string,
00118                                          const gchar     *format,
00119                                          ...) G_GNUC_PRINTF (2, 3);
00120 
00121 /* -- optimize g_strig_append_c --- */
00122 #ifdef G_CAN_INLINE
00123 static inline GString*
00124 g_string_append_c_inline (GString *gstring,
00125                           gchar    c)
00126 {
00127   if (gstring->len + 1 < gstring->allocated_len)
00128     {
00129       gstring->str[gstring->len++] = c;
00130       gstring->str[gstring->len] = 0;
00131     }
00132   else
00133     g_string_insert_c (gstring, -1, c);
00134   return gstring;
00135 }
00136 #define g_string_append_c(gstr,c)       g_string_append_c_inline (gstr, c)
00137 #endif /* G_CAN_INLINE */
00138 
00139 
00140 #ifndef G_DISABLE_DEPRECATED
00141 
00142 /* The following two functions are deprecated and will be removed in
00143  * the next major release. They use the locale-specific tolower and
00144  * toupper, which is almost never the right thing.
00145  */
00146 
00147 IMPORT_C GString*     g_string_down              (GString        *string);
00148 IMPORT_C GString*     g_string_up                (GString        *string);
00149 
00150 /* These aliases are included for compatibility. */
00151 #define g_string_sprintf        g_string_printf
00152 #define g_string_sprintfa       g_string_append_printf
00153 
00154 #endif /* G_DISABLE_DEPRECATED */
00155 
00156 G_END_DECLS
00157 
00158 #endif /* __G_STRING_H__ */
00159 

Copyright © Nokia Corporation 2001-2008
Back to top