diff options
author | andreas 'randy' weinberger <vdr@smue.org> | 2010-02-21 19:58:27 +0100 |
---|---|---|
committer | andreas 'randy' weinberger <vdr@smue.org> | 2010-02-21 19:58:27 +0100 |
commit | 10ab31fa86dbf9875b5f6baa6ac59fefaaf86be3 (patch) | |
tree | 60ad7c856565f03e145b2996d1bb5f9cd64c0532 /glcdgraphics/common.c | |
download | graphlcd-base-10ab31fa86dbf9875b5f6baa6ac59fefaaf86be3.tar.gz graphlcd-base-10ab31fa86dbf9875b5f6baa6ac59fefaaf86be3.tar.bz2 |
initial git upload, based on graphlcd-base-0.1.5
Diffstat (limited to 'glcdgraphics/common.c')
-rw-r--r-- | glcdgraphics/common.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/glcdgraphics/common.c b/glcdgraphics/common.c new file mode 100644 index 0000000..8942424 --- /dev/null +++ b/glcdgraphics/common.c @@ -0,0 +1,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 |