blob: 8942424cfa2a355218b8cb0e96819abbdfdc9f66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
* GraphLCD graphics library
*
* common.c - various functions
*
* This file is released under the GNU General Public License. Refer
* to the COPYING file distributed with this package.
*
* (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
*/
#include <ctype.h>
#include "common.h"
namespace GLCD
{
void clip(int & value, int min, int max)
{
if (value < min)
value = min;
if (value > max)
value = max;
}
void sort(int & value1, int & value2)
{
if (value2 < value1)
{
int tmp;
tmp = value2;
value2 = value1;
value1 = tmp;
}
}
std::string trim(const std::string & s)
{
std::string::size_type start, end;
start = 0;
while (start < s.length())
{
if (!isspace(s[start]))
break;
start++;
}
end = s.length() - 1;
while (end >= 0)
{
if (!isspace(s[end]))
break;
end--;
}
return s.substr(start, end - start + 1);
}
} // end of namespace
|