2
* Copyright (C) 2007 Michael Lamothe
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program 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
12
* GNU Library General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
19
#include "string_utility.h"
20
#include "exception.h"
22
Glib::ustring StringUtility::format(const char* fmt, ...)
27
gchar* text = g_strdup_vprintf(fmt, ap);
28
Glib::ustring result = text;
35
Glib::ustring StringUtility::get_buffer(const char* buffer, unsigned int length)
38
result.append(buffer, length);
42
Glib::ustring StringUtility::escape(const Glib::ustring& source)
45
const gchar* destination = g_strescape(source.c_str(), NULL);
47
delete [] destination;
51
StringSplitter::StringSplitter(const Glib::ustring& text, const char* deliminator, int max_length)
54
parts = g_strsplit(text.c_str(), deliminator, max_length);
55
gchar** iterator = parts;
56
while (*iterator++ != NULL) count++;
59
StringSplitter::~StringSplitter()
64
const gchar* StringSplitter::get_value(int index)
68
throw Exception("Index out of bounds");
73
int StringSplitter::get_int_value(int index)
75
return atoi(get_value(index));