Skip to content

Commit 8431488

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 3b88aca commit 8431488

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
@@ -45,6 +45,12 @@ String::String(const char *cstr)
4545
if (cstr) copy(cstr, strlen(cstr));
4646
}
4747

48+
String::String(const char *cstr, unsigned int length)
49+
{
50+
init();
51+
if (cstr) copy(cstr, length);
52+
}
53+
4854
String::String(const String &value)
4955
{
5056
init();

Diff for: api/String.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class String
6868
// fails, the string will be marked as invalid (i.e. "if (s)" will
6969
// be false).
7070
String(const char *cstr = "");
71+
String(const char *cstr, unsigned int length);
7172
String(const String &str);
7273
String(const __FlashStringHelper *str);
7374
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)

0 commit comments

Comments
 (0)