Skip to content

Commit 7f2eca2

Browse files
Add String(char *, unsigned) constructor
This constructor allows converting a buffer containing a non-nul-terminated string to a String object, by explicitely passing the length.
1 parent 74a66a7 commit 7f2eca2

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

hardware/arduino/avr/cores/arduino/WString.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ String::String(const char *cstr)
3131
if (cstr) copy(cstr, strlen(cstr));
3232
}
3333

34+
String::String(const char *cstr, unsigned int length)
35+
{
36+
init();
37+
if (cstr) copy(cstr, length);
38+
}
39+
3440
String::String(const String &value)
3541
{
3642
init();

hardware/arduino/avr/cores/arduino/WString.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class String
5757
// fails, the string will be marked as invalid (i.e. "if (s)" will
5858
// be false).
5959
String(const char *cstr = "");
60+
String(const char *cstr, unsigned int length);
6061
String(const String &str);
6162
String(const __FlashStringHelper *str);
6263
#ifdef __GXX_EXPERIMENTAL_CXX0X__

hardware/arduino/sam/cores/arduino/WString.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ String::String(const char *cstr)
3333
if (cstr) copy(cstr, strlen(cstr));
3434
}
3535

36+
String::String(const char *cstr, unsigned int length)
37+
{
38+
init();
39+
if (cstr) copy(cstr, length);
40+
}
41+
3642
String::String(const String &value)
3743
{
3844
init();

hardware/arduino/sam/cores/arduino/WString.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class String
5757
// fails, the string will be marked as invalid (i.e. "if (s)" will
5858
// be false).
5959
String(const char *cstr = "");
60+
String(const char *cstr, unsigned int length);
6061
String(const String &str);
6162
String(const __FlashStringHelper *str);
6263
#ifdef __GXX_EXPERIMENTAL_CXX0X__

0 commit comments

Comments
 (0)