Skip to content

Strings without null-termination #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 25, 2021
Prev Previous commit
Next Next commit
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.
  • Loading branch information
matthijskooijman committed Jan 25, 2021
commit 84314888a8a73b643469c5609beed6d21d1c037a
6 changes: 6 additions & 0 deletions api/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ String::String(const char *cstr)
if (cstr) copy(cstr, strlen(cstr));
}

String::String(const char *cstr, unsigned int length)
{
init();
if (cstr) copy(cstr, length);
}

String::String(const String &value)
{
init();
Expand Down
1 change: 1 addition & 0 deletions api/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class String
// fails, the string will be marked as invalid (i.e. "if (s)" will
// be false).
String(const char *cstr = "");
String(const char *cstr, unsigned int length);
String(const String &str);
String(const __FlashStringHelper *str);
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
Expand Down