Function StringRef

Summary

#include <include/rapidjson/document.h>

(1) template <typename CharType>
    GenericStringRef< CharType > StringRef(const CharType *str)

(2) template <typename CharType>
    GenericStringRef< CharType > StringRef(const CharType *str, size_t length)

(3) template <typename CharType>
    GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)

Function overload

Synopsis

#include <include/rapidjson/document.h>

template <typename CharType>
GenericStringRef< CharType > StringRef(const CharType *str)

Description

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.

Template Parameters

CharType - Character type of the string

Parameters

str - Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue

Returns
GenericStringRef string reference object
See
GenericValue::GenericValue(StringRefType), GenericValue::operator=(StringRefType), GenericValue::SetString(StringRefType), GenericValue::PushBack(StringRefType, Allocator&), GenericValue::AddMember

Source

Lines 453-456 in include/rapidjson/document.h.

template<typename CharType>
inline GenericStringRef<CharType> StringRef(const CharType* str) {
    return GenericStringRef<CharType>(str);
}

Synopsis

#include <include/rapidjson/document.h>

template <typename CharType>
GenericStringRef< CharType > StringRef(const CharType *str, size_t length)

Description

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.

Template Parameters

CharType - character type of the string

Parameters

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.

Returns
GenericStringRef string reference object

Source

Lines 473-476 in include/rapidjson/document.h.

template<typename CharType>
inline GenericStringRef<CharType> StringRef(const CharType* str, size_t length) {
    return GenericStringRef<CharType>(str, SizeType(length));
}

Synopsis

#include <include/rapidjson/document.h>

template <typename CharType>
GenericStringRef< CharType > StringRef(const std::basic_string< CharType > &str)

Description

Mark a string object as constant string.

Mark a string object (e.g. std::string) as a "string literal". This function can be used to avoid copying a string to be referenced as a value in a JSON GenericValue object, if the string's lifetime is known to be valid long enough.

Template Parameters

CharType - character type of the string

Parameters

str - Constant string, lifetime assumed to be longer than the use of the string in e.g. a GenericValue

Returns
GenericStringRef string reference object
Note
Requires the definition of the preprocessor symbol RAPIDJSON_HAS_STDSTRING.

Source

Lines 491-494 in include/rapidjson/document.h.

template<typename CharType>
inline GenericStringRef<CharType> StringRef(const std::basic_string<CharType>& str) {
    return GenericStringRef<CharType>(str.data(), SizeType(str.size()));
}





Add Discussion as Guest

Log in