3 * Copyright (C) Bob 2009
5 * boblight is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * boblight is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
25 void PrintError(const std::string
& error
)
27 std::cerr
<< "ERROR: " << error
<< "\n";
30 //get the first word (separated by whitespace) from string data and place that in word
31 //then remove that word from string data
32 bool GetWord(string
& data
, string
& word
)
34 stringstream
datastream(data
);
38 if (datastream
.fail())
44 size_t pos
= data
.find(word
) + word
.length();
46 if (pos
>= data
.length())
52 data
= data
.substr(pos
);
58 if (datastream
.fail())
64 //convert . or , to the current locale for correct conversion of ascii float
65 void ConvertFloatLocale(std::string
& strfloat
)
67 static struct lconv
* locale
= localeconv();
69 size_t pos
= strfloat
.find_first_of(",.");
71 while (pos
!= string::npos
)
73 strfloat
.replace(pos
, 1, 1, *locale
->decimal_point
);
76 if (pos
>= strfloat
.size())
79 pos
= strfloat
.find_first_of(",.", pos
);