Code

refactoring: gathering some commonly copy'n'pasted functions on a common
[inkscape.git] / src / helper-fns.h
1 #ifndef SEEN_HELPER_FNS_H
2 #define SEEN_HELPER_FNS_H
3 /** \file
4  * 
5  * Some helper functions
6  * 
7  * Authors:
8  *   Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
9  * 
10  *
11  * Copyright (C) 2006 Hugo Rodrigues
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 static double
17 helperfns_read_number(gchar const *value) {
18     if (!value) return 0;
19     char *end;
20     double ret = g_ascii_strtod(value, &end);
21     if (*end) {
22         g_warning("Unable to convert \"%s\" to number", value);
23         // We could leave this out, too. If strtod can't convert
24         // anything, it will return zero.
25         ret = 0;
26     }
27     return ret;
28 }
30 static bool helperfns_read_bool(gchar const *value, bool default_value){
31     if (!value) return default_value;
32     switch(value[0]){
33         case 't':
34             if (strncmp(value, "true", 4) == 0) return true;
35             break;
36         case 'f':
37             if (strncmp(value, "false", 5) == 0) return false;
38             break;
39     }
40     return default_value;
41 }
42  
43 #endif /* !SEEN_HELPER_FNS_H */
45 /*
46   Local Variables:
47   mode:c++
48   c-file-style:"stroustrup"
49   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
50   indent-tabs-mode:nil
51   fill-column:99
52   End:
53 */
54 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :