avr/cpp/collection/StrDefs.h

Go to the documentation of this file.
00001 /**********************************************************************************************************************\
00002 
00003         C++ library for Atmel AVR microcontrollers
00004         Copyright (C) 2007 Lauri Kirikal, Mikk Leini, MT� TT� Robotiklubi
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program is distributed in the hope that it will be useful,
00012         but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License
00017         along with this program; if not, write to the Free Software
00018         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 
00020         See http://creativecommons.org/licenses/GPL/2.0/
00021 
00022         MT� TT� Robotiklubi  http://www.robotiklubi.ee robotiklubi@gmail.com
00023         Lauri Kirikal        laurikirikal@gmail.com
00024         Mikk Leini           mikk.leini@gmail.com
00025 
00026 \**********************************************************************************************************************/
00027 
00028 #ifndef __AVR_CPP_STRING_DEFINITIONS_H__
00029 #define __AVR_CPP_STRING_DEFINITIONS_H__
00030 
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <stdio.h>
00034 
00035 #define STR_NULL ""
00036 #define END_LINE "\x0D\x0A"
00037 
00038 typedef char                    char_t;
00039 typedef const char_t    cchar_t;
00040 typedef char_t *                str_t;
00041 typedef const char_t *  cstr_t;
00042 
00043 inline uint16_t StrLength(const char *s) { return (uint16_t)strlen(s); }
00044 inline char *   StrJoin(char *dest, const char *src) { return strcat(dest, src); }
00045 inline int              StrCompare(const char *s1, const char *s2) { return strcmp(s1, s2); }
00046 inline int              StrICompare(const char *s1, const char *s2) { return strcasecmp(s1, s2); }
00047 inline int              StrNCompare(const char *s1, const char *s2, size_t  maxlen) { return strncmp(s1, s2, maxlen); }
00048 inline int              StrNICompare(const char *s1, const char *s2, size_t maxlen) { return strncasecmp(s1, s2, maxlen); }
00049 inline char     *       StrCopy(char *dest, const char *src) { return strcpy(dest, src); }
00050 inline char *   StrNCopy(char *dest, const char *src, size_t maxlen) { return strncpy(dest, src, maxlen); }
00051 inline int              ToInteger(const char *s) { return atoi(s); }
00052 inline double   ToDouble(const char *s) { return atof(s); }
00053 inline double   ToDoubleEx(const char *s, char **endptr) { return strtod(s, endptr); }
00054 inline char *   ToString(int value, char *string, int radix) { return itoa(value, string, radix); }
00055 inline int              DoubleToString(char *buffer, double value) { return sprintf(buffer, "%f", value); }
00056 inline char *   FindChar(char *s, int c, size_t n) { return (char *)memchr((void *)s, c, n); }
00057 inline char *   StrAlloc(size_t size) { return (char *)malloc(size * sizeof(char)); }
00058 inline char *   StrRealloc(char *block, size_t size) { return (char *)realloc((char *)block, size * sizeof(char)); }
00059 inline char *   StrToUpper(char *s) { return strupr(s); }
00060 inline char *   StrToLower(char *s) { return strlwr(s); }
00061 inline char *   StrFind(const char *s1, const char *s2) { return strstr(s1, s2); }
00062 inline char *   StrIFind(const char *s1, const char *s2) { return strcasestr(s1, s2); }
00063 
00064 #endif // ifndef __AVR_CPP_STRING_DEFINITIONS_H__

Generated on Sat Sep 15 23:41:46 2007 for AVR C++ Lib (common) by  doxygen 1.5.2
SourceForge.net Logo MTÜ TTÜ Robotiklubi