18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 2d0825bca7fe65beaee391d30da42e937db621564Steve Block * Copyright (C) 2005, 2007, 2010 Apple Inc. All rights reserved. 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 4d0825bca7fe65beaee391d30da42e937db621564Steve Block * Redistribution and use in source and binary forms, with or without 5d0825bca7fe65beaee391d30da42e937db621564Steve Block * modification, are permitted provided that the following conditions 6d0825bca7fe65beaee391d30da42e937db621564Steve Block * are met: 7d0825bca7fe65beaee391d30da42e937db621564Steve Block * 1. Redistributions of source code must retain the above copyright 8d0825bca7fe65beaee391d30da42e937db621564Steve Block * notice, this list of conditions and the following disclaimer. 9d0825bca7fe65beaee391d30da42e937db621564Steve Block * 2. Redistributions in binary form must reproduce the above copyright 10d0825bca7fe65beaee391d30da42e937db621564Steve Block * notice, this list of conditions and the following disclaimer in the 11d0825bca7fe65beaee391d30da42e937db621564Steve Block * documentation and/or other materials provided with the distribution. 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 13d0825bca7fe65beaee391d30da42e937db621564Steve Block * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14d0825bca7fe65beaee391d30da42e937db621564Steve Block * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15d0825bca7fe65beaee391d30da42e937db621564Steve Block * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16d0825bca7fe65beaee391d30da42e937db621564Steve Block * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17d0825bca7fe65beaee391d30da42e937db621564Steve Block * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18d0825bca7fe65beaee391d30da42e937db621564Steve Block * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19d0825bca7fe65beaee391d30da42e937db621564Steve Block * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20d0825bca7fe65beaee391d30da42e937db621564Steve Block * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21d0825bca7fe65beaee391d30da42e937db621564Steve Block * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22d0825bca7fe65beaee391d30da42e937db621564Steve Block * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23d0825bca7fe65beaee391d30da42e937db621564Steve Block * THE POSSIBILITY OF SUCH DAMAGE. 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */ 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h" 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "break_lines.h" 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "TextBreakIterator.h" 304576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang#include <wtf/StdLibExtras.h> 312fc2651226baac27029e38c9d6ef883fa32084dbSteve Block#include <wtf/unicode/CharacterNames.h> 328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if PLATFORM(MAC) 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <CoreServices/CoreServices.h> 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstatic inline bool isBreakableSpace(UChar ch, bool treatNoBreakSpaceAsBreak) 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project switch (ch) { 420617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen case ' ': 430617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen case '\n': 440617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen case '\t': 450617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen return true; 460617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen case noBreakSpace: 470617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen return treatNoBreakSpaceAsBreak; 480617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen default: 490617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen return false; 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 530617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsenstatic const UChar asciiLineBreakTableFirstChar = '!'; 540617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsenstatic const UChar asciiLineBreakTableLastChar = 127; 550617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen 560617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// Pack 8 bits into one byte 570617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#define B(a, b, c, d, e, f, g, h) \ 580617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen ((a) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7)) 590617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen 600617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// Line breaking table row for each digit (0-9) 610617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#define DI { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 620617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen 630617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// Line breaking table row for ascii letters (a-z A-Z) 640617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#define AL { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 650617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen 660617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#define F 0xFF 670617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen 680617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// Line breaking table for printable ASCII characters. Line breaking opportunities in this table are as below: 690617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// - before openning punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6); 700617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// - after '-' and '?' (backward-compatible, and compatible with Internet Explorer). 710617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// Please refer to <https://bugs.webkit.org/show_bug.cgi?id=37698> for line breaking matrixes of different browsers 720617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen// and the ICU standard. 730617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsenstatic const unsigned char asciiLineBreakTable[][(asciiLineBreakTableLastChar - asciiLineBreakTableFirstChar) / 8 + 1] = { 740617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen // ! " # $ % & ' ( ) * + , - . / 0 1-8 9 : ; < = > ? @ A-X Y Z [ \ ] ^ _ ` a-x y z { | } ~ DEL 750617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ! 760617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // " 770617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // # 780617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // $ 790617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // % 800617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // & 810617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // ' 820617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // ( 830617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ) 840617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // * 850617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // + 860617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // , 870617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(1, 1, 1, 1, 1, 1, 1, 1), B(1, 1, 1, 1, 1, 1, 1, 1), F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1) }, // - 880617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // . 890617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // / 900617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, // 0-9 910617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // : 920617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ; 930617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // < 940617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // = 950617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // > 960617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 1, 1, 1, 1, 0, 1), B(0, 1, 1, 0, 1, 0, 0, 1), F, B(1, 0, 0, 1, 1, 1, 0, 1), F, F, F, B(1, 1, 1, 1, 0, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 0, 1, 1, 0) }, // ? 970617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // @ 980617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // A-Z 990617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // [ 1000617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // '\' 1010617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ] 1020617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // ^ 1030617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // _ 1040617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // ` 1050617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // a-z 1060617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // { 1070617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // | 1080617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // } 1090617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ~ 1100617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // DEL 111d0825bca7fe65beaee391d30da42e937db621564Steve Block}; 112d0825bca7fe65beaee391d30da42e937db621564Steve Block 1130617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#undef B 1140617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#undef F 1150617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#undef DI 1160617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen#undef AL 1170617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen 1184576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) WangCOMPILE_ASSERT(WTF_ARRAY_LENGTH(asciiLineBreakTable) == asciiLineBreakTableLastChar - asciiLineBreakTableFirstChar + 1, TestLineBreakTableConsistency); 119d0825bca7fe65beaee391d30da42e937db621564Steve Block 120d0825bca7fe65beaee391d30da42e937db621564Steve Blockstatic inline bool shouldBreakAfter(UChar ch, UChar nextCh) 1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1229436923afbaf725afc7f71307ebc992c0c7ee1faSteve Block#ifdef ANDROID_LAYOUT 123a571e242f305463ffcb0a8680c750312ed04ea79claireho if (ch == '/') // as '/' is used in uri which is always long, we would like to break it 1240617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen return true; 125a571e242f305463ffcb0a8680c750312ed04ea79claireho#endif 126a571e242f305463ffcb0a8680c750312ed04ea79claireho 127a571e242f305463ffcb0a8680c750312ed04ea79claireho // If both ch and nextCh are ASCII characters, use a lookup table for enhanced speed and for compatibility 128a571e242f305463ffcb0a8680c750312ed04ea79claireho // with other browsers (see comments for asciiLineBreakTable for details). 129a571e242f305463ffcb0a8680c750312ed04ea79claireho if (ch >= asciiLineBreakTableFirstChar && ch <= asciiLineBreakTableLastChar 130a571e242f305463ffcb0a8680c750312ed04ea79claireho && nextCh >= asciiLineBreakTableFirstChar && nextCh <= asciiLineBreakTableLastChar) { 131a571e242f305463ffcb0a8680c750312ed04ea79claireho const unsigned char* tableRow = asciiLineBreakTable[ch - asciiLineBreakTableFirstChar]; 132a571e242f305463ffcb0a8680c750312ed04ea79claireho int nextChIndex = nextCh - asciiLineBreakTableFirstChar; 133a571e242f305463ffcb0a8680c750312ed04ea79claireho return tableRow[nextChIndex / 8] & (1 << (nextChIndex % 8)); 1348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 135a571e242f305463ffcb0a8680c750312ed04ea79claireho // Otherwise defer to the Unicode algorithm by returning false. 136a571e242f305463ffcb0a8680c750312ed04ea79claireho return false; 1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstatic inline bool needsLineBreakIterator(UChar ch) 1408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1410617145a89917ae7735fe1c9538688ab9a577df5Kristian Monsen return ch > asciiLineBreakTableLastChar && ch != noBreakSpace; 1428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1445f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#if PLATFORM(MAC) && defined(BUILDING_ON_TIGER) 1458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstatic inline TextBreakLocatorRef lineBreakLocator() 1468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project TextBreakLocatorRef locator = 0; 1488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project UCCreateTextBreakLocator(0, 0, kUCTextBreakLineMask, &locator); 1498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return locator; 1508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 1528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 15381bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdochint nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos, bool treatNoBreakSpaceAsBreak) 1548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 15581bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch const UChar* str = lazyBreakIterator.string(); 15681bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch int len = lazyBreakIterator.length(); 1578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int nextBreak = -1; 1588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project UChar lastCh = pos > 0 ? str[pos - 1] : 0; 1608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project for (int i = pos; i < len; i++) { 1618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project UChar ch = str[i]; 1628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 163d0825bca7fe65beaee391d30da42e937db621564Steve Block if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastCh, ch)) 1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return i; 1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (needsLineBreakIterator(ch) || needsLineBreakIterator(lastCh)) { 1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (nextBreak < i && i) { 1685f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#if !PLATFORM(MAC) || !defined(BUILDING_ON_TIGER) 16981bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch TextBreakIterator* breakIterator = lazyBreakIterator.get(); 1708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (breakIterator) 1718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project nextBreak = textBreakFollowing(breakIterator, i - 1); 1728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#else 1738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project static TextBreakLocatorRef breakLocator = lineBreakLocator(); 1748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (breakLocator) { 1758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project UniCharArrayOffset nextUCBreak; 1768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (UCFindTextBreak(breakLocator, kUCTextBreakLineMask, 0, str, len, i, &nextUCBreak) == 0) 1778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project nextBreak = nextUCBreak; 1788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 1808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project if (i == nextBreak && !isBreakableSpace(lastCh, treatNoBreakSpaceAsBreak)) 1828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return i; 1838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project lastCh = ch; 1868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project } 1878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return len; 1898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore 192