~ubuntu-branches/ubuntu/trusty/me-tv/trusty

« back to all changes in this revision

Viewing changes to src/string_splitter.cc

  • Committer: Bazaar Package Importer
  • Author(s): Teis Dreijer
  • Date: 2010-02-14 11:29:00 UTC
  • mfrom: (1.1.11 upstream) (3.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100214112900-krutrmpz248vz1ji
Tags: 1.1.6-2
* Updated debian/control
  - Removed libgnomem-2.6-dev and libgnomeuimm-2.6-dev
    from Build-Depends (Closes: #568782)
  - Added libgconfmm-2.6-dev to Build-Depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2010 Michael Lamothe
3
 
 *
4
 
 * This file is part of Me TV
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 * 
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU Library General Public License for more details.
15
 
 * 
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
19
 
 */
20
 
 
21
 
#include "string_splitter.h"
22
 
#include "exception.h"
23
 
#include "me-tv-i18n.h"
24
 
 
25
 
StringSplitter::StringSplitter(const Glib::ustring& text, const char* delimiter, gboolean squeeze_repeats, gsize max_length)
26
 
{
27
 
        parts = g_strsplit_set(text.c_str(), delimiter, max_length);
28
 
        count = 0;
29
 
        gchar** iterator = parts;
30
 
        while (*iterator != NULL && count < max_length)
31
 
        {
32
 
                parts[count] = *iterator;
33
 
                if (!squeeze_repeats || g_utf8_strlen(*iterator, -1) > 0)
34
 
                {
35
 
                        count++;
36
 
                }
37
 
                iterator++;
38
 
        }
39
 
}
40
 
        
41
 
StringSplitter::~StringSplitter()
42
 
{
43
 
        g_strfreev(parts);
44
 
}
45
 
 
46
 
const gchar* StringSplitter::get_value(guint index)
47
 
{
48
 
        if (index >= count)
49
 
        {
50
 
                throw Exception(_("Index out of bounds"));
51
 
        }
52
 
        return parts[index];
53
 
}
54
 
 
55
 
gint StringSplitter::get_int_value(guint index)
56
 
{
57
 
        return atoi(get_value(index));
58
 
}
59
 
 
60
 
gsize StringSplitter::get_count() const
61
 
{
62
 
        return count;
63
 
}