cec: fix compilation on windows after interface changes
[deb_libcec.git] / src / lib / util / misc.cpp
... / ...
CommitLineData
1/*
2 * boblight
3 * Copyright (C) Bob 2009
4 *
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.
9 *
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.
14 *
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/>.
17 */
18
19#include <iostream>
20#include <locale.h>
21#include "misc.h"
22
23using namespace std;
24
25void PrintError(const std::string& error)
26{
27 std::cerr << "ERROR: " << error << "\n";
28}
29
30//get the first word (separated by whitespace) from string data and place that in word
31//then remove that word from string data
32bool GetWord(string& data, string& word)
33{
34 stringstream datastream(data);
35 string end;
36
37 datastream >> word;
38 if (datastream.fail())
39 {
40 data.clear();
41 return false;
42 }
43
44 size_t pos = data.find(word) + word.length();
45
46 if (pos >= data.length())
47 {
48 data.clear();
49 return true;
50 }
51
52 data = data.substr(pos);
53
54 datastream.clear();
55 datastream.str(data);
56
57 datastream >> end;
58 if (datastream.fail())
59 data.clear();
60
61 return true;
62}
63
64//convert . or , to the current locale for correct conversion of ascii float
65void ConvertFloatLocale(std::string& strfloat)
66{
67 static struct lconv* locale = localeconv();
68
69 size_t pos = strfloat.find_first_of(",.");
70
71 while (pos != string::npos)
72 {
73 strfloat.replace(pos, 1, 1, *locale->decimal_point);
74 pos++;
75
76 if (pos >= strfloat.size())
77 break;
78
79 pos = strfloat.find_first_of(",.", pos);
80 }
81}