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

/*
 * Copyright (C) 1999 Lars Knoll ([email protected])
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
 * reserved.
 * Copyright (C) 2009 Google Inc. All rights reserved.
 *
 * 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

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_STRING_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_STRING_IMPL_H_

#include <limits.h>
#include <string.h>

#include <atomic>

#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/dcheck_is_on.h"
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/text/ascii_ctype.h"
#include "third_party/blink/renderer/platform/wtf/text/ascii_fast_path.h"
#include "third_party/blink/renderer/platform/wtf/text/number_parsing_options.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hasher.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_uchar.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/blink/renderer/platform/wtf/wtf_export.h"

#if BUILDFLAG(IS_APPLE)
#include "base/apple/scoped_cftyperef.h"

typedef const struct __CFString* CFStringRef;
#endif

#ifdef __OBJC__
@class NSString;
#endif

namespace WTF {

enum TextCaseSensitivity {};

// Computes a standard StringHasher string for the given buffer,
// with the caveat that the buffer may contain 8-bit data only.
// In that case, it is converted from UChar to LChar on the fly,
// so that we return the same hash as if we hashed the string as
// LChar to begin with. This ensures that the same code points
// are hashed to the same value, even if someone called e.g.
// Ensure16Bit() on the string at some point.
WTF_EXPORT unsigned ComputeHashForWideString(const UChar* str, unsigned length);

enum StripBehavior {};

CharacterMatchFunctionPtr;
IsWhiteSpaceFunctionPtr;
StaticStringsTable;

// You can find documentation about this class in this doc:
// https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/renderer/platform/wtf/text/README.md
class WTF_EXPORT StringImpl {};

template <>
ALWAYS_INLINE const LChar* StringImpl::GetCharacters<LChar>() const {}

template <>
ALWAYS_INLINE const UChar* StringImpl::GetCharacters<UChar>() const {}

// The following template specialization can be moved to the class declaration
// once we officially switch to C++17 (we need C++ DR727 to be implemented).
template <>
ALWAYS_INLINE size_t StringImpl::AllocationSize<LChar>(wtf_size_t length) {}

WTF_EXPORT bool Equal(const StringImpl*, const StringImpl*);
WTF_EXPORT bool Equal(const StringImpl*, const LChar*);
inline bool Equal(const StringImpl* a, const char* b) {}
WTF_EXPORT bool Equal(const StringImpl*, const LChar*, wtf_size_t);
WTF_EXPORT bool Equal(const StringImpl*, const UChar*, wtf_size_t);
inline bool Equal(const StringImpl* a, const char* b, wtf_size_t length) {}
inline bool Equal(const LChar* a, StringImpl* b) {}
inline bool Equal(const char* a, StringImpl* b) {}
WTF_EXPORT bool EqualNonNull(const StringImpl* a, const StringImpl* b);

ALWAYS_INLINE bool StringImpl::ContainsOnlyASCIIOrEmpty() const {}

ALWAYS_INLINE bool StringImpl::IsLowerASCII() const {}

template <typename CharType>
ALWAYS_INLINE bool Equal(const CharType* a,
                         const CharType* b,
                         wtf_size_t length) {}

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

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

// Unicode aware case insensitive string matching. Non-ASCII characters might
// match to ASCII characters. These functions are rarely used to implement web
// platform features.
// These functions are deprecated. Use EqualIgnoringASCIICase(), or introduce
// EqualIgnoringUnicodeCase(). See crbug.com/627682
WTF_EXPORT bool DeprecatedEqualIgnoringCase(const LChar*,
                                            const LChar*,
                                            wtf_size_t length);
WTF_EXPORT bool DeprecatedEqualIgnoringCase(const UChar*,
                                            const LChar*,
                                            wtf_size_t length);
inline bool DeprecatedEqualIgnoringCase(const LChar* a,
                                        const UChar* b,
                                        wtf_size_t length) {}
WTF_EXPORT bool DeprecatedEqualIgnoringCase(const UChar*,
                                            const UChar*,
                                            wtf_size_t length);

WTF_EXPORT bool EqualIgnoringNullity(StringImpl*, StringImpl*);

template <typename CharacterTypeA, typename CharacterTypeB>
inline bool EqualIgnoringASCIICase(const CharacterTypeA* a,
                                   const CharacterTypeB* b,
                                   wtf_size_t length) {}

WTF_EXPORT int CodeUnitCompareIgnoringASCIICase(const StringImpl*,
                                                const StringImpl*);
WTF_EXPORT int CodeUnitCompareIgnoringASCIICase(const StringImpl*,
                                                const LChar*);

inline wtf_size_t Find(const LChar* characters,
                       wtf_size_t length,
                       LChar match_character,
                       wtf_size_t index = 0) {}

inline wtf_size_t Find(const UChar* characters,
                       wtf_size_t length,
                       UChar match_character,
                       wtf_size_t index = 0) {}

ALWAYS_INLINE wtf_size_t Find(const UChar* characters,
                              wtf_size_t length,
                              LChar match_character,
                              wtf_size_t index = 0) {}

inline wtf_size_t Find(const LChar* characters,
                       wtf_size_t length,
                       UChar match_character,
                       wtf_size_t index = 0) {}

template <typename CharacterType>
inline wtf_size_t Find(const CharacterType* characters,
                       wtf_size_t length,
                       char match_character,
                       wtf_size_t index = 0) {}

inline wtf_size_t Find(const LChar* characters,
                       wtf_size_t length,
                       CharacterMatchFunctionPtr match_function,
                       wtf_size_t index = 0) {}

inline wtf_size_t Find(const UChar* characters,
                       wtf_size_t length,
                       CharacterMatchFunctionPtr match_function,
                       wtf_size_t index = 0) {}

template <typename CharacterType>
inline wtf_size_t ReverseFind(const CharacterType* characters,
                              wtf_size_t length,
                              CharacterType match_character,
                              wtf_size_t index = UINT_MAX) {}

ALWAYS_INLINE wtf_size_t ReverseFind(const UChar* characters,
                                     wtf_size_t length,
                                     LChar match_character,
                                     wtf_size_t index = UINT_MAX) {}

inline wtf_size_t ReverseFind(const LChar* characters,
                              wtf_size_t length,
                              UChar match_character,
                              wtf_size_t index = UINT_MAX) {}

inline wtf_size_t StringImpl::Find(LChar character, wtf_size_t start) {}

ALWAYS_INLINE wtf_size_t StringImpl::Find(char character, wtf_size_t start) {}

inline wtf_size_t StringImpl::Find(UChar character, wtf_size_t start) {}

inline wtf_size_t LengthOfNullTerminatedString(const UChar* string) {}

template <wtf_size_t inlineCapacity>
bool EqualIgnoringNullity(const Vector<UChar, inlineCapacity>& a,
                          StringImpl* b) {}

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

static inline int CodeUnitCompare8(const StringImpl* string1,
                                   const StringImpl* string2) {}

static inline int CodeUnitCompare16(const StringImpl* string1,
                                    const StringImpl* string2) {}

static inline int CodeUnitCompare8To16(const StringImpl* string1,
                                       const StringImpl* string2) {}

static inline int CodeUnitCompare(const StringImpl* string1,
                                  const StringImpl* string2) {}

inline scoped_refptr<StringImpl> StringImpl::IsolatedCopy() const {}

template <typename BufferType>
inline void StringImpl::AppendTo(BufferType& result,
                                 wtf_size_t start,
                                 wtf_size_t length) const {}

template <typename BufferType>
inline void StringImpl::PrependTo(BufferType& result,
                                  wtf_size_t start,
                                  wtf_size_t length) const {}

template <typename T>
struct HashTraits;
// Defined in string_hash.h.
template <>
struct HashTraits<StringImpl*>;
template <>
struct HashTraits<scoped_refptr<StringImpl>>;

}  // namespace WTF

Equal;
EqualNonNull;
kTextCaseASCIIInsensitive;
kTextCaseSensitive;
kTextCaseUnicodeInsensitive;
LengthOfNullTerminatedString;
ReverseFind;
StringImpl;
TextCaseSensitivity;

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_STRING_IMPL_H_