chromium/third_party/blink/renderer/platform/wtf/text/text_codec_cjk.cc

/*
 * Copyright (C) 2020 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/platform/wtf/text/text_codec_cjk.h"

#include <utility>

#include "base/feature_list.h"
#include "base/functional/function_ref.h"
#include "base/memory/ptr_util.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/encoding_tables.h"
#include "third_party/blink/renderer/platform/wtf/text/string_concatenate.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace WTF {

class TextCodecCJK::Decoder {};

namespace {

constexpr char kCanonicalNameEucJp[] =;
constexpr char kCanonicalNameShiftJis[] =;
constexpr char kCanonicalNameEucKr[] =;
constexpr char kCanonicalNameIso2022Jp[] =;
constexpr char kCanonicalNameGbk[] =;
constexpr char kCanonicalNameGb18030[] =;

constexpr std::array<const char*, 6> kSupportedCanonicalNames{};

void AppendUnencodableReplacement(UChar32 code_point,
                                  UnencodableHandling handling,
                                  Vector<uint8_t>& result) {}

std::optional<UChar> FindCodePointInJis0208(uint16_t pointer) {}

std::optional<UChar> FindCodePointJis0212(uint16_t pointer) {}

// https://encoding.spec.whatwg.org/#euc-jp-encoder
Vector<uint8_t> EncodeEucJp(StringView string, UnencodableHandling handling) {}

class Iso2022JpEncoder {};

// https://encoding.spec.whatwg.org/#iso-2022-jp-encoder
Vector<uint8_t> EncodeIso2022Jp(StringView string,
                                UnencodableHandling handling) {}

// https://encoding.spec.whatwg.org/#shift_jis-encoder
Vector<uint8_t> EncodeShiftJis(StringView string,
                               UnencodableHandling handling) {}

// https://encoding.spec.whatwg.org/#euc-kr-encoder
Vector<uint8_t> EncodeEucKr(StringView string, UnencodableHandling handling) {}

// https://encoding.spec.whatwg.org/index-gb18030-ranges.txt
const std::array<std::pair<uint32_t, UChar32>, 207>& Gb18030Ranges() {}

// https://encoding.spec.whatwg.org/#index-gb18030-ranges-code-point
std::optional<UChar32> IndexGb18030RangesCodePoint(uint32_t pointer) {}

// https://encoding.spec.whatwg.org/#index-gb18030-ranges-pointer
uint32_t Gb18030RangesPointer(UChar32 code_point) {}

// https://unicode-org.atlassian.net/browse/ICU-22357
// TODO(yyanagisawa): rename function names in comment
// The 2-byte values are handled correctly by values from gb18030()
// but these need to be exceptions from gb18030Ranges().
static std::optional<uint32_t> Gb18030_2022Encode(UChar32 codePoint) {}
static std::optional<UChar32> Gb18030_2022Decode(uint8_t first,
                                                 uint8_t second,
                                                 uint8_t third,
                                                 uint8_t fourth) {}

// https://encoding.spec.whatwg.org/#gb18030-encoder
enum class IsGbk : bool {};
Vector<uint8_t> EncodeGbShared(StringView string,
                               UnencodableHandling handling,
                               IsGbk is_gbk) {}

Vector<uint8_t> EncodeGb18030(StringView string, UnencodableHandling handling) {}

Vector<uint8_t> EncodeGbk(StringView string, UnencodableHandling handling) {}

// https://encoding.spec.whatwg.org/#euc-jp-decoder
class EucJpDecoder : public TextCodecCJK::Decoder {};

// https://encoding.spec.whatwg.org/#iso-2022-jp-decoder
class Iso2022JpDecoder : public TextCodecCJK::Decoder {};

// https://encoding.spec.whatwg.org/#shift_jis-decoder
class ShiftJisDecoder : public TextCodecCJK::Decoder {};

// https://encoding.spec.whatwg.org/#euc-kr-decoder
class EucKrDecoder : public TextCodecCJK::Decoder {};

// https://encoding.spec.whatwg.org/#gb18030-decoder
// https://encoding.spec.whatwg.org/#gbk-decoder
// Note that the same decoder is used for GB18030 and GBK.
class Gb18030Decoder : public TextCodecCJK::Decoder {};

}  // namespace

enum class TextCodecCJK::Encoding : uint8_t {};

TextCodecCJK::TextCodecCJK(Encoding encoding) :{}

void TextCodecCJK::RegisterEncodingNames(EncodingNameRegistrar registrar) {}

void TextCodecCJK::RegisterCodecs(TextCodecRegistrar registrar) {}

std::unique_ptr<TextCodec> TextCodecCJK::Create(const TextEncoding& encoding,
                                                const void*) {}

String TextCodecCJK::Decoder::Decode(const uint8_t* bytes,
                                     wtf_size_t length,
                                     bool flush,
                                     bool stop_on_error,
                                     bool& saw_error) {}

String TextCodecCJK::Decode(const char* charBytes,
                            wtf_size_t length,
                            FlushBehavior flush_behavior,
                            bool stop_on_error,
                            bool& saw_error) {}

Vector<uint8_t> TextCodecCJK::EncodeCommon(StringView string,
                                           UnencodableHandling handling) const {}

std::string TextCodecCJK::Encode(const UChar* characters,
                                 wtf_size_t length,
                                 UnencodableHandling handling) {}

std::string TextCodecCJK::Encode(const LChar* characters,
                                 wtf_size_t length,
                                 UnencodableHandling handling) {}

// static
bool TextCodecCJK::IsSupported(StringView name) {}

}  // namespace WTF