|
| template<SizeType N> |
| | GenericStringRef (const CharType(&str)[N]) RAPIDJSON_NOEXCEPT |
| | Create string reference from const character array
|
| | GenericStringRef (const CharType *str) |
| | Explicitly create string reference from const character pointer
|
| | GenericStringRef (const CharType *str, SizeType len) |
| | Create constant string reference from pointer and length
|
|
| GenericStringRef (const GenericStringRef &rhs) |
|
| operator const Ch * () const |
| | implicit conversion to plain CharType pointer
|
template<typename CharType>
struct rapidjson::GenericStringRef< CharType >
Reference to a constant string (not taking a copy)
- 模板参数
-
| CharType | character type of the string |
This helper class is used to automatically infer constant string references for string literals, especially from const (!) character arrays.
The main use is for creating JSON string values without copying the source string via an 分配器. This requires that the referenced string pointers have a sufficient lifetime, which exceeds the lifetime of the associated GenericValue.
Example
const char foo[] = "foo";
v.SetString(foo);
const char* bar = foo;
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding
定义 document.h:2008
GenericStringRef< CharType > StringRef(const CharType *str)
Mark a character pointer as constant string
定义 document.h:344
- 参见
- StringRef, GenericValue::SetString
template<typename CharType>
Mark a character pointer as constant string
Mark a plain character pointer as a "string literal". This function can be used to avoid copying a character string to be referenced as a value in a JSON GenericValue object, if the string's lifetime is known to be valid long enough.
This version has better performance with supplied length, and also supports string containing null characters.
- 模板参数
-
| CharType | character type of the string |
- 参数
-
| str | Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue |
| length | The length of source string. |
- 返回
- GenericStringRef string reference object