1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
2 
3    eel-string.h: String routines to augment <string.h>.
4 
5    Copyright (C) 2000 Eazel, Inc.
6 
7    The Gnome Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Library General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11 
12    The Gnome Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Library General Public License for more details.
16 
17    You should have received a copy of the GNU Library General Public
18    License along with the Gnome Library; see the file COPYING.LIB.  If not,
19    write to the Free Software Foundation, Inc., 51 Franklin Street - Suite 500,
20    Boston, MA 02110-1335, USA.
21 
22    Authors: Darin Adler <darin@eazel.com>
23 */
24 
25 #ifndef EEL_STRING_H
26 #define EEL_STRING_H
27 
28 #include <glib.h>
29 #include <string.h>
30 #include <stdarg.h>
31 
32 /* We use the "str" abbrevation to mean char * string, since
33  * "string" usually means g_string instead. We use the "istr"
34  * abbreviation to mean a case-insensitive char *.
35  */
36 
37 #define THOU_TO_STR(c) g_strdup_printf ("%'d", c);
38 
39 /* NULL is allowed for all the str parameters to these functions. */
40 
41 /* Escape function for '_' character. */
42 char *   eel_str_double_underscores        (const char    *str);
43 /* Escape function for spaces */
44 char *   eel_str_escape_spaces             (const char    *str);
45 /* Escape function for quotes */
46 char *   eel_str_escape_quotes             (const char    *str);
47 /* Capitalize a string */
48 char *   eel_str_capitalize                (const char    *str);
49 
50 /* Middle truncate a string to a maximum of truncate_length characters.
51  * The resulting string will be truncated in the middle with a "..."
52  * delimiter.
53  */
54 char *   eel_str_middle_truncate           (const char    *str,
55 					    guint          truncate_length);
56 
57 
58 /* Remove all characters after the passed-in substring. */
59 char *   eel_str_strip_substring_and_after (const char    *str,
60 					    const char    *substring);
61 
62 /* Replace all occurrences of substring with replacement. */
63 char *   eel_str_replace_substring         (const char    *str,
64 					    const char    *substring,
65 					    const char    *replacement);
66 
67 typedef char * eel_ref_str;
68 
69 eel_ref_str eel_ref_str_new        (const char  *string);
70 eel_ref_str eel_ref_str_get_unique (const char  *string);
71 eel_ref_str eel_ref_str_ref        (eel_ref_str  str);
72 void        eel_ref_str_unref      (eel_ref_str  str);
73 
74 #define eel_ref_str_peek(__str) ((const char *)(__str))
75 
76 GList *eel_strv_to_glist (gchar **strv);
77 
78 typedef struct {
79   char character;
80   char *(*to_string) (char *format, va_list va);
81   void (*skip) (va_list *va);
82 } EelPrintfHandler;
83 
84 char *eel_strdup_printf_with_custom (EelPrintfHandler *handlers,
85 				     const char *format,
86 				     ...);
87 char *eel_strdup_vprintf_with_custom (EelPrintfHandler *custom,
88 				      const char *format,
89 				      va_list va);
90 
91 #endif /* EEL_STRING_H */
92