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