My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. WString.h - String library for Wiring & Arduino
  3. Copyright (c) 2009-10 Hernando Barragan. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. #ifndef String_h
  17. #define String_h
  18. //#include "WProgram.h"
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. class String
  23. {
  24. public:
  25. // constructors
  26. String( const char *value = "" );
  27. String( const String &value );
  28. String( const char );
  29. String( const unsigned char );
  30. String( const int, const int base=10);
  31. String( const unsigned int, const int base=10 );
  32. String( const long, const int base=10 );
  33. String( const unsigned long, const int base=10 );
  34. ~String() { free(_buffer); _length = _capacity = 0;} //added _length = _capacity = 0;
  35. // operators
  36. const String & operator = ( const String &rhs );
  37. const String & operator +=( const String &rhs );
  38. //const String & operator +=( const char );
  39. int operator ==( const String &rhs ) const;
  40. int operator !=( const String &rhs ) const;
  41. int operator < ( const String &rhs ) const;
  42. int operator > ( const String &rhs ) const;
  43. int operator <=( const String &rhs ) const;
  44. int operator >=( const String &rhs ) const;
  45. char operator []( unsigned int index ) const;
  46. char& operator []( unsigned int index );
  47. //operator const char *() const { return _buffer; }
  48. // general methods
  49. char charAt( unsigned int index ) const;
  50. int compareTo( const String &anotherString ) const;
  51. unsigned char endsWith( const String &suffix ) const;
  52. unsigned char equals( const String &anObject ) const;
  53. unsigned char equalsIgnoreCase( const String &anotherString ) const;
  54. int indexOf( char ch ) const;
  55. int indexOf( char ch, unsigned int fromIndex ) const;
  56. int indexOf( const String &str ) const;
  57. int indexOf( const String &str, unsigned int fromIndex ) const;
  58. int lastIndexOf( char ch ) const;
  59. int lastIndexOf( char ch, unsigned int fromIndex ) const;
  60. int lastIndexOf( const String &str ) const;
  61. int lastIndexOf( const String &str, unsigned int fromIndex ) const;
  62. const unsigned int length( ) const { return _length; }
  63. void setCharAt(unsigned int index, const char ch);
  64. unsigned char startsWith( const String &prefix ) const;
  65. unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
  66. String substring( unsigned int beginIndex ) const;
  67. String substring( unsigned int beginIndex, unsigned int endIndex ) const;
  68. String toLowerCase( ) const;
  69. String toUpperCase( ) const;
  70. String trim( ) const;
  71. void getBytes(unsigned char *buf, unsigned int bufsize);
  72. void toCharArray(char *buf, unsigned int bufsize);
  73. long toInt( );
  74. const String& concat( const String &str );
  75. String replace( char oldChar, char newChar );
  76. String replace( const String& match, const String& replace );
  77. friend String operator + ( String lhs, const String &rhs );
  78. protected:
  79. char *_buffer; // the actual char array
  80. unsigned int _capacity; // the array length minus one (for the '\0')
  81. unsigned int _length; // the String length (not counting the '\0')
  82. void getBuffer(unsigned int maxStrLen);
  83. private:
  84. };
  85. // allocate buffer space
  86. inline void String::getBuffer(unsigned int maxStrLen)
  87. {
  88. _capacity = maxStrLen;
  89. _buffer = (char *) malloc(_capacity + 1);
  90. if (_buffer == NULL) _length = _capacity = 0;
  91. }
  92. inline String operator+( String lhs, const String &rhs )
  93. {
  94. return lhs += rhs;
  95. }
  96. #endif