aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
Diffstat (limited to 'cores')
-rwxr-xr-xcores/arduino/Print.cpp4
-rw-r--r--cores/arduino/WString.cpp27
-rw-r--r--cores/arduino/WString.h4
3 files changed, 27 insertions, 8 deletions
diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp
index 6fe162d..4ee556d 100755
--- a/cores/arduino/Print.cpp
+++ b/cores/arduino/Print.cpp
@@ -45,7 +45,9 @@ void Print::write(const uint8_t *buffer, size_t size)
void Print::print(const String &s)
{
- print(s.toCharArray());
+ for (int i = 0; i < s.length(); i++) {
+ write(s[i]);
+ }
}
void Print::print(const char str[])
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index fd07c2d..2718956 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -169,7 +169,7 @@ int String::operator==( const String &rhs ) const
int String::operator!=( const String &rhs ) const
{
- return ( _length != rhs.length() || strcmp( _buffer, rhs.toCharArray() ) != 0 );
+ return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
}
int String::operator<( const String &rhs ) const
@@ -213,7 +213,7 @@ boolean String::endsWith( const String &s2 ) const
if ( _length < s2._length )
return 0;
- return strcmp( &_buffer[ _length - s2._length], s2.toCharArray() ) == 0;
+ return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
}
boolean String::equals( const String &s2 ) const
@@ -228,7 +228,7 @@ boolean String::equalsIgnoreCase( const String &s2 ) const
else if ( _length != s2._length )
return false; //0;
- return strcmp(toLowerCase().toCharArray(), s2.toLowerCase().toCharArray()) == 0;
+ return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
}
String String::replace( char findChar, char replaceChar )
@@ -285,7 +285,7 @@ int String::indexOf( const String &s2, unsigned int fromIndex ) const
if ( fromIndex >= _length )
return -1;
- const char *theFind = strstr( &_buffer[ fromIndex ], s2.toCharArray() );
+ const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
if ( theFind == NULL )
return -1;
@@ -349,7 +349,7 @@ boolean String::startsWith( const String &s2, unsigned int offset ) const
if ( offset > _length - s2._length )
return 0;
- return strncmp( &_buffer[offset], s2.toCharArray(), s2._length ) == 0;
+ return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
}
String String::substring( unsigned int left ) const
@@ -417,3 +417,20 @@ String String::trim() const
return temp.substring( i, j + 1);
}
+void String::getBytes(unsigned char *buf, unsigned int bufsize)
+{
+ if (!bufsize || !buf) return;
+ unsigned int len = bufsize - 1;
+ if (len > _length) len = _length;
+ strncpy((char *)buf, _buffer, len);
+ buf[len] = 0;
+}
+
+void String::toCharArray(char *buf, unsigned int bufsize)
+{
+ if (!bufsize || !buf) return;
+ unsigned int len = bufsize - 1;
+ if (len > _length) len = _length;
+ strncpy(buf, _buffer, len);
+ buf[len] = 0;
+}
diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h
index eede8ae..fb87c52 100644
--- a/cores/arduino/WString.h
+++ b/cores/arduino/WString.h
@@ -76,8 +76,8 @@ class String
String toLowerCase( ) const;
String toUpperCase( ) const;
String trim( ) const;
- const unsigned char *getBytes() const { return (unsigned char*)_buffer; }
- const char* toCharArray() const { return _buffer; }
+ void getBytes(unsigned char *buf, unsigned int bufsize);
+ void toCharArray(char *buf, unsigned int bufsize);
const String& concat( const String &str );
String replace( char oldChar, char newChar );
String replace( const String& match, const String& replace );