1 /*
2  * Copyright 2010, 2011, 2014 Peter Olsson
3  *
4  * This file is part of Brum Brum Rally.
5  *
6  * Brum Brum Rally is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Brum Brum Rally is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "str.h"
21 #include <cctype>
22 #include <climits>
23 #include <cstddef>
24 #include <sstream>
25 
int2string(int i)26 std::string int2string(int i)
27 {
28 	std::ostringstream osstream;
29 	osstream << i;
30 	return osstream.str();
31 }
32 
time2string(int t,bool showMilliseconds)33 std::string time2string(int t, bool showMilliseconds)
34 {
35 	std::ostringstream  s;
36 	if (t == INT_MAX) // DNF
37 	{
38 		s << "DNF";
39 	}
40 	else
41 	{
42 		s << (t / 600000);
43 		s << (t / 60000) % 10;
44 		s << ":";
45 		s << (t / 10000) % 6;
46 		s << (t / 1000) % 10;
47 		s << ":";
48 		s << (t / 100) % 10;
49 		s << (t / 10) % 10;
50 		if (showMilliseconds)
51 		{
52 			s << t  % 10;
53 		}
54 	}
55 	return s.str();
56 }
57 
toLower(std::string & str)58 void toLower(std::string& str)
59 {
60 	for (std::size_t i = 0; i < str.length(); ++i)
61 	{
62 		str[i] = std::tolower(str[i]);
63 	}
64 }
65