chromium/third_party/blink/renderer/platform/text/text_break_iterator.cc

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

#include "third_party/blink/renderer/platform/text/text_break_iterator.h"

#include <unicode/uchar.h>
#include <unicode/uvernum.h>

#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/break_iterator_data_inline_header.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/ascii_ctype.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/unicode.h"

namespace blink {

unsigned NumGraphemeClusters(const String& string) {}

void GraphemesClusterList(const StringView& text, Vector<unsigned>* graphemes) {}

unsigned LengthOfGraphemeCluster(const String& string, unsigned offset) {}

static const UChar kAsciiLineBreakTableFirstChar =;
static const UChar kAsciiLineBreakTableLastChar =;

// Pack 8 bits into one byte
#define B

// Line breaking table row for each digit (0-9)
#define DI

// Line breaking table row for ascii letters (a-z A-Z)
#define AL

#define F

// Check if the generated table match the `kAsciiLineBreakTable` table.
#define CHECK_ASCII_LINE_BRAEK_TABLE

// Line breaking table for printable ASCII characters. Line breaking
// opportunities in this table are as below:
// - before opening punctuations such as '(', '<', '[', '{' after certain
//   characters (compatible with Firefox 3.6);
// - after '-' and '?' (backward-compatible, and compatible with Internet
//   Explorer).
// Please refer to <https://bugs.webkit.org/show_bug.cgi?id=37698> for line
// breaking matrixes of different browsers and the ICU standard.
// clang-format off
static const unsigned char kAsciiLineBreakTable[][(kAsciiLineBreakTableLastChar - kAsciiLineBreakTableFirstChar) / 8 + 1] =;
// clang-format on

#if CHECK_ASCII_LINE_BRAEK_TABLE
void CheckAsciiLineBreakTable() {
  for (UChar ch2 = kAsciiLineBreakTableFirstChar;
       ch2 <= kAsciiLineBreakTableLastChar; ++ch2) {
    for (UChar ch1 = kAsciiLineBreakTableFirstChar;
         ch1 <= kAsciiLineBreakTableLastChar; ++ch1) {
      const UChar i2 = ch2 - kAsciiLineBreakTableFirstChar;
      const bool ascii =
          kAsciiLineBreakTable[ch1 - kAsciiLineBreakTableFirstChar][i2 / 8] &
          (1 << (i2 % 8));
      const bool fast = GetFastLineBreak(ch1, ch2);
      CHECK_EQ(ascii, fast)
          << String::Format("%02X/%02X (%c/%c)", ch1, ch2, ch1, ch2);
    }
  }
}
#endif  // CHECK_ASCII_LINE_BRAEK_TABLE

#define BA_LB_COUNT
// Line breaking table for CSS word-break: break-all. This table differs from
// asciiLineBreakTable in:
// - Indices are Line Breaking Classes defined in UAX#14 Unicode Line Breaking
//   Algorithm: http://unicode.org/reports/tr14/#DescriptionOfProperties
// - 1 indicates additional break opportunities. 0 indicates to fallback to
//   normal line break, not "prohibit break."
// clang-format off
static const unsigned char kBreakAllLineBreakClassTable[][BA_LB_COUNT / 8 + 1] =;
// clang-format on

#undef B
#undef F
#undef DI
#undef AL

static_assert;
static_assert;

static inline ULineBreak LineBreakPropertyValue(UChar last_ch, UChar ch) {}

static inline bool ShouldBreakAfterBreakAll(ULineBreak last_line_break,
                                            ULineBreak line_break) {}

// Computes if 'word-break:keep-all' should prevent line break.
// https://drafts.csswg.org/css-text-3/#valdef-word-break-keep-all
// The spec is not very verbose on how this should work. This logic prevents L/M
// general categories and complex line breaking since the spec says "except some
// south east aisans".
// https://github.com/w3c/csswg-drafts/issues/1619
static inline bool ShouldKeepAfterKeepAll(UChar last_ch,
                                          UChar ch,
                                          UChar next_ch) {}

enum class FastBreakResult : uint8_t {};

template <typename CharacterType, bool use_fast_table>
struct LazyLineBreakIterator::Context {};

template <typename CharacterType,
          LineBreakType line_break_type,
          BreakSpaceType break_space>
inline unsigned LazyLineBreakIterator::NextBreakablePosition(
    unsigned pos,
    const CharacterType* str,
    unsigned len) const {}

template <typename CharacterType,
          LineBreakType line_break_type,
          BreakSpaceType break_space,
          bool use_fast_table>
inline unsigned LazyLineBreakIterator::NextBreakablePosition(
    unsigned pos,
    const CharacterType* str,
    unsigned len) const {}

template <typename CharacterType, LineBreakType lineBreakType>
inline unsigned LazyLineBreakIterator::NextBreakablePosition(
    unsigned pos,
    const CharacterType* str,
    unsigned len) const {}

template <LineBreakType lineBreakType>
inline unsigned LazyLineBreakIterator::NextBreakablePosition(
    unsigned pos,
    unsigned len) const {}

unsigned LazyLineBreakIterator::NextBreakablePositionBreakCharacter(
    unsigned pos) const {}

unsigned LazyLineBreakIterator::NextBreakablePosition(unsigned pos,
                                                      unsigned len) const {}

unsigned LazyLineBreakIterator::NextBreakOpportunity(unsigned offset) const {}

unsigned LazyLineBreakIterator::NextBreakOpportunity(unsigned offset,
                                                     unsigned len) const {}

unsigned LazyLineBreakIterator::PreviousBreakOpportunity(unsigned offset,
                                                         unsigned min) const {}

std::ostream& operator<<(std::ostream& ostream, LineBreakType line_break_type) {}

std::ostream& operator<<(std::ostream& ostream, BreakSpaceType break_space) {}

}  // namespace blink