Struct Transcoder

Synopsis

#include <include/rapidjson/encodings.h>

template<typename SourceEncoding, typename TargetEncoding>
struct Transcoder

Description

Encoding conversion.

Mentioned in

Methods

TranscodeTake one Unicode codepoint from source encoding, convert it to target encoding and put it to the output stream.
TranscodeUnsafe
ValidateValidate one Unicode codepoint from an encoded stream.

Source

Lines 657-683 in include/rapidjson/encodings.h.

template<typename SourceEncoding, typename TargetEncoding>
struct Transcoder {
    //! Take one Unicode codepoint from source encoding, convert it to target encoding and put it to the output stream.
    template<typename InputStream, typename OutputStream>
    static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) {
        unsigned codepoint;
        if (!SourceEncoding::Decode(is, &codepoint))
            return false;
        TargetEncoding::Encode(os, codepoint);
        return true;
    }

    template<typename InputStream, typename OutputStream>
    static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) {
        unsigned codepoint;
        if (!SourceEncoding::Decode(is, &codepoint))
            return false;
        TargetEncoding::EncodeUnsafe(os, codepoint);
        return true;
    }

    //! Validate one Unicode codepoint from an encoded stream.
    template<typename InputStream, typename OutputStream>
    static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) {
        return Transcode(is, os);   // Since source/target encoding is different, must transcode.
    }
};





Add Discussion as Guest

Log in