Skip to content

Commit 8289b2d

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 015b004 commit 8289b2d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-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__

0 commit comments

Comments
 (0)