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

/*
 * Copyright (C) 2004, 2006, 2008, 2011 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 COMPUTER, 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 COMPUTER, 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_utf8.h"

#include <memory>
#include <variant>
#include "base/memory/ptr_util.h"
#include "base/numerics/checked_math.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/string_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/text_codec_ascii_fast_path.h"

namespace WTF {

// We'll use nonCharacter* constants to signal invalid utf-8.
// The number in the name signals how many input bytes were invalid.
const int kNonCharacter1 =;
const int kNonCharacter2 =;
const int kNonCharacter3 =;

bool IsNonCharacter(int character) {}

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

void TextCodecUTF8::RegisterEncodingNames(EncodingNameRegistrar registrar) {}

void TextCodecUTF8::RegisterCodecs(TextCodecRegistrar registrar) {}

static constexpr uint8_t kNonASCIISequenceLength[256] =;

static inline int DecodeNonASCIISequence(const uint8_t* sequence,
                                         unsigned length) {}

static inline UChar* AppendCharacter(UChar* destination, int character) {}

void TextCodecUTF8::ConsumePartialSequenceBytes(int num_bytes) {}

void TextCodecUTF8::HandleError(int character,
                                UChar*& destination,
                                bool stop_on_error,
                                bool& saw_error) {}

template <>
bool TextCodecUTF8::HandlePartialSequence<LChar>(LChar*& destination,
                                                 const uint8_t*& source,
                                                 const uint8_t* end,
                                                 bool flush,
                                                 bool,
                                                 bool&) {}

template <>
bool TextCodecUTF8::HandlePartialSequence<UChar>(UChar*& destination,
                                                 const uint8_t*& source,
                                                 const uint8_t* end,
                                                 bool flush,
                                                 bool stop_on_error,
                                                 bool& saw_error) {}

namespace {
template <typename CharType>
class InlinedStringBuffer {};
}  // namespace

String TextCodecUTF8::Decode(const char* bytes,
                             wtf_size_t length,
                             FlushBehavior flush,
                             bool stop_on_error,
                             bool& saw_error) {}

template <typename CharType>
std::string TextCodecUTF8::EncodeCommon(const CharType* characters,
                                        wtf_size_t length) {}

template <typename CharType>
TextCodec::EncodeIntoResult TextCodecUTF8::EncodeIntoCommon(
    const CharType* characters,
    wtf_size_t length,
    unsigned char* destination,
    size_t capacity) {}

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

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

TextCodec::EncodeIntoResult TextCodecUTF8::EncodeInto(
    const UChar* characters,
    wtf_size_t length,
    unsigned char* destination,
    size_t capacity) {}

TextCodec::EncodeIntoResult TextCodecUTF8::EncodeInto(
    const LChar* characters,
    wtf_size_t length,
    unsigned char* destination,
    size_t capacity) {}

}  // namespace WTF