diff --git a/src/helper-fns.h b/src/helper-fns.h
index 9d3380bf2cee47a0cac4783ab62c1a3587ba5a06..f407364a595e7366be01be82bb718667550bb585 100644 (file)
--- a/src/helper-fns.h
+++ b/src/helper-fns.h
* Some helper functions
*
* Authors:
- * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
+ * Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
*
*
* Copyright (C) 2006 Hugo Rodrigues
// can be more clear.
#define HELPERFNS_NO_WARNING false
-/* convert localized ascii representation to double
+/* convert ascii representation to double
* the function can only be used to convert numbers as given by gui elements that use localized representation
* @param value ascii representation of the number
* @return the converted number
* is not known beforehand. For example, see sp_feColorMatrix_set in
* sp-fecolormatrix.cpp */
inline double helperfns_read_number(gchar const *value, bool warning = true) {
- if (!value) return 0;
+ if (!value) {
+ g_warning("Called helperfns_read_number with value==null_ptr, this can lead to unexpected behaviour.");
+ return 0;
+ }
char *end;
- double ret = g_strtod(value, &end);
+ double ret = g_ascii_strtod(value, &end);
if (*end) {
if (warning) {
g_warning("helper-fns::helperfns_read_number() Unable to convert \"%s\" to number", value);
return default_value;
}
-/* convert localized ascii representation to double
+/* convert ascii representation to double
* the function can only be used to convert numbers as given by gui elements that use localized representation
* numbers are delimeted by space
* @param value ascii representation of the number
is >> str;
char *end;
- double ret = g_strtod(str.c_str(), &end);
+ double ret = g_ascii_strtod(str.c_str(), &end);
if (*end) {
g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", str.c_str());
// We could leave this out, too. If strtod can't convert
return v;
}
-/* convert localized ascii representation to double
+/* convert ascii representation to double
* the function can only be used to convert numbers as given by gui elements that use localized representation
* numbers are delimeted by space
* @param value ascii representation of the number
@@ -94,24 +97,23 @@ inline std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
*/
inline std::vector<gdouble> helperfns_read_vector(const gchar* value){
std::vector<gdouble> v;
- std::istringstream is(value);
- gdouble d;
- std::string str;
- is >> str;
- while(str.size())
+ gchar const* beg = value;
+ while(isspace(*beg)) beg++;
+ while(*beg)
{
char *end;
- double ret = g_strtod(str.c_str(), &end);
- if (*end){
- g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", str.c_str());
+ double ret = g_ascii_strtod(beg, &end);
+ if (end==beg){
+ g_warning("helper-fns::helperfns_read_vector() Unable to convert \"%s\" to number", beg);
// We could leave this out, too. If strtod can't convert
// anything, it will return zero.
ret = 0;
}
- v.push_back(d);
+ v.push_back(ret);
- is >> str;
+ beg = end;
+ while(isspace(*beg)) beg++;
}
return v;
}
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :