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

/*
 * Copyright (C) 1999 Lars Knoll ([email protected])
 *           (C) 1999 Antti Koivisto ([email protected])
 *           (C) 2001 Dirk Mueller ( [email protected] )
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All
 * rights reserved.
 * Copyright (C) 2006 Andrew Wellington ([email protected])
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#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/string_impl.h"

#include <algorithm>
#include <memory>

#include "base/functional/callback.h"
#include "base/i18n/string_search.h"
#include "base/numerics/safe_conversions.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
#include "third_party/blink/renderer/platform/wtf/dynamic_annotations.h"
#include "third_party/blink/renderer/platform/wtf/leak_annotations.h"
#include "third_party/blink/renderer/platform/wtf/size_assertions.h"
#include "third_party/blink/renderer/platform/wtf/static_constructors.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_table.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/character_visitor.h"
#include "third_party/blink/renderer/platform/wtf/text/string_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/string_to_number.h"
#include "third_party/blink/renderer/platform/wtf/text/unicode.h"
#include "third_party/blink/renderer/platform/wtf/text/unicode_string.h"

numeric_limits;

namespace WTF {

namespace  // namespace

void* StringImpl::operator new(size_t size) {}

void StringImpl::operator delete(void* ptr) {}

inline StringImpl::~StringImpl() {}

void StringImpl::DestroyIfNeeded() const {}

unsigned StringImpl::ComputeASCIIFlags() const {}

#if DCHECK_IS_ON()
std::string StringImpl::AsciiForDebugging() const {}
#endif

scoped_refptr<StringImpl> StringImpl::CreateUninitialized(
    size_t length,
    base::span<LChar>& data) {}

scoped_refptr<StringImpl> StringImpl::CreateUninitialized(wtf_size_t length,
                                                          LChar*& data) {}

scoped_refptr<StringImpl> StringImpl::CreateUninitialized(
    size_t length,
    base::span<UChar>& data) {}

scoped_refptr<StringImpl> StringImpl::CreateUninitialized(wtf_size_t length,
                                                          UChar*& data) {}

static StaticStringsTable& StaticStrings() {}

#if DCHECK_IS_ON()
static bool g_allow_creation_of_static_strings =;
#endif

const StaticStringsTable& StringImpl::AllStaticStrings() {}

void StringImpl::FreezeStaticStrings() {}

wtf_size_t StringImpl::highest_static_string_length_ =;

DEFINE_GLOBAL();
DEFINE_GLOBAL();
// Callers need the global empty strings to be non-const.
StringImpl* StringImpl::empty_ =;
StringImpl* StringImpl::empty16_bit_ =;
void StringImpl::InitStatics() {}

StringImpl* StringImpl::CreateStatic(const char* string, wtf_size_t length) {}

void StringImpl::ReserveStaticStringsCapacityForSize(wtf_size_t size) {}

scoped_refptr<StringImpl> StringImpl::Create(
    base::span<const UChar> utf16_data) {}

scoped_refptr<StringImpl> StringImpl::Create(const UChar* characters,
                                             wtf_size_t length) {}

scoped_refptr<StringImpl> StringImpl::Create(
    base::span<const LChar> latin1_data) {}

scoped_refptr<StringImpl> StringImpl::Create(const LChar* characters,
                                             wtf_size_t length) {}

scoped_refptr<StringImpl> StringImpl::Create(
    const LChar* characters,
    wtf_size_t length,
    ASCIIStringAttributes ascii_attributes) {}

scoped_refptr<StringImpl> StringImpl::Create8BitIfPossible(
    const UChar* characters,
    wtf_size_t length) {}

scoped_refptr<StringImpl> StringImpl::Create(const LChar* string) {}

bool StringImpl::ContainsOnlyWhitespaceOrEmpty() {}

scoped_refptr<StringImpl> StringImpl::Substring(wtf_size_t start,
                                                wtf_size_t length) const {}

UChar32 StringImpl::CharacterStartingAt(wtf_size_t i) {}

wtf_size_t StringImpl::CopyTo(UChar* buffer,
                              wtf_size_t start,
                              wtf_size_t max_length) const {}

class StringImplAllocator {};

scoped_refptr<StringImpl> StringImpl::LowerASCII() {}

scoped_refptr<StringImpl> StringImpl::UpperASCII() {}

scoped_refptr<StringImpl> StringImpl::Fill(UChar character) {}

scoped_refptr<StringImpl> StringImpl::FoldCase() {}

scoped_refptr<StringImpl> StringImpl::Truncate(wtf_size_t length) {}

template <class UCharPredicate>
inline unsigned StringImpl::LengthWithStrippedMatchedCharacters(
    UCharPredicate predicate) const {}

template <class UCharPredicate>
inline scoped_refptr<StringImpl> StringImpl::StripMatchedCharacters(
    UCharPredicate predicate) {}

class UCharPredicate final {};

class SpaceOrNewlinePredicate final {};

unsigned StringImpl::LengthWithStrippedWhiteSpace() const {}

scoped_refptr<StringImpl> StringImpl::StripWhiteSpace() {}

scoped_refptr<StringImpl> StringImpl::StripWhiteSpace(
    IsWhiteSpaceFunctionPtr is_white_space) {}

template <typename CharType>
ALWAYS_INLINE scoped_refptr<StringImpl> StringImpl::RemoveCharacters(
    const CharType* characters,
    CharacterMatchFunctionPtr find_match) {}

scoped_refptr<StringImpl> StringImpl::RemoveCharacters(
    CharacterMatchFunctionPtr find_match) {}

scoped_refptr<StringImpl> StringImpl::Remove(wtf_size_t start,
                                             wtf_size_t length_to_remove) {}

template <typename CharType, class UCharPredicate>
inline scoped_refptr<StringImpl> StringImpl::SimplifyMatchedCharactersToSpace(
    UCharPredicate predicate,
    StripBehavior strip_behavior) {}

scoped_refptr<StringImpl> StringImpl::SimplifyWhiteSpace(
    StripBehavior strip_behavior) {}

scoped_refptr<StringImpl> StringImpl::SimplifyWhiteSpace(
    IsWhiteSpaceFunctionPtr is_white_space,
    StripBehavior strip_behavior) {}

int StringImpl::ToInt(NumberParsingOptions options, bool* ok) const {}

wtf_size_t StringImpl::ToUInt(NumberParsingOptions options, bool* ok) const {}

wtf_size_t StringImpl::HexToUIntStrict(bool* ok) {}

uint64_t StringImpl::HexToUInt64Strict(bool* ok) {}

int64_t StringImpl::ToInt64(NumberParsingOptions options, bool* ok) const {}

uint64_t StringImpl::ToUInt64(NumberParsingOptions options, bool* ok) const {}

double StringImpl::ToDouble(bool* ok) {}

float StringImpl::ToFloat(bool* ok) {}

// Table is based on ftp://ftp.unicode.org/Public/UNIDATA/CaseFolding.txt
const UChar StringImpl::kLatin1CaseFoldTable[256] =;

bool DeprecatedEqualIgnoringCase(const LChar* a,
                                 const LChar* b,
                                 wtf_size_t length) {}

bool DeprecatedEqualIgnoringCase(const UChar* a,
                                 const UChar* b,
                                 wtf_size_t length) {}

bool DeprecatedEqualIgnoringCase(const UChar* a,
                                 const LChar* b,
                                 wtf_size_t length) {}

wtf_size_t StringImpl::Find(CharacterMatchFunctionPtr match_function,
                            wtf_size_t start) {}

wtf_size_t StringImpl::Find(base::RepeatingCallback<bool(UChar)> match_callback,
                            wtf_size_t index) const {}

template <typename SearchCharacterType, typename MatchCharacterType>
ALWAYS_INLINE static wtf_size_t FindInternal(
    const SearchCharacterType* search_characters,
    const MatchCharacterType* match_characters,
    wtf_size_t index,
    wtf_size_t search_length,
    wtf_size_t match_length) {}

wtf_size_t StringImpl::Find(const StringView& match_string, wtf_size_t index) {}

template <typename SearchCharacterType, typename MatchCharacterType>
ALWAYS_INLINE static wtf_size_t FindIgnoringCaseInternal(
    const SearchCharacterType* search_characters,
    const MatchCharacterType* match_characters,
    wtf_size_t index,
    wtf_size_t search_length,
    wtf_size_t match_length) {}

wtf_size_t StringImpl::FindIgnoringCase(const StringView& match_string,
                                        wtf_size_t index) {}

template <typename SearchCharacterType, typename MatchCharacterType>
ALWAYS_INLINE static wtf_size_t FindIgnoringASCIICaseInternal(
    const SearchCharacterType* search_characters,
    const MatchCharacterType* match_characters,
    wtf_size_t index,
    wtf_size_t search_length,
    wtf_size_t match_length) {}

wtf_size_t StringImpl::FindIgnoringASCIICase(const StringView& match_string,
                                             wtf_size_t index) {}

wtf_size_t StringImpl::ReverseFind(UChar c, wtf_size_t index) {}

template <typename SearchCharacterType, typename MatchCharacterType>
ALWAYS_INLINE static wtf_size_t ReverseFindInternal(
    const SearchCharacterType* search_characters,
    const MatchCharacterType* match_characters,
    wtf_size_t index,
    wtf_size_t length,
    wtf_size_t match_length) {}

wtf_size_t StringImpl::ReverseFind(const StringView& match_string,
                                   wtf_size_t index) {}

bool StringImpl::StartsWith(UChar character) const {}

bool StringImpl::StartsWith(const StringView& prefix) const {}

bool StringImpl::StartsWithIgnoringCase(const StringView& prefix) const {}

bool StringImpl::StartsWithIgnoringCaseAndAccents(
    const StringView& prefix) const {}

std::u16string StringImpl::ToU16String() const {}

bool StringImpl::StartsWithIgnoringASCIICase(const StringView& prefix) const {}

bool StringImpl::EndsWith(UChar character) const {}

bool StringImpl::EndsWith(const StringView& suffix) const {}

bool StringImpl::EndsWithIgnoringCase(const StringView& suffix) const {}

bool StringImpl::EndsWithIgnoringASCIICase(const StringView& suffix) const {}

scoped_refptr<StringImpl> StringImpl::Replace(UChar old_c, UChar new_c) {}

// TODO(esprehn): Passing a null replacement is the same as empty string for
// this method but all others treat null as a no-op. We should choose one
// behavior.
scoped_refptr<StringImpl> StringImpl::Replace(wtf_size_t position,
                                              wtf_size_t length_to_replace,
                                              const StringView& string) {}

scoped_refptr<StringImpl> StringImpl::Replace(UChar pattern,
                                              const StringView& replacement) {}

scoped_refptr<StringImpl> StringImpl::Replace(UChar pattern,
                                              const LChar* replacement,
                                              wtf_size_t rep_str_length) {}

scoped_refptr<StringImpl> StringImpl::Replace(UChar pattern,
                                              const UChar* replacement,
                                              wtf_size_t rep_str_length) {}

scoped_refptr<StringImpl> StringImpl::Replace(const StringView& pattern,
                                              const StringView& replacement) {}

scoped_refptr<StringImpl> StringImpl::UpconvertedString() {}

static inline bool StringImplContentEqual(const StringImpl* a,
                                          const StringImpl* b) {}

bool Equal(const StringImpl* a, const StringImpl* b) {}

template <typename CharType>
inline bool EqualInternal(const StringImpl* a,
                          const CharType* b,
                          wtf_size_t length) {}

bool Equal(const StringImpl* a, const LChar* b, wtf_size_t length) {}

bool Equal(const StringImpl* a, const UChar* b, wtf_size_t length) {}

bool Equal(const StringImpl* a, const LChar* b) {}

bool EqualNonNull(const StringImpl* a, const StringImpl* b) {}

bool EqualIgnoringNullity(StringImpl* a, StringImpl* b) {}

template <typename CharacterType1, typename CharacterType2>
int CodeUnitCompareIgnoringASCIICase(wtf_size_t l1,
                                     wtf_size_t l2,
                                     const CharacterType1* c1,
                                     const CharacterType2* c2) {}

template <typename CharacterType>
int CodeUnitCompareIgnoringASCIICase(const StringImpl* string1,
                                     const CharacterType* string2,
                                     wtf_size_t length2) {}

int CodeUnitCompareIgnoringASCIICase(const StringImpl* string1,
                                     const LChar* string2) {}

int CodeUnitCompareIgnoringASCIICase(const StringImpl* string1,
                                     const StringImpl* string2) {}

}  // namespace WTF