Skip to content

Commit 581941e

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 76de157 commit 581941e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Diff for: api/String.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();

Diff for: api/String.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class String
6161
// fails, the string will be marked as invalid (i.e. "if (s)" will
6262
// be false).
6363
String(const char *cstr = "");
64+
String(const char *cstr, unsigned int length);
6465
String(const String &str);
6566
String(const __FlashStringHelper *str);
6667
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)

0 commit comments

Comments
 (0)