Untitled diff

Erstellt Diff läuft nie ab
33 Entfernungen
225 Zeilen
28 Hinzufügungen
219 Zeilen
/*
/*
WString.h - String library for Wiring & Arduino
WString.h - String library for Wiring & Arduino
...mostly rewritten by Paul Stoffregen...
...mostly rewritten by Paul Stoffregen...
Copyright (c) 2009-10 Hernando Barragan. All right reserved.
Copyright (c) 2009-10 Hernando Barragan. All right reserved.
Copyright 2011, Paul Stoffregen, paul@pjrc.com
Copyright 2011, Paul Stoffregen, paul@pjrc.com


This library is free software; you can redistribute it and/or
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
version 2.1 of the License, or (at your option) any later version.


This library is distributed in the hope that it will be useful,
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Lesser General Public License for more details.


You should have received a copy of the GNU Lesser General Public
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/


#ifndef String_class_h
#ifndef String_class_h
#define String_class_h
#define String_class_h
#ifdef __cplusplus
#ifdef __cplusplus


#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include <avr/pgmspace.h>
#include <avr/pgmspace.h>


// When compiling programs with this class, the following gcc parameters
// When compiling programs with this class, the following gcc parameters
// dramatically increase performance and memory (RAM) efficiency, typically
// dramatically increase performance and memory (RAM) efficiency, typically
// with little or no increase in code size.
// with little or no increase in code size.
// -felide-constructors
// -felide-constructors
// -std=c++0x
// -std=c++0x


class __FlashStringHelper;
class __FlashStringHelper;
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))


// An inherited class for holding the result of a concatenation. These
// An inherited class for holding the result of a concatenation. These
// result objects are assumed to be writable by subsequent concatenations.
// result objects are assumed to be writable by subsequent concatenations.
class StringSumHelper;
class StringSumHelper;


// The string class
// The string class
class String
class String
{
{
// use a function pointer to allow for "if (s)" without the
// use a function pointer to allow for "if (s)" without the
// complications of an operator bool(). for more information, see:
// complications of an operator bool(). for more information, see:
// http://www.artima.com/cppsource/safebool.html
// http://www.artima.com/cppsource/safebool.html
typedef void (String::*StringIfHelperType)() const;
typedef void (String::*StringIfHelperType)() const;
void StringIfHelper() const {}
void StringIfHelper() const {}


public:
public:
// constructors
// constructors
// creates a copy of the initial value.
// creates a copy of the initial value.
// if the initial value is null or invalid, or if memory allocation
// if the initial value is null or invalid, or if memory allocation
// fails, the string will be marked as invalid (i.e. "if (s)" will
// fails, the string will be marked as invalid (i.e. "if (s)" will
// be false).
// be false).
String(const char *cstr = "");
String(const char *cstr = "");
String(const String &str);
String(const String &str);
String(const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String(String &&rval);
String(String &&rval);
String(StringSumHelper &&rval);
String(StringSumHelper &&rval);
#endif
#endif
explicit String(char c);
explicit String(char c);
explicit String(unsigned char, unsigned char base=10);
explicit String(unsigned char, unsigned char base=10);
explicit String(int, unsigned char base=10);
explicit String(int, unsigned char base=10);
explicit String(unsigned int, unsigned char base=10);
explicit String(unsigned int, unsigned char base=10);
explicit String(long, unsigned char base=10);
explicit String(long, unsigned char base=10);
explicit String(unsigned long, unsigned char base=10);
explicit String(unsigned long, unsigned char base=10);
explicit String(float, unsigned char decimalPlaces=2);
explicit String(double, unsigned char decimalPlaces=2);
~String(void);
~String(void);


// memory management
// memory management
// return true on success, false on failure (in which case, the string
// return true on success, false on failure (in which case, the string
// is left unchanged). reserve(0), if successful, will validate an
// is left unchanged). reserve(0), if successful, will validate an
// invalid string (i.e., "if (s)" will be true afterwards)
// invalid string (i.e., "if (s)" will be true afterwards)
unsigned char reserve(unsigned int size);
unsigned char reserve(unsigned int size);
inline unsigned int length(void) const {return len;}
inline unsigned int length(void) const {return len;}


// creates a copy of the assigned value. if the value is null or
// creates a copy of the assigned value. if the value is null or
// invalid, or if the memory allocation fails, the string will be
// invalid, or if the memory allocation fails, the string will be
// marked as invalid ("if (s)" will be false).
// marked as invalid ("if (s)" will be false).
String & operator = (const String &rhs);
String & operator = (const String &rhs);
String & operator = (const char *cstr);
String & operator = (const char *cstr);
String & operator = (const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String & operator = (String &&rval);
String & operator = (String &&rval);
String & operator = (StringSumHelper &&rval);
String & operator = (StringSumHelper &&rval);
#endif
#endif


// concatenate (works w/ built-in types)
// concatenate (works w/ built-in types)

// returns true on success, false on failure (in which case, the string
// returns true on success, false on failure (in which case, the string
// is left unchanged). if the argument is null or invalid, the
// is left unchanged). if the argument is null or invalid, the
// concatenation is considered unsucessful.
// concatenation is considered unsucessful.
unsigned char concat(const String &str);
unsigned char concat(const String &str);
unsigned char concat(const char *cstr);
unsigned char concat(const char *cstr);
unsigned char concat(char c);
unsigned char concat(char c);
unsigned char concat(unsigned char c);
unsigned char concat(unsigned char c);