aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-string.c
blob: 2d53c25b53b71c60ca0fd99c3a5dafe563290064 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 *  Copyright (C) 2002 Marco Pesenti Gritti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  $Id$
 */

#include "config.h"

#include "ephy-string.h"

#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>

gboolean
ephy_string_to_int (const char *string, gulong *integer)
{
    gulong result;
    char *parse_end;

    /* Check for the case of an empty string. */
    if (string == NULL || *string == '\0')
    {
        return FALSE;
    }

    /* Call the standard library routine to do the conversion. */
    errno = 0;
    result = strtol (string, &parse_end, 0);

    /* Check that the result is in range. */
    if ((result == G_MINLONG || result == G_MAXLONG) && errno == ERANGE)
    {
        return FALSE;
    }

    /* Check that all the trailing characters are spaces. */
    while (*parse_end != '\0')
    {
        if (!g_ascii_isspace (*parse_end++))
        {
            return FALSE;
        }
    }

    /* Return the result. */
    *integer = result;
    return TRUE;
}

char *
ephy_string_blank_chr (char *source)
{
    char *p;

        if (source == NULL)
    {
        return NULL;
    }

    p = source;
    while (*p != '\0')
    {
        if ((guchar) *p < 0x20)
        {
            *p = ' ';
        }
        p++;
    }

        return source;
}