Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/UnicodeRangeSet.cpp

Issue 1808853002: Move UnicodeRangeSet to platform/fonts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "UnicodeRangeSet.h"
27
28 #include "wtf/text/WTFString.h"
29
30 namespace blink {
31
32 UnicodeRangeSet::UnicodeRangeSet(const Vector<UnicodeRange>& ranges)
33 : m_ranges(ranges)
34 {
35 if (m_ranges.isEmpty())
36 return;
37
38 std::sort(m_ranges.begin(), m_ranges.end());
39
40 // Unify overlapping ranges.
41 UChar32 from = m_ranges[0].from();
42 UChar32 to = m_ranges[0].to();
43 size_t targetIndex = 0;
44 for (size_t i = 1; i < m_ranges.size(); i++) {
45 if (to + 1 >= m_ranges[i].from()) {
46 to = std::max(to, m_ranges[i].to());
47 } else {
48 m_ranges[targetIndex++] = UnicodeRange(from, to);
49 from = m_ranges[i].from();
50 to = m_ranges[i].to();
51 }
52 }
53 m_ranges[targetIndex++] = UnicodeRange(from, to);
54 m_ranges.shrink(targetIndex);
55 }
56
57 bool UnicodeRangeSet::contains(UChar32 c) const
58 {
59 if (isEntireRange())
60 return true;
61 Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begin(), m_ranges.end(), c);
62 return it != m_ranges.end() && it->contains(c);
63 }
64
65 bool UnicodeRangeSet::contains(const FontDataRange& range) const
66 {
67 for (auto it = m_ranges.begin(); it != m_ranges.end(); ++it) {
68 if (*it == range)
69 return true;
70 }
71 return false;
72 }
73
74 bool UnicodeRangeSet::intersectsWith(const String& text) const
75 {
76 if (text.isEmpty())
77 return false;
78 if (isEntireRange())
79 return true;
80 if (text.is8Bit() && m_ranges[0].from() >= 0x100)
81 return false;
82
83 unsigned index = 0;
84 while (index < text.length()) {
85 UChar32 c = text.characterStartingAt(index);
86 index += U16_LENGTH(c);
87 if (contains(c))
88 return true;
89 }
90 return false;
91 }
92
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698