00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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__