From 10ab31fa86dbf9875b5f6baa6ac59fefaaf86be3 Mon Sep 17 00:00:00 2001 From: andreas 'randy' weinberger Date: Sun, 21 Feb 2010 19:58:27 +0100 Subject: initial git upload, based on graphlcd-base-0.1.5 --- glcdgraphics/common.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 glcdgraphics/common.c (limited to 'glcdgraphics/common.c') 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 + */ + +#include + +#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 -- cgit v1.2.3