1 /* vim:set et ts=4 sts=4:
3 * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
5 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef __PY_STRING_H_
22 #define __PY_STRING_H_
30 class String : public std::string {
32 String () : std::string () { }
33 String (const gchar *str) : std::string (str) { }
34 String (const std::string &str) : std::string (str) { }
35 String (gint len) : std::string () { reserve (len); }
37 String & printf (const gchar *fmt, ...)
43 str = g_strdup_vprintf (fmt, args);
51 String & appendPrintf (const gchar *fmt, ...)
57 str = g_strdup_vprintf (fmt, args);
66 String & appendUnichar (gunichar ch)
70 len = g_unichar_to_utf8 (ch, str);
76 String & insert (gint i, gchar ch)
78 std::string::insert (i, 1, ch);
82 String & truncate (guint len)
88 gsize utf8Length (void) const
90 return g_utf8_strlen (c_str(), -1);
93 String & operator<< (gint i)
95 return appendPrintf ("%d", i);
98 String & operator<< (guint i)
100 return appendPrintf ("%u", i);
103 String & operator<< (const gchar ch)
109 String & operator<< (const gchar *str)
115 String & operator<< (const gunichar *wstr)
119 str = g_ucs4_to_utf8 (wstr, -1, NULL, NULL, &error);
121 g_warning ("convert ucs4 to utf8 failed: %s", error->message);
122 g_error_free (error);
131 gchar operator[] (gint i)
133 return std::string::operator[] (i);
136 String & operator<< (const std::string &str)
138 return operator<< (str.c_str ());
141 String & operator<< (const String &str)
143 return operator<< ((const gchar *)str);
146 String & operator= (const gchar * str)
152 operator const gchar *(void) const
154 return this->c_str ();
157 operator gboolean (void) const