graphlcd-base/glcdgraphics/common.c
changeset 4 df6a40031aa5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/graphlcd-base/glcdgraphics/common.c	Wed Feb 06 17:32:55 2008 +0000
     1.3 @@ -0,0 +1,60 @@
     1.4 +/*
     1.5 + * GraphLCD graphics library
     1.6 + *
     1.7 + * common.c  -  various functions
     1.8 + *
     1.9 + * This file is released under the GNU General Public License. Refer
    1.10 + * to the COPYING file distributed with this package.
    1.11 + *
    1.12 + * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
    1.13 + */
    1.14 +
    1.15 +#include <ctype.h>
    1.16 +
    1.17 +#include "common.h"
    1.18 +
    1.19 +
    1.20 +namespace GLCD
    1.21 +{
    1.22 +
    1.23 +void clip(int & value, int min, int max)
    1.24 +{
    1.25 +    if (value < min)
    1.26 +        value = min;
    1.27 +    if (value > max)
    1.28 +        value = max;
    1.29 +}
    1.30 +
    1.31 +void sort(int & value1, int & value2)
    1.32 +{
    1.33 +    if (value2 < value1)
    1.34 +    {
    1.35 +        int tmp;
    1.36 +        tmp = value2;
    1.37 +        value2 = value1;
    1.38 +        value1 = tmp;
    1.39 +    }
    1.40 +}
    1.41 +
    1.42 +std::string trim(const std::string & s)
    1.43 +{
    1.44 +	std::string::size_type start, end;
    1.45 +
    1.46 +	start = 0;
    1.47 +	while (start < s.length())
    1.48 +	{
    1.49 +		if (!isspace(s[start]))
    1.50 +			break;
    1.51 +		start++;
    1.52 +	}
    1.53 +	end = s.length() - 1;
    1.54 +	while (end >= 0)
    1.55 +	{
    1.56 +		if (!isspace(s[end]))
    1.57 +			break;
    1.58 +		end--;
    1.59 +	}
    1.60 +	return s.substr(start, end - start + 1);
    1.61 +}
    1.62 +
    1.63 +} // end of namespace