Browse Source

Add explicit string literal overload to try to help Coverity (and

avoid a strlen call to boot).
Michael Hansen 11 years ago
parent
commit
fa1bb779e5
  1. 11
      Sources/Plasma/CoreLib/plString.h

11
Sources/Plasma/CoreLib/plString.h

@ -254,6 +254,13 @@ public:
*/ */
plString(const char *cstr, size_t size = STRLEN_AUTO) { IConvertFromUtf8(cstr, size); } plString(const char *cstr, size_t size = STRLEN_AUTO) { IConvertFromUtf8(cstr, size); }
/** Construct a plString from a string literal.
* \note This constructor expects the input to be UTF-8 encoded. For
* conversion from ISO-8859-1 8-bit data, use FromIso8859_1().
*/
template <size_t _Sz>
plString(const char (&literal)[_Sz]) { IConvertFromUtf8(literal, _Sz); }
/** Copy constructor. */ /** Copy constructor. */
plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { } plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { }
@ -269,6 +276,10 @@ public:
/** Assignment operator. Same as plString(const char *). */ /** Assignment operator. Same as plString(const char *). */
plString &operator=(const char *cstr) { IConvertFromUtf8(cstr, STRLEN_AUTO); return *this; } plString &operator=(const char *cstr) { IConvertFromUtf8(cstr, STRLEN_AUTO); return *this; }
/** Assignment operator. Same as plString(const char (&)[_Sz]). */
template <size_t _Sz>
plString &operator=(const char (&literal)[_Sz]) { IConvertFromUtf8(literal, _Sz); return *this; }
/** Assignment operator. Same as plString(const plString &). */ /** Assignment operator. Same as plString(const plString &). */
plString &operator=(const plString &copy) { fUtf8Buffer = copy.fUtf8Buffer; return *this; } plString &operator=(const plString &copy) { fUtf8Buffer = copy.fUtf8Buffer; return *this; }

Loading…
Cancel
Save