Skip to content

Commit 53df991

Browse files
matthijskooijmanaentinger
authored andcommitted
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 eaca5bf commit 53df991

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
@@ -35,6 +35,12 @@ String::String(const char *cstr)
3535
if (cstr) copy(cstr, strlen(cstr));
3636
}
3737

38+
String::String(const char *cstr, unsigned int length)
39+
{
40+
init();
41+
if (cstr) copy(cstr, length);
42+
}
43+
3844
String::String(const String &value)
3945
{
4046
init();

Diff for: api/String.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class String
6565
// fails, the string will be marked as invalid (i.e. "if (s)" will
6666
// be false).
6767
String(const char *cstr = "");
68+
String(const char *cstr, unsigned int length);
6869
String(const String &str);
6970
String(const __FlashStringHelper *str);
7071
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)

0 commit comments

Comments
 (0)