OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) | 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 return findIgnoringCaseInner(characters8() + index, matchString->cha
racters8(), index, searchLength, matchLength); | 1331 return findIgnoringCaseInner(characters8() + index, matchString->cha
racters8(), index, searchLength, matchLength); |
1332 return findIgnoringCaseInner(characters8() + index, matchString->charact
ers16(), index, searchLength, matchLength); | 1332 return findIgnoringCaseInner(characters8() + index, matchString->charact
ers16(), index, searchLength, matchLength); |
1333 } | 1333 } |
1334 | 1334 |
1335 if (matchString->is8Bit()) | 1335 if (matchString->is8Bit()) |
1336 return findIgnoringCaseInner(characters16() + index, matchString->charac
ters8(), index, searchLength, matchLength); | 1336 return findIgnoringCaseInner(characters16() + index, matchString->charac
ters8(), index, searchLength, matchLength); |
1337 | 1337 |
1338 return findIgnoringCaseInner(characters16() + index, matchString->characters
16(), index, searchLength, matchLength); | 1338 return findIgnoringCaseInner(characters16() + index, matchString->characters
16(), index, searchLength, matchLength); |
1339 } | 1339 } |
1340 | 1340 |
| 1341 template <typename SearchCharacterType, typename MatchCharacterType> |
| 1342 ALWAYS_INLINE static size_t findIgnoringASCIICaseInner(const SearchCharacterType
* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index, u
nsigned searchLength, unsigned matchLength) |
| 1343 { |
| 1344 // delta is the number of additional times to test; delta == 0 means test on
ly once. |
| 1345 unsigned delta = searchLength - matchLength; |
| 1346 |
| 1347 unsigned i = 0; |
| 1348 // keep looping until we match |
| 1349 while (!equalIgnoringASCIICase(searchCharacters + i, matchCharacters, matchL
ength)) { |
| 1350 if (i == delta) |
| 1351 return kNotFound; |
| 1352 ++i; |
| 1353 } |
| 1354 return index + i; |
| 1355 } |
| 1356 |
| 1357 size_t StringImpl::findIgnoringASCIICase(StringImpl* matchString, unsigned index
) |
| 1358 { |
| 1359 // Check for null or empty string to match against |
| 1360 if (!matchString) |
| 1361 return kNotFound; |
| 1362 unsigned matchLength = matchString->length(); |
| 1363 if (!matchLength) |
| 1364 return min(index, length()); |
| 1365 |
| 1366 // Check index & matchLength are in range. |
| 1367 if (index > length()) |
| 1368 return kNotFound; |
| 1369 unsigned searchLength = length() - index; |
| 1370 if (matchLength > searchLength) |
| 1371 return kNotFound; |
| 1372 |
| 1373 if (is8Bit()) { |
| 1374 const LChar* searchStart = characters8() + index; |
| 1375 if (matchString->is8Bit()) |
| 1376 return findIgnoringASCIICaseInner(searchStart, matchString->characte
rs8(), index, searchLength, matchLength); |
| 1377 return findIgnoringASCIICaseInner(searchStart, matchString->characters16
(), index, searchLength, matchLength); |
| 1378 } |
| 1379 |
| 1380 const UChar* searchStart = characters16() + index; |
| 1381 if (matchString->is8Bit()) |
| 1382 return findIgnoringASCIICaseInner(searchStart, matchString->characters8(
), index, searchLength, matchLength); |
| 1383 return findIgnoringASCIICaseInner(searchStart, matchString->characters16(),
index, searchLength, matchLength); |
| 1384 } |
| 1385 |
1341 size_t StringImpl::findNextLineStart(unsigned index) | 1386 size_t StringImpl::findNextLineStart(unsigned index) |
1342 { | 1387 { |
1343 if (is8Bit()) | 1388 if (is8Bit()) |
1344 return WTF::findNextLineStart(characters8(), m_length, index); | 1389 return WTF::findNextLineStart(characters8(), m_length, index); |
1345 return WTF::findNextLineStart(characters16(), m_length, index); | 1390 return WTF::findNextLineStart(characters16(), m_length, index); |
1346 } | 1391 } |
1347 | 1392 |
1348 size_t StringImpl::count(LChar c) const | 1393 size_t StringImpl::count(LChar c) const |
1349 { | 1394 { |
1350 int count = 0; | 1395 int count = 0; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 } | 1543 } |
1499 | 1544 |
1500 bool StringImpl::startsWithIgnoringCase(const StringImpl* prefix) const | 1545 bool StringImpl::startsWithIgnoringCase(const StringImpl* prefix) const |
1501 { | 1546 { |
1502 ASSERT(prefix); | 1547 ASSERT(prefix); |
1503 if (prefix->length() > length()) | 1548 if (prefix->length() > length()) |
1504 return false; | 1549 return false; |
1505 return equalSubstringIgnoringCase(this, 0, prefix); | 1550 return equalSubstringIgnoringCase(this, 0, prefix); |
1506 } | 1551 } |
1507 | 1552 |
| 1553 ALWAYS_INLINE static bool equalSubstringIgnoringASCIICase(const StringImpl* stri
ngImpl, unsigned startOffset, const StringImpl* matchString) |
| 1554 { |
| 1555 ASSERT(stringImpl); |
| 1556 ASSERT(matchString); |
| 1557 ASSERT(matchString->length() <= stringImpl->length()); |
| 1558 ASSERT(startOffset + matchString->length() <= stringImpl->length()); |
| 1559 |
| 1560 unsigned matchLength = matchString->length(); |
| 1561 if (stringImpl->is8Bit()) { |
| 1562 const LChar* start = stringImpl->characters8() + startOffset; |
| 1563 if (matchString->is8Bit()) |
| 1564 return equalIgnoringASCIICase(start, matchString->characters8(), mat
chLength); |
| 1565 return equalIgnoringASCIICase(start, matchString->characters16(), matchL
ength); |
| 1566 } |
| 1567 const UChar* start = stringImpl->characters16() + startOffset; |
| 1568 if (matchString->is8Bit()) |
| 1569 return equalIgnoringASCIICase(start, matchString->characters8(), matchLe
ngth); |
| 1570 return equalIgnoringASCIICase(start, matchString->characters16(), matchLengt
h); |
| 1571 } |
| 1572 |
| 1573 bool StringImpl::startsWithIgnoringASCIICase(const StringImpl* prefix) const |
| 1574 { |
| 1575 ASSERT(prefix); |
| 1576 if (prefix->length() > length()) |
| 1577 return false; |
| 1578 return equalSubstringIgnoringASCIICase(this, 0, prefix); |
| 1579 } |
| 1580 |
1508 bool StringImpl::endsWith(UChar character) const | 1581 bool StringImpl::endsWith(UChar character) const |
1509 { | 1582 { |
1510 return m_length && (*this)[m_length - 1] == character; | 1583 return m_length && (*this)[m_length - 1] == character; |
1511 } | 1584 } |
1512 | 1585 |
1513 bool StringImpl::endsWith(const char* matchString, unsigned matchLength) const | 1586 bool StringImpl::endsWith(const char* matchString, unsigned matchLength) const |
1514 { | 1587 { |
1515 ASSERT(matchLength); | 1588 ASSERT(matchLength); |
1516 if (matchLength > length()) | 1589 if (matchLength > length()) |
1517 return false; | 1590 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
1529 | 1602 |
1530 bool StringImpl::endsWithIgnoringCase(const StringImpl* suffix) const | 1603 bool StringImpl::endsWithIgnoringCase(const StringImpl* suffix) const |
1531 { | 1604 { |
1532 ASSERT(suffix); | 1605 ASSERT(suffix); |
1533 unsigned suffixLength = suffix->length(); | 1606 unsigned suffixLength = suffix->length(); |
1534 if (suffixLength > length()) | 1607 if (suffixLength > length()) |
1535 return false; | 1608 return false; |
1536 return equalSubstringIgnoringCase(this, length() - suffixLength, suffix); | 1609 return equalSubstringIgnoringCase(this, length() - suffixLength, suffix); |
1537 } | 1610 } |
1538 | 1611 |
| 1612 bool StringImpl::endsWithIgnoringASCIICase(const StringImpl* suffix) const |
| 1613 { |
| 1614 ASSERT(suffix); |
| 1615 unsigned suffixLength = suffix->length(); |
| 1616 if (suffixLength > length()) |
| 1617 return false; |
| 1618 return equalSubstringIgnoringASCIICase(this, length() - suffixLength, suffix
); |
| 1619 } |
| 1620 |
1539 PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) | 1621 PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) |
1540 { | 1622 { |
1541 if (oldC == newC) | 1623 if (oldC == newC) |
1542 return this; | 1624 return this; |
1543 | 1625 |
1544 if (find(oldC) == kNotFound) | 1626 if (find(oldC) == kNotFound) |
1545 return this; | 1627 return this; |
1546 | 1628 |
1547 unsigned i; | 1629 unsigned i; |
1548 if (is8Bit()) { | 1630 if (is8Bit()) { |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { | 2209 } else if (localeIdMatchesLang(localeIdentifier, "lt")) { |
2128 // TODO(rob.buis) implement upper-casing rules for lt | 2210 // TODO(rob.buis) implement upper-casing rules for lt |
2129 // like in StringImpl::upper(locale). | 2211 // like in StringImpl::upper(locale). |
2130 } | 2212 } |
2131 } | 2213 } |
2132 | 2214 |
2133 return toUpper(c); | 2215 return toUpper(c); |
2134 } | 2216 } |
2135 | 2217 |
2136 } // namespace WTF | 2218 } // namespace WTF |
OLD | NEW |