123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- #ifndef String_class_h
- #define String_class_h
- #ifdef __cplusplus
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <avr/pgmspace.h>
- class __FlashStringHelper;
- #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
- class StringSumHelper;
- class String
- {
-
-
-
- typedef void (String::*StringIfHelperType)() const;
- void StringIfHelper() const {}
- public:
-
-
-
-
-
- String(const char *cstr = "");
- String(const String &str);
- #ifdef __GXX_EXPERIMENTAL_CXX0X__
- String(String &&rval);
- String(StringSumHelper &&rval);
- #endif
- explicit String(char c);
- explicit String(unsigned char, unsigned char base=10);
- explicit String(int, unsigned char base=10);
- explicit String(unsigned int, unsigned char base=10);
- explicit String(long, unsigned char base=10);
- explicit String(unsigned long, unsigned char base=10);
- ~String(void);
-
-
-
-
- unsigned char reserve(unsigned int size);
- inline unsigned int length(void) const {return len;}
-
-
-
- String & operator = (const String &rhs);
- String & operator = (const char *cstr);
- #ifdef __GXX_EXPERIMENTAL_CXX0X__
- String & operator = (String &&rval);
- String & operator = (StringSumHelper &&rval);
- #endif
-
-
-
-
-
- unsigned char concat(const String &str);
- unsigned char concat(const char *cstr);
- unsigned char concat(char c);
- unsigned char concat(unsigned char c);
- unsigned char concat(int num);
- unsigned char concat(unsigned int num);
- unsigned char concat(long num);
- unsigned char concat(unsigned long num);
-
-
-
- String & operator += (const String &rhs) {concat(rhs); return (*this);}
- String & operator += (const char *cstr) {concat(cstr); return (*this);}
- String & operator += (char c) {concat(c); return (*this);}
- String & operator += (unsigned char num) {concat(num); return (*this);}
- String & operator += (int num) {concat(num); return (*this);}
- String & operator += (unsigned int num) {concat(num); return (*this);}
- String & operator += (long num) {concat(num); return (*this);}
- String & operator += (unsigned long num) {concat(num); return (*this);}
- friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
- friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
-
- operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
- int compareTo(const String &s) const;
- unsigned char equals(const String &s) const;
- unsigned char equals(const char *cstr) const;
- unsigned char operator == (const String &rhs) const {return equals(rhs);}
- unsigned char operator == (const char *cstr) const {return equals(cstr);}
- unsigned char operator != (const String &rhs) const {return !equals(rhs);}
- unsigned char operator != (const char *cstr) const {return !equals(cstr);}
- unsigned char operator < (const String &rhs) const;
- unsigned char operator > (const String &rhs) const;
- unsigned char operator <= (const String &rhs) const;
- unsigned char operator >= (const String &rhs) const;
- unsigned char equalsIgnoreCase(const String &s) const;
- unsigned char startsWith( const String &prefix) const;
- unsigned char startsWith(const String &prefix, unsigned int offset) const;
- unsigned char endsWith(const String &suffix) const;
-
- char charAt(unsigned int index) const;
- void setCharAt(unsigned int index, char c);
- char operator [] (unsigned int index) const;
- char& operator [] (unsigned int index);
- void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
- void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
- {getBytes((unsigned char *)buf, bufsize, index);}
-
- int indexOf( char ch ) const;
- int indexOf( char ch, unsigned int fromIndex ) const;
- int indexOf( const String &str ) const;
- int indexOf( const String &str, unsigned int fromIndex ) const;
- int lastIndexOf( char ch ) const;
- int lastIndexOf( char ch, unsigned int fromIndex ) const;
- int lastIndexOf( const String &str ) const;
- int lastIndexOf( const String &str, unsigned int fromIndex ) const;
- String substring( unsigned int beginIndex ) const;
- String substring( unsigned int beginIndex, unsigned int endIndex ) const;
-
- void replace(char find, char replace);
- void replace(const String& find, const String& replace);
- void toLowerCase(void);
- void toUpperCase(void);
- void trim(void);
-
- long toInt(void) const;
- protected:
- char *buffer;
- unsigned int capacity;
- unsigned int len;
- unsigned char flags;
- protected:
- void init(void);
- void invalidate(void);
- unsigned char changeBuffer(unsigned int maxStrLen);
- unsigned char concat(const char *cstr, unsigned int length);
-
- String & copy(const char *cstr, unsigned int length);
- #ifdef __GXX_EXPERIMENTAL_CXX0X__
- void move(String &rhs);
- #endif
- };
- class StringSumHelper : public String
- {
- public:
- StringSumHelper(const String &s) : String(s) {}
- StringSumHelper(const char *p) : String(p) {}
- StringSumHelper(char c) : String(c) {}
- StringSumHelper(unsigned char num) : String(num) {}
- StringSumHelper(int num) : String(num) {}
- StringSumHelper(unsigned int num) : String(num) {}
- StringSumHelper(long num) : String(num) {}
- StringSumHelper(unsigned long num) : String(num) {}
- };
- #endif
- #endif
|