summaryrefslogtreecommitdiff
path: root/glcdgraphics/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'glcdgraphics/common.c')
-rw-r--r--glcdgraphics/common.c60
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