1366 return(TPtrC16(Ptr()+aPos,aLength)); |
1373 return(TPtrC16(Ptr()+aPos,aLength)); |
1367 } |
1374 } |
1368 |
1375 |
1369 #endif // !defined(__DES16_MACHINE_CODED__) |
1376 #endif // !defined(__DES16_MACHINE_CODED__) |
1370 |
1377 |
|
1378 |
|
1379 /** |
|
1380 * A helper function, which moves a pointer one Unicode character forward. |
|
1381 * |
|
1382 * @aStart points to the head of the string to process. |
|
1383 * @aEnd points to the end of the string. Note that aEnd points to the first |
|
1384 * 16-bit unit after the string. That is, the string length (i.e, count |
|
1385 * of 16-bit units) is (aEnd-aStart). |
|
1386 * |
|
1387 * On return, |
|
1388 * if find valid character, then return KErrNone, with aNewStart pointing |
|
1389 * to the 16-bit unit after the found character; |
|
1390 * if meet corrupt surrogate before find a valid character, then return |
|
1391 * KErrCorruptSurrogateFound, with aNewStart pointing to the corrupt surrogate; |
|
1392 * if meet aEnd before find a valid character, then return KErrNotFound. |
|
1393 * |
|
1394 * @return KErrNone if ok; |
|
1395 * KErrNotFound if get to aEnd; |
|
1396 * KErrCorruptSurrogateFound if meet corrupt surrogate. |
|
1397 */ |
|
1398 TInt ProceedOneCharacter(const TText16* aStart, const TText16* aEnd, TText16*& aNewStart, TUint& aCurrentChar) |
|
1399 { |
|
1400 if (!aStart || !aEnd || aStart>=aEnd) |
|
1401 return KErrNotFound; |
|
1402 if (!TChar::IsSurrogate(aStart[0])) |
|
1403 { |
|
1404 aCurrentChar = aStart[0]; |
|
1405 aNewStart = const_cast<TText16*> (aStart + 1); |
|
1406 return KErrNone; |
|
1407 } |
|
1408 else if (TChar::IsHighSurrogate(aStart[0])) |
|
1409 { |
|
1410 if (aEnd < aStart + 2) |
|
1411 return KErrCorruptSurrogateFound; |
|
1412 if (!TChar::IsLowSurrogate(aStart[1])) |
|
1413 { |
|
1414 aNewStart = const_cast<TText16*> (aStart + 2); |
|
1415 return KErrCorruptSurrogateFound; |
|
1416 } |
|
1417 aCurrentChar = TChar::JoinSurrogate(aStart[0], aStart[1]); |
|
1418 aNewStart = const_cast<TText16*> (aStart + 2); |
|
1419 return KErrNone; |
|
1420 } |
|
1421 else |
|
1422 { |
|
1423 aNewStart = const_cast<TText16*> (aStart); |
|
1424 return KErrCorruptSurrogateFound; |
|
1425 } |
|
1426 } |
|
1427 |
|
1428 /** |
|
1429 * A helper function, which moves a pointer one or more Unicode characters forward. |
|
1430 * |
|
1431 * This function starts from aStart, stops when one of below conditions matched: |
|
1432 * 1) 16-bit position >= (aEnd - aStart); |
|
1433 * 2) 16-bit position >= aMaxInt16Position; |
|
1434 * 3) character position >= aMaxCharacterPosition; |
|
1435 * |
|
1436 * Specify a huge integer (say KMaskDesLength16) for aMaxInt16Position or |
|
1437 * aMaxCharacterPosition to indicate unlimited 16-bit position or character |
|
1438 * position. |
|
1439 * |
|
1440 * When return, aOutInt16Position, aOutCharacterPosition and aLastChar will |
|
1441 * indicate the same one character, whose |
|
1442 * 16-bit position <= aMaxInt16Position, and |
|
1443 * character position <= aMaxCharacterPosition. |
|
1444 * |
|
1445 * @return KErrNone if no error found; |
|
1446 * KErrNotFound if get to aEnd before find wanted position; or, |
|
1447 * if aMaxIntPosition<=0 or aMaxCharacterPosition<=0; |
|
1448 * KErrCorruptSurrogateFound if meet corrupt surrogate. |
|
1449 */ |
|
1450 TInt ProceedMultiCharacters(const TText16* aStart, const TText16* aEnd, |
|
1451 const TInt aMaxInt16Position, const TInt aMaxCharacterPosition, |
|
1452 TInt& aOutInt16Position, TInt& aOutCharacterPosition, TUint& aLastChar) |
|
1453 { |
|
1454 TText16 *next; |
|
1455 TInt status = KErrNotFound; |
|
1456 aOutInt16Position = 0; |
|
1457 aOutCharacterPosition = 0; |
|
1458 while (aOutInt16Position <= aMaxInt16Position && aOutCharacterPosition <= aMaxCharacterPosition) |
|
1459 { |
|
1460 status = ::ProceedOneCharacter(aStart+aOutInt16Position, aEnd, next, aLastChar); |
|
1461 if (status == KErrNotFound || status == KErrCorruptSurrogateFound) |
|
1462 return status; |
|
1463 if (next - aStart > aMaxInt16Position || aOutInt16Position == aMaxInt16Position || aOutCharacterPosition == aMaxCharacterPosition) |
|
1464 { |
|
1465 return status; |
|
1466 } |
|
1467 aOutInt16Position = (next - aStart); |
|
1468 ++aOutCharacterPosition; |
|
1469 } |
|
1470 return status; |
|
1471 } |
|
1472 |
|
1473 EXPORT_C TInt TDesC16::FindCorruptSurrogate() const |
|
1474 /** |
|
1475 Look for the first corrupt surrogate in the descriptor. |
|
1476 |
|
1477 @return The 16-bit position of the first corrupt surrogate. KErrNotFound, if |
|
1478 not found. |
|
1479 */ |
|
1480 { |
|
1481 // Do not use TUTF32Iterator, because it hides some characters, including corrupt surrogate. |
|
1482 TInt strLength = Length(); |
|
1483 |
|
1484 const TText16* start = Ptr(); |
|
1485 const TText16* end = Ptr() + strLength; |
|
1486 TInt int16Pos; |
|
1487 TInt charPos; |
|
1488 TUint lastChar; |
|
1489 TInt status = ::ProceedMultiCharacters(start, end, KMaskDesLength16, KMaskDesLength16, int16Pos, charPos, lastChar); |
|
1490 if (status == KErrCorruptSurrogateFound) |
|
1491 return int16Pos; |
|
1492 return KErrNotFound; |
|
1493 } |
|
1494 |
|
1495 EXPORT_C TInt TDesC16::Locate2(TChar aChar) const |
|
1496 /** |
|
1497 The surrogate aware version of Locate(). |
|
1498 |
|
1499 Searches for the first occurrence of a character within this descriptor's |
|
1500 data. |
|
1501 |
|
1502 The search starts at the beginning of the data, i.e. at the leftmost |
|
1503 position. |
|
1504 |
|
1505 @param aChar The Unicode character to be found. Can be inside or outside BMP. |
|
1506 |
|
1507 @return The offset of the character position from the beginning of the data. |
|
1508 KErrNotFound, if no matching character can be found. |
|
1509 KErrCorruptSurrogateFound, if meet corrupt surrogate in the searching. |
|
1510 |
|
1511 @see TDesC16::Locate() |
|
1512 */ |
|
1513 { |
|
1514 TInt strLength = Length(); |
|
1515 const TText16* start = Ptr(); |
|
1516 const TText16* end = Ptr() + strLength; |
|
1517 TText16* next; |
|
1518 TUint currentChar; |
|
1519 TInt int16Index = 0; |
|
1520 TInt status = KErrNone; |
|
1521 FOREVER |
|
1522 { |
|
1523 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
1524 if (status != KErrNone) |
|
1525 return status; |
|
1526 if (currentChar == aChar) |
|
1527 return int16Index; |
|
1528 int16Index = (next - start); |
|
1529 } |
|
1530 } |
|
1531 |
|
1532 LOCAL_C TInt DoLocateF16_2(const TDesC16& aDes, TUint aChar) |
|
1533 // Surrogate-aware version of DoLocateF16(). |
|
1534 // Locate character aChar in the descriptor folded. |
|
1535 { |
|
1536 const TText* table = convTable(EMatchFolded); |
|
1537 TUint aChar32 = aChar; |
|
1538 aChar = lookup2(aChar32, table); |
|
1539 |
|
1540 // find aChar in aDes |
|
1541 TInt strLength = aDes.Length(); |
|
1542 const TText16* start = aDes.Ptr(); |
|
1543 const TText16* end = aDes.Ptr() + strLength; |
|
1544 TText16* next; |
|
1545 TUint currentChar; |
|
1546 TInt int16Index = 0; |
|
1547 TInt status = KErrNone; |
|
1548 while (status == KErrNone) |
|
1549 { |
|
1550 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
1551 if (status != KErrNone) |
|
1552 break; |
|
1553 if (lookup2(currentChar, table) == aChar) |
|
1554 return int16Index; |
|
1555 int16Index = (next - start); |
|
1556 } |
|
1557 return status; |
|
1558 } |
|
1559 |
|
1560 EXPORT_C TInt TDesC16::LocateF2(TChar aChar) const |
|
1561 /** |
|
1562 The surrogate aware version of LocateF(). |
|
1563 |
|
1564 Searches for the first occurrence of a folded character within this |
|
1565 descriptor's folded data. |
|
1566 |
|
1567 The search starts at the beginning of the data, i.e. at the leftmost |
|
1568 position. |
|
1569 |
|
1570 Note that folding is locale-independent behaviour. It is also important to |
|
1571 note that there can be no guarantee that folding is in any way culturally |
|
1572 appropriate, and should not be used for searching strings in natural language. |
|
1573 |
|
1574 @param aChar The Unicode character to be found. Can be inside or outside BMP. |
|
1575 |
|
1576 @return The offset of the character position from the beginning of the data. |
|
1577 KErrNotFound, if no matching character can be found. |
|
1578 KErrCorruptSurrogateFound, if meet corrupt surrogate in the searching. |
|
1579 |
|
1580 @see TDesC16::LocateF() |
|
1581 */ |
|
1582 { |
|
1583 return DoLocateF16_2(*this, aChar); |
|
1584 } |
|
1585 |
|
1586 /** |
|
1587 * Proceed backward from aEnd toward aStart by one character. |
|
1588 * |
|
1589 * @aStart points to the first 16-bit unit in a descriptor. |
|
1590 * @aEnd points to the 16-bit unit after the last one. So, count of 16-bit |
|
1591 * units to process is (aEnd-aStart). |
|
1592 * |
|
1593 * On return, |
|
1594 * if valid character found, then return KErrNone, with aNewEnd pointing |
|
1595 * to the character found; |
|
1596 * if meet corrupt surrogate before find a valid character, then return |
|
1597 * KErrCorruptSurrogateFound, with aNewStart point to the corrupt |
|
1598 * surrogate; |
|
1599 * if aStart met, then return KErrNotFound. |
|
1600 * |
|
1601 * @return KErrNone if ok; |
|
1602 * KErrNotFound if get to aStart; |
|
1603 * KErrCorruptSurrogateFound if meet corrupt surrogate. |
|
1604 */ |
|
1605 TInt RecedeOneCharacter(const TText16* aStart, const TText16* aEnd, TText16*& aNewEnd, TUint& aCurrentChar) |
|
1606 { |
|
1607 if (!aStart || !aEnd || aStart>=aEnd) |
|
1608 return KErrNotFound; |
|
1609 if (!TChar::IsSurrogate(aEnd[-1])) |
|
1610 { |
|
1611 aCurrentChar = aEnd[-1]; |
|
1612 aNewEnd = const_cast<TText16*> (aEnd - 1); |
|
1613 return KErrNone; |
|
1614 } |
|
1615 else if (TChar::IsLowSurrogate(aEnd[-1])) |
|
1616 { |
|
1617 if (aEnd < aStart + 2) |
|
1618 return KErrNotFound; |
|
1619 if (!TChar::IsHighSurrogate(aEnd[-2])) |
|
1620 { |
|
1621 aNewEnd = const_cast<TText16*> (aEnd - 2); |
|
1622 return KErrCorruptSurrogateFound; |
|
1623 } |
|
1624 aCurrentChar = TChar::JoinSurrogate(aEnd[-2], aEnd[-1]); |
|
1625 aNewEnd = const_cast<TText16*> (aEnd - 2); |
|
1626 return KErrNone; |
|
1627 } |
|
1628 else |
|
1629 { |
|
1630 aNewEnd = const_cast<TText16*> (aEnd); |
|
1631 return KErrCorruptSurrogateFound; |
|
1632 } |
|
1633 } |
|
1634 |
|
1635 EXPORT_C TInt TDesC16::LocateReverse2(TChar aChar) const |
|
1636 /** |
|
1637 The surrogate aware version of LocateReverse(). |
|
1638 |
|
1639 Searches for the first occurrence of a character within this descriptor's |
|
1640 data, searching from the end of the data. |
|
1641 |
|
1642 The search starts at the rightmost position. |
|
1643 |
|
1644 @param aChar The Unicode character to be found. Can be inside or outside BMP. |
|
1645 |
|
1646 @return The offset of the character position from the beginning of the data. |
|
1647 KErrNotFound, if no matching character can be found. |
|
1648 KErrCorruptSurrogateFound, if meet corrupt surrogate in the searching. |
|
1649 |
|
1650 @see TDesC16::LocateReverse() |
|
1651 */ |
|
1652 { |
|
1653 TInt strLength = Length(); |
|
1654 const TText16* start = Ptr(); |
|
1655 TText16* newEnd; |
|
1656 TUint currentChar; |
|
1657 TInt int16Index = strLength; |
|
1658 TInt status = KErrNone; |
|
1659 FOREVER |
|
1660 { |
|
1661 status = ::RecedeOneCharacter(start, start+int16Index, newEnd, currentChar); |
|
1662 if (status != KErrNone) |
|
1663 return status; |
|
1664 int16Index = (newEnd - start); |
|
1665 if (currentChar == aChar) |
|
1666 return int16Index; |
|
1667 } |
|
1668 } |
|
1669 |
|
1670 EXPORT_C TInt TDesC16::LocateReverseF2(TChar aChar) const |
|
1671 /** |
|
1672 The surrogate aware version of LocateReverseF(). |
|
1673 |
|
1674 Searches for the first occurrence of a folded character within this descriptor's |
|
1675 folded data, searching from the end of the data. |
|
1676 |
|
1677 The search starts at the rightmost position. |
|
1678 |
|
1679 Note that folding is locale-independent behaviour. It is also important to |
|
1680 note that there can be no guarantee that folding is in any way culturally |
|
1681 appropriate, and should not be used for searching strings in natural language. |
|
1682 |
|
1683 @param aChar The Unicode character to be found. Can be inside or outside BMP. |
|
1684 |
|
1685 @return The offset of the character position from the beginning of the data. |
|
1686 KErrNotFound, if no matching character can be found. |
|
1687 KErrCorruptSurrogateFound, if meet corrupt surrogate in the searching. |
|
1688 |
|
1689 @see TDesC16::LocateReverseF() |
|
1690 */ |
|
1691 { |
|
1692 TInt strLength = Length(); |
|
1693 const TText16* start = Ptr(); |
|
1694 TText16* newEnd; |
|
1695 TUint currentChar; |
|
1696 TInt int16Index = strLength; |
|
1697 TInt status = KErrNone; |
|
1698 FOREVER |
|
1699 { |
|
1700 status = ::RecedeOneCharacter(start, start+int16Index, newEnd, currentChar); |
|
1701 if (status != KErrNone) |
|
1702 return status; |
|
1703 int16Index = (newEnd - start); |
|
1704 TCharF c(currentChar); |
|
1705 if (c == aChar) |
|
1706 return int16Index; |
|
1707 } |
|
1708 } |
|
1709 |
|
1710 inline TUint conv2(TUint aChar, const TText *aConv, const TUnicodeDataSet* aCharDataSet) |
|
1711 // Surrogate-aware version of conv(). |
|
1712 // If aConv is not NULL then convert the character. |
|
1713 { |
|
1714 if (aConv) |
|
1715 return TUnicode(aChar).Fold((TInt)aConv, aCharDataSet); |
|
1716 else |
|
1717 return aChar; |
|
1718 } |
|
1719 |
|
1720 // Surrogate-aware version of DoMatch16(). |
|
1721 // This helper function uses the same search algorithm as DoMatch16(). |
|
1722 TInt DoMatch16_2(const TDesC16 &aLeftD, const TDesC16 &aRightD, TMatchType aType) |
|
1723 { |
|
1724 const TText* table=convTable(aType); |
|
1725 const TUint16* const pRight=aRightD.Ptr(); |
|
1726 const TUint16* pM=pRight-1; // pre-increment addressing |
|
1727 const TUint16* const pP=pM+aRightD.Length(); |
|
1728 const TUint16* const pLeft=aLeftD.Ptr()-1; // pre-increment addressing |
|
1729 const TUint16* pB=pLeft; |
|
1730 const TUint16* pB2=pLeft; // always points to current char; pB2==pB or pB-1 |
|
1731 const TUint16* const pE=pB+aLeftD.Length(); |
|
1732 |
|
1733 // Note: pM and pB always point to the int16 unit before the character to handle. |
|
1734 // so, pM[0] and pB[0] may be a low surrogate. |
|
1735 // but, pM[1] and pB[1] must be start of a character. |
|
1736 // Note: pB2 always points to current character being handled. |
|
1737 // pB2 is used to generated return value. |
|
1738 // if pB[0] is low surrogate, then pB2=pB-1; |
|
1739 // if pB[0] is BMP, then pB2=pB. |
|
1740 // |
|
1741 // A 'diagram' shows the pointers: |
|
1742 // |
|
1743 // before search: |
|
1744 // left: ############################ |
|
1745 // ^ ^ |
|
1746 // pLeft/pB/pB2 pE |
|
1747 // |
|
1748 // right: ############################ |
|
1749 // ^^ ^ |
|
1750 // pM pRight pP |
|
1751 // |
|
1752 // |
|
1753 // after several iterations (C is the next character going to be checked): |
|
1754 // left: ###############C############ |
|
1755 // ^ ^ ^ |
|
1756 // pLeft pB/pB2 pE |
|
1757 // |
|
1758 // right: ##########C################# |
|
1759 // ^ ^ ^ |
|
1760 // pRight pM pP |
|
1761 // |
|
1762 |
|
1763 const TUnicodeDataSet* charDataSet = GetLocaleCharSet()->iCharDataSet; |
|
1764 |
|
1765 // Match any pattern up to the first star |
|
1766 TUint c; |
|
1767 TInt status; |
|
1768 TText* newStart; |
|
1769 for (;;) |
|
1770 { |
|
1771 status = ::ProceedOneCharacter(pM+1, pP+1, newStart, c); |
|
1772 if (status == KErrCorruptSurrogateFound) |
|
1773 return KErrCorruptSurrogateFound; |
|
1774 if (status == KErrNotFound) // exhausted the pattern |
|
1775 return pB==pE ? 0 : KErrNotFound; |
|
1776 pM = newStart - 1; |
|
1777 c = conv2(c, table, charDataSet); |
|
1778 if (c==KMatchAny) |
|
1779 break; |
|
1780 if (pB==pE) // no more input |
|
1781 return KErrNotFound; |
|
1782 TUint c2; |
|
1783 pB2 = pB + 1; |
|
1784 status = ::ProceedOneCharacter(pB+1, pE+1, newStart, c2); |
|
1785 if (status == KErrCorruptSurrogateFound) |
|
1786 return KErrCorruptSurrogateFound; |
|
1787 pB = newStart - 1; |
|
1788 if (c != conv2(c2, table, charDataSet) && c != KMatchOne) // match failed |
|
1789 return KErrNotFound; |
|
1790 } |
|
1791 // reached a star |
|
1792 if (pM==pP) |
|
1793 return 0; |
|
1794 TInt r=pM==pRight ? -1 : 0; // r = how many int16 has been matched in candidate (aLeftD) |
|
1795 for (;;) |
|
1796 { |
|
1797 status = ::ProceedOneCharacter(pM+1, pP+1, newStart, c); |
|
1798 if (status == KErrCorruptSurrogateFound) |
|
1799 return KErrCorruptSurrogateFound; |
|
1800 pM = newStart - 1; |
|
1801 c = conv2(c, table, charDataSet); |
|
1802 if (c==KMatchAny) |
|
1803 { |
|
1804 star: if (pM==pP) // star at end of pattern, always matches |
|
1805 return Max(r,0); |
|
1806 if (r<-1) // skipped some '?', matches at beginning |
|
1807 r=0; |
|
1808 continue; |
|
1809 } |
|
1810 if (pB==pE) // no more input |
|
1811 return KErrNotFound; |
|
1812 if (c==KMatchOne) |
|
1813 { // skip a character in the input |
|
1814 if (pM==pP) |
|
1815 return r+((r>=0) ? 0 : (pE-pLeft)); |
|
1816 TUint dummyC; |
|
1817 pB2 = pB + 1; |
|
1818 status = ::ProceedOneCharacter(pB+1, pE+1, newStart, dummyC); |
|
1819 if (status == KErrCorruptSurrogateFound) |
|
1820 return KErrCorruptSurrogateFound; |
|
1821 pB = newStart - 1; |
|
1822 if (r < 0) |
|
1823 r -= (newStart - pB2); // back r by 1 or 2, depending on dummyC is BMP or non-BMP. |
|
1824 continue; |
|
1825 } |
|
1826 // Matching a non-wild character |
|
1827 for (;;) |
|
1828 { |
|
1829 if (table) |
|
1830 { |
|
1831 TUint c2; |
|
1832 for (;;) |
|
1833 { |
|
1834 pB2 = pB + 1; |
|
1835 status = ::ProceedOneCharacter(pB+1, pE+1, newStart, c2); |
|
1836 if (status == KErrCorruptSurrogateFound) |
|
1837 return KErrCorruptSurrogateFound; |
|
1838 pB = newStart - 1; |
|
1839 if (lookup2(c2, table) == c) |
|
1840 break; |
|
1841 if (pB==pE) // no more input |
|
1842 return KErrNotFound; |
|
1843 } |
|
1844 } |
|
1845 else |
|
1846 { |
|
1847 TUint c2; |
|
1848 for (;;) |
|
1849 { |
|
1850 pB2 = pB + 1; |
|
1851 status = ::ProceedOneCharacter(pB+1, pE+1, newStart, c2); |
|
1852 if (status == KErrCorruptSurrogateFound) |
|
1853 return KErrCorruptSurrogateFound; |
|
1854 pB = newStart - 1; |
|
1855 if (c2 == c) |
|
1856 break; |
|
1857 if (pB==pE) // no more input |
|
1858 return KErrNotFound; |
|
1859 } |
|
1860 } |
|
1861 // Try to match up to the next star |
|
1862 const TUint16* pb=pB; |
|
1863 const TUint16* pm=pM; |
|
1864 for (;;) |
|
1865 { |
|
1866 if (pm<pP) |
|
1867 { |
|
1868 TUint cc; |
|
1869 status = ::ProceedOneCharacter(pm+1, pP+1, newStart, cc); |
|
1870 if (status == KErrCorruptSurrogateFound) |
|
1871 return KErrCorruptSurrogateFound; |
|
1872 pm = newStart - 1; |
|
1873 cc = conv2(cc, table, charDataSet); |
|
1874 if (cc==KMatchAny) |
|
1875 { // sub-match successful, back to main loop |
|
1876 r+=(r>=0 ? 0 : pB2-pLeft); |
|
1877 pB=pb; |
|
1878 pM=pm; |
|
1879 goto star; |
|
1880 } |
|
1881 if (pb==pE) |
|
1882 return KErrNotFound; // no more input |
|
1883 TUint cc2; |
|
1884 status = ::ProceedOneCharacter(pb+1, pE+1, newStart, cc2); |
|
1885 if (status == KErrCorruptSurrogateFound) |
|
1886 return KErrCorruptSurrogateFound; |
|
1887 pb = newStart - 1; |
|
1888 if (cc != conv2(cc2, table, charDataSet) && cc != KMatchOne) |
|
1889 break; // sub-match failed, try next input character |
|
1890 } |
|
1891 else if (pb==pE) // end of matching pattern |
|
1892 { |
|
1893 return r+(r>=0 ? 0 : pB2-pLeft); // end of input, so have a match |
|
1894 } |
|
1895 else |
|
1896 break; // try next input character |
|
1897 } |
|
1898 } |
|
1899 } |
|
1900 } |
|
1901 |
|
1902 EXPORT_C TInt TDesC16::Match2(const TDesC16 &aDes) const |
|
1903 /** |
|
1904 The surrogate aware version of Match(). |
|
1905 |
|
1906 Searches this descriptor's data for a match with the match pattern supplied |
|
1907 in the specified descriptor. |
|
1908 |
|
1909 The match pattern can contain the wildcard characters "*" and "?", where "*" |
|
1910 matches zero or more consecutive occurrences of any character and "?" matches |
|
1911 a single occurrence of any character. |
|
1912 |
|
1913 Note that there is no 'escape character', which means that it is not possible |
|
1914 to match either the "*" character itself or the "?" character itself using |
|
1915 this function. |
|
1916 |
|
1917 @param aDes A 16-bit non-modifable descriptor containing the match pattern. |
|
1918 |
|
1919 @return If a match is found, the offset within this descriptor's data where |
|
1920 the match first occurs. KErrNotFound, if there is no match. |
|
1921 KErrCorruptSurrogateFound, if meet corrupt surrogate in the searching. |
|
1922 |
|
1923 @see TDesC16::Match() |
|
1924 */ |
|
1925 { |
|
1926 return DoMatch16_2(*this, aDes, EMatchNormal); |
|
1927 } |
|
1928 |
1371 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__) |
1929 #if !defined( __DES16_MACHINE_CODED__) | defined(__EABI_CTORS__) |
1372 EXPORT_C TBufCBase16::TBufCBase16() |
1930 EXPORT_C TBufCBase16::TBufCBase16() |
1373 // |
1931 // |
1374 // Constructor |
1932 // Constructor |
1375 // |
1933 // |
3381 VA_LIST list; |
3939 VA_LIST list; |
3382 VA_START(list,aFmt); |
3940 VA_START(list,aFmt); |
3383 AppendFormatList(aFmt,list); |
3941 AppendFormatList(aFmt,list); |
3384 } |
3942 } |
3385 |
3943 |
|
3944 EXPORT_C void TDes16::Append2(TChar aChar) |
|
3945 /** |
|
3946 The surrogate aware version of Append(). |
|
3947 |
|
3948 Appends data onto the end of this descriptor's data. |
|
3949 |
|
3950 The length of this descriptor is incremented to reflect the new content. The |
|
3951 length will be increased by 1 if aChar is inside BMP or 2 if aChar is outside |
|
3952 BMP. |
|
3953 |
|
3954 @param aChar A single character to be appended. Can be inside or outside BMP. |
|
3955 |
|
3956 @panic USER 11 if the resulting new length of this descriptor is greater than |
|
3957 its maximum length. |
|
3958 |
|
3959 @panic USER 217 if corrupt surrogate found in aChar. This functions will not |
|
3960 validate already existing surrogate in the descriptor. |
|
3961 |
|
3962 @see TDes16::Append() |
|
3963 */ |
|
3964 { |
|
3965 __ASSERT_ALWAYS(TChar::IsSupplementary(aChar) || !TChar::IsSurrogate((TText16)aChar), Panic(ECorruptSurrogateFound)); |
|
3966 |
|
3967 TInt len = Length(); |
|
3968 TUint16 *pB = WPtr() + len; |
|
3969 if (TChar::IsSupplementary(aChar)) |
|
3970 { |
|
3971 SetLength(len + 2); |
|
3972 *pB++ = TChar::GetHighSurrogate(aChar); |
|
3973 *pB = TChar::GetLowSurrogate(aChar); |
|
3974 } |
|
3975 else |
|
3976 { |
|
3977 SetLength(len + 1); |
|
3978 *pB = (TText16)aChar; |
|
3979 } |
|
3980 } |
|
3981 |
|
3982 EXPORT_C void TDes16::Fill2(TChar aChar) |
|
3983 /** |
|
3984 The surrogate aware version of Fill(). |
|
3985 |
|
3986 Fills the descriptor's data area with the specified character, replacing any |
|
3987 existing data. |
|
3988 |
|
3989 The descriptor is filled from the beginning up to its current length. The |
|
3990 descriptor's length does not change. It is not filled to its maximum length. |
|
3991 If aChar is supplementary character, and available space to fill is odd in |
|
3992 16-bit unit, then the last 16-bit unit will be filled with high surrogate, |
|
3993 and the length will keep unchanged. |
|
3994 |
|
3995 @param aChar The fill character. Can be inside or outside BMP. |
|
3996 |
|
3997 @see TDes16::Fill() |
|
3998 */ |
|
3999 { |
|
4000 TUint16 *pB = WPtr(); |
|
4001 TUint16 *pE = pB + Length(); |
|
4002 if (!TChar::IsSupplementary(aChar)) |
|
4003 { |
|
4004 while (pB < pE) |
|
4005 *pB++ = (TUint16)aChar; |
|
4006 } |
|
4007 else |
|
4008 { |
|
4009 while (pB < pE - 1) |
|
4010 { |
|
4011 *pB++ = TChar::GetHighSurrogate(aChar); |
|
4012 *pB++ = TChar::GetLowSurrogate(aChar); |
|
4013 } |
|
4014 // fill the last 16-bit unit |
|
4015 if (pB < pE) |
|
4016 *pB++ = TChar::GetHighSurrogate(aChar); |
|
4017 } |
|
4018 } |
|
4019 |
|
4020 EXPORT_C void TDes16::Fill2(TChar aChar, TInt aLength) |
|
4021 /** |
|
4022 The surrogate aware version of Fill(). |
|
4023 |
|
4024 Fills the descriptor's data area with the specified character, replacing any |
|
4025 existing data. |
|
4026 |
|
4027 The descriptor is filled with the specified number of characters, |
|
4028 and its length is changed to reflect this. |
|
4029 |
|
4030 If aChar is supplementary character, and available space to fill is odd in |
|
4031 16-bit unit, then the last 16-bit unit will be left unchanged. |
|
4032 |
|
4033 @param aChar The fill character. Can be inside or outside BMP. |
|
4034 @param aLength The new length of the descriptor. |
|
4035 |
|
4036 @panic USER 11 if aLength is negative or is greater than the maximum length |
|
4037 of this descriptor. |
|
4038 |
|
4039 @panic USER 217 if corrupt surrogate found in aChar. These functions will not |
|
4040 validate already existing surrogate in the descriptor. |
|
4041 |
|
4042 @see TDes16::Fill() |
|
4043 */ |
|
4044 { |
|
4045 __ASSERT_ALWAYS(TChar::IsSupplementary(aChar) || !TChar::IsSurrogate((TText16)aChar), Panic(ECorruptSurrogateFound)); |
|
4046 |
|
4047 SetLength(aLength); |
|
4048 Fill2(aChar); |
|
4049 } |
|
4050 |
|
4051 EXPORT_C void TDes16::AppendFill2(TChar aChar, TInt aLength) |
|
4052 /** |
|
4053 The surrogate aware version of AppendFill(). |
|
4054 |
|
4055 Appends and fills this descriptor with the specified character. |
|
4056 |
|
4057 The descriptor is appended with the specified number of characters, and its |
|
4058 length is changed to reflect this. |
|
4059 |
|
4060 If aChar is supplementary character, and available space to fill is odd in |
|
4061 16-bit unit, then the last 16-bit unit will be filled with high surrogate. |
|
4062 |
|
4063 @param aChar The fill character. Can be inside or outside BMP. |
|
4064 @param aLength The length of additional space to append into. |
|
4065 |
|
4066 @panic USER 11 if aLength is negative, or the resulting length of this |
|
4067 descriptor is greater than its maximum length. |
|
4068 |
|
4069 @panic USER 217 if corrupt surrogate found in aChar. These functions will not |
|
4070 validate already existing surrogate in the descriptor. |
|
4071 |
|
4072 @see TDes16::AppendFill() |
|
4073 */ |
|
4074 { |
|
4075 __ASSERT_ALWAYS(TChar::IsSupplementary(aChar) || !TChar::IsSurrogate((TText16)aChar), Panic(ECorruptSurrogateFound)); |
|
4076 |
|
4077 TInt len=Length(); |
|
4078 TUint16 *pB=WPtr()+len; |
|
4079 SetLength(len+aLength); |
|
4080 TUint16 *pE=pB+aLength; |
|
4081 if (!TChar::IsSupplementary(aChar)) |
|
4082 { |
|
4083 while (pB < pE) |
|
4084 *pB++ = (TUint16)aChar; |
|
4085 } |
|
4086 else |
|
4087 { |
|
4088 while (pB < pE - 1) |
|
4089 { |
|
4090 *pB++ = TChar::GetHighSurrogate(aChar); |
|
4091 *pB++ = TChar::GetLowSurrogate(aChar); |
|
4092 } |
|
4093 // fill the last 16-bit unit |
|
4094 if (pB < pE) |
|
4095 *pB++ = TChar::GetHighSurrogate(aChar); |
|
4096 } |
|
4097 } |
|
4098 |
|
4099 EXPORT_C void TDes16::Justify2(const TDesC16 &aDes, TInt aWidth, TAlign anAlignment, TChar aFill) |
|
4100 /** |
|
4101 The surrogate aware version of Justify(). |
|
4102 |
|
4103 Copies data into this descriptor and justifies it, replacing any existing data. |
|
4104 |
|
4105 The length of this descriptor is set to reflect the new data. |
|
4106 |
|
4107 The target area is considered to be an area of specified width positioned at |
|
4108 the beginning of this descriptor's data area. Source data is copied into, and |
|
4109 aligned within this target area according to the specified alignment |
|
4110 instruction. |
|
4111 |
|
4112 If the length of the target area is larger than the length of the source, then |
|
4113 spare space within the target area is padded with the fill character. |
|
4114 |
|
4115 @param aDes A 16-bit non-modifiable descriptor containing the source data. |
|
4116 The length of the data to be copied is the smaller of: |
|
4117 the length of the source descriptor, and |
|
4118 the width of the target area (only if this is not the |
|
4119 explicit negative value KDefaultJustifyWidth). |
|
4120 |
|
4121 @param aWidth The width of the target area. If this has the specific |
|
4122 negative value KDefaultJustifyWidth, then the width is |
|
4123 re-set to the length of the data source. |
|
4124 |
|
4125 @param anAlignment The alignment of the data within the target area |
|
4126 |
|
4127 @param aFill The fill character used to pad the target area. Can be |
|
4128 inside or outside BMP. |
|
4129 |
|
4130 @panic USER 11 if the resulting length of this descriptor is greater than |
|
4131 its maximum length or aWidth has a negative value other |
|
4132 than KDefaultJustifyWidth. |
|
4133 |
|
4134 @panic USER 217 if corrupt surrogate found in the parameters or in the |
|
4135 descriptor. |
|
4136 |
|
4137 @see TDes16::Justify() |
|
4138 */ |
|
4139 { |
|
4140 Zero(); |
|
4141 AppendJustify2(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill); |
|
4142 } |
|
4143 |
|
4144 EXPORT_C void TDes16::AppendJustify2(const TDesC16 &aDes, TInt aWidth, TAlign anAlignment, TChar aFill) |
|
4145 /** |
|
4146 The surrogate aware version of AppendJustify. |
|
4147 |
|
4148 Appends data onto the end of this descriptor's data and justifies it. |
|
4149 |
|
4150 The source of the appended data is an existing descriptor. |
|
4151 |
|
4152 The target area is considered to be an area of specified width, immediately |
|
4153 following this descriptor's existing data. Source data is copied into, and |
|
4154 aligned within this target area according to the specified alignment instruction. |
|
4155 |
|
4156 If the length of the target area is larger than the length of the source, |
|
4157 then spare space within the target area is padded with the fill character. |
|
4158 |
|
4159 @param aDes A 16-bit non-modifiable descriptor containing the source |
|
4160 data. The length of the data to be copied is the smaller of: |
|
4161 the length of the source descriptor, and |
|
4162 the width of the target area (only if this is not the |
|
4163 explicit negative value KDefaultJustifyWidth). |
|
4164 |
|
4165 @param aWidth The width of the target area. If this has the specific |
|
4166 negative value KDefaultJustifyWidth, then the width is |
|
4167 re-set to the length of the data source. |
|
4168 |
|
4169 @param anAlignment The alignment of the data within the target area. |
|
4170 |
|
4171 @param aFill The fill character used to pad the target area. Can be |
|
4172 inside or outside BMP. |
|
4173 |
|
4174 @panic USER 11 if the resulting length of this descriptor is greater than |
|
4175 its maximum length or aWidth has a negative value other |
|
4176 than KDefaultJustifyWidth. |
|
4177 |
|
4178 @panic USER 217 if corrupt surrogate found in the parameters or in the |
|
4179 descriptor. |
|
4180 |
|
4181 @see TDes16::AppendJustify() |
|
4182 */ |
|
4183 { |
|
4184 AppendJustify2(aDes.Ptr(),aDes.Length(),aWidth,anAlignment,aFill); |
|
4185 } |
|
4186 |
|
4187 EXPORT_C void TDes16::AppendJustify2(const TDesC16 &aDes, TInt aLength, TInt aWidth, TAlign anAlignment, TChar aFill) |
|
4188 /** |
|
4189 The surrogate aware version of AppendJustify. |
|
4190 |
|
4191 Appends data onto the end of this descriptor's data and justifies it. |
|
4192 |
|
4193 The source of the appended data is an existing descriptor. |
|
4194 |
|
4195 The target area is considered to be an area of specified width, immediately |
|
4196 following this descriptor's existing data. Source data is copied into, and |
|
4197 aligned within this target area according to the specified alignment instruction. |
|
4198 |
|
4199 If the length of the target area is larger than the length of the source, |
|
4200 then spare space within the target area is padded with the fill character. |
|
4201 |
|
4202 @param aDes An 8-bit non-modifiable descriptor containing the source data. |
|
4203 |
|
4204 @param aLength The length of data to be copied from the source descriptor. |
|
4205 If this is greater than the width of the target area, then |
|
4206 the length of data copied is limited to the width. |
|
4207 The length of data to be copied must not be greater than |
|
4208 the length of the source descriptor. Note that this |
|
4209 condition is not automatically tested. |
|
4210 |
|
4211 @param aWidth The width of the target area. If this has the specific negative |
|
4212 value KDefaultJustifyWidth, then the width is |
|
4213 re-set to the length of the data source. |
|
4214 |
|
4215 @param anAlignment The alignment of the data within the target area. |
|
4216 |
|
4217 @param aFill The fill character used to pad the target area. Can be |
|
4218 inside or outside BMP. |
|
4219 |
|
4220 @panic USER 11 if the resulting length of this descriptor is greater than |
|
4221 its maximum length or aWidth has a negative value other |
|
4222 than KDefaultJustifyWidth. |
|
4223 |
|
4224 @panic USER 217 if corrupt surrogate found in the parameters or in the |
|
4225 descriptor. |
|
4226 |
|
4227 @see TDes16::AppendJustify() |
|
4228 */ |
|
4229 { |
|
4230 AppendJustify2(aDes.Ptr(),aLength,aWidth,anAlignment,aFill); |
|
4231 } |
|
4232 |
|
4233 EXPORT_C void TDes16::AppendJustify2(const TUint16 *aString, TInt aWidth, TAlign anAlignment, TChar aFill) |
|
4234 /** |
|
4235 The surrogate aware version of AppendJustify. |
|
4236 |
|
4237 Appends a zero terminated string onto the end of this descriptor's data and |
|
4238 justifies it. |
|
4239 |
|
4240 The zero terminator is not copied. |
|
4241 |
|
4242 The target area is considered to be an area of specified width, immediately |
|
4243 following this descriptor's existing data. Source data is copied into, and |
|
4244 aligned within, this target area according to the specified alignment instruction. |
|
4245 |
|
4246 If the length of the target area is larger than the length of the source, |
|
4247 then spare space within the target area is padded with the fill character. |
|
4248 |
|
4249 @param aString A pointer to a zero terminated string The length of the data |
|
4250 to be copied is the smaller of: the length of the string (excluding the zero |
|
4251 terminator), the width of the target area (only if this is not the explicit |
|
4252 negative value KDefaultJustifyWidth). |
|
4253 |
|
4254 @param aWidth The width of the target area. If this has the specific negative |
|
4255 value KDefaultJustifyWidth, then the width is re-set to the length of the |
|
4256 zero terminated string (excluding the zero terminator). |
|
4257 |
|
4258 @param anAlignment The alignment of the data within the target area. |
|
4259 |
|
4260 @param aFill The fill character used to pad the target area. Can be |
|
4261 inside or outside BMP. |
|
4262 |
|
4263 @panic USER 11 if the resulting length of this descriptor is greater than |
|
4264 its maximum length or aWidth has a negative value other |
|
4265 than KDefaultJustifyWidth. |
|
4266 |
|
4267 @panic USER 217 if corrupt surrogate found in the parameters or in the |
|
4268 descriptor. |
|
4269 |
|
4270 @see TDes16::AppendJustify() |
|
4271 */ |
|
4272 { |
|
4273 __CHECK_ALIGNMENT(aString,ETDes16AppendJustify1); |
|
4274 AppendJustify2(aString,STRING_LENGTH_16(aString),aWidth,anAlignment,aFill); |
|
4275 } |
|
4276 |
|
4277 EXPORT_C void TDes16::AppendJustify2(const TUint16 *aString, TInt aLength, TInt aWidth, TAlign anAlignment, TChar aFill) |
|
4278 /** |
|
4279 The surrogate aware version of AppendJustify. |
|
4280 |
|
4281 Appends data onto the end of this descriptor's data and justifies it. |
|
4282 |
|
4283 The source of the appended data is a memory location. |
|
4284 |
|
4285 The target area is considered to be an area of specified width, immediately |
|
4286 following this descriptor's existing data. Source data is copied into, and |
|
4287 aligned within, this target area according to the specified alignment instruction. |
|
4288 |
|
4289 If the length of the target area is larger than the length of the source, |
|
4290 then spare space within the target area is padded with the fill character. |
|
4291 |
|
4292 @param aString A pointer to a source memory location. |
|
4293 |
|
4294 @param aLength The length of data to be copied. If this is greater than the |
|
4295 width of the target area, then the length of data copied is |
|
4296 limited to the width. |
|
4297 |
|
4298 @param aWidth The width of the target area. If this has the specific negative |
|
4299 value KDefaultJustifyWidth, then the width is |
|
4300 re-set to the length of the data source. |
|
4301 |
|
4302 @param anAlignment The alignment of the data within the target area. |
|
4303 |
|
4304 @param aFill The fill character used to pad the target area. Can be |
|
4305 inside or outside BMP. |
|
4306 |
|
4307 @panic USER 11 if the resulting length of this descriptor is greater than |
|
4308 its maximum length or aWidth has a negative value other |
|
4309 than KDefaultJustifyWidth. |
|
4310 |
|
4311 @panic USER 17 if aLength is negative. |
|
4312 |
|
4313 @panic USER 217 if corrupt surrogate found in the parameters or in the |
|
4314 descriptor. |
|
4315 |
|
4316 @see TDes16::AppendJustify() |
|
4317 */ |
|
4318 { |
|
4319 __ASSERT_ALWAYS(aLength>=0,Panic(ETDes16LengthNegative)); |
|
4320 __CHECK_ALIGNMENT(aString,ETDes16AppendJustify2); |
|
4321 if (aWidth==KDefaultJustifyWidth) |
|
4322 aWidth=aLength; |
|
4323 if (aLength>aWidth) |
|
4324 aLength=aWidth; |
|
4325 TInt offset=Length(); |
|
4326 AppendFill2(aFill,aWidth); |
|
4327 TInt r=aWidth-aLength; |
|
4328 if (anAlignment==ECenter) |
|
4329 r>>=1; |
|
4330 else if (anAlignment==ELeft) |
|
4331 r=0; |
|
4332 memCopy(WPtr()+offset+r,aString,aLength); |
|
4333 } |
|
4334 |
|
4335 EXPORT_C void TDes16::Fold2() |
|
4336 /** |
|
4337 The surrogate aware version of Fold(). |
|
4338 |
|
4339 Performs folding on the content of this descriptor. |
|
4340 |
|
4341 Note that folding is locale-independent behaviour. It is also important to |
|
4342 note that there can be no guarantee that folding is in any way culturally |
|
4343 appropriate, and should not be used when dealing with strings in natural |
|
4344 language. |
|
4345 |
|
4346 @panic USER 217 if corrupt surrogate found in the descriptor. |
|
4347 |
|
4348 @see TDes16::Fold() |
|
4349 */ |
|
4350 { |
|
4351 TInt strLength = Length(); |
|
4352 TText16* start = WPtr(); |
|
4353 const TText16* end = Ptr() + strLength; |
|
4354 TText16* next; |
|
4355 TUint currentChar; |
|
4356 TInt int16Index = 0; |
|
4357 TInt status = KErrNone; |
|
4358 FOREVER |
|
4359 { |
|
4360 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4361 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4362 if (status == KErrNotFound) |
|
4363 break; |
|
4364 TCharF c(currentChar); |
|
4365 // at present, c and currentChar always in the same plane |
|
4366 if (TChar::IsSupplementary(c)) |
|
4367 { |
|
4368 start[int16Index] = TChar::GetHighSurrogate(c); |
|
4369 start[int16Index+1] = TChar::GetLowSurrogate(c); |
|
4370 } |
|
4371 else |
|
4372 { |
|
4373 start[int16Index] = (TText16)c; |
|
4374 } |
|
4375 int16Index = (next - start); |
|
4376 } |
|
4377 } |
|
4378 |
|
4379 EXPORT_C void TDes16::Collate2() |
|
4380 /** |
|
4381 The surrogate aware version of Collate(). |
|
4382 |
|
4383 Performs collation on the content of this descriptor. |
|
4384 |
|
4385 @panic USER 217 if corrupt surrogate found in the descriptor. |
|
4386 |
|
4387 @see TDes16::Collate() |
|
4388 */ |
|
4389 { |
|
4390 TInt strLength = Length(); |
|
4391 TText16* start = WPtr(); |
|
4392 const TText16* end = Ptr() + strLength; |
|
4393 TText16* next; |
|
4394 TUint currentChar; |
|
4395 TInt int16Index = 0; |
|
4396 TInt status = KErrNone; |
|
4397 FOREVER |
|
4398 { |
|
4399 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4400 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4401 if (status == KErrNotFound) |
|
4402 break; |
|
4403 TChar c = User::Collate(currentChar); |
|
4404 // at present, c and currentChar always in the same plane |
|
4405 if (TChar::IsSupplementary(c)) |
|
4406 { |
|
4407 start[int16Index] = TChar::GetHighSurrogate(c); |
|
4408 start[int16Index+1] = TChar::GetLowSurrogate(c); |
|
4409 } |
|
4410 else |
|
4411 { |
|
4412 start[int16Index] = (TText16)c; |
|
4413 } |
|
4414 int16Index = (next - start); |
|
4415 } |
|
4416 } |
|
4417 |
|
4418 EXPORT_C void TDes16::LowerCase2() |
|
4419 /** |
|
4420 The surrogate aware version of LowerCase(). |
|
4421 |
|
4422 Converts the content of this descriptor to lower case. |
|
4423 |
|
4424 Conversion is implemented as appropriate to the current locale. |
|
4425 |
|
4426 @panic USER 217 if corrupt surrogate found in the descriptor. |
|
4427 |
|
4428 @see TDes16::LowerCase() |
|
4429 */ |
|
4430 { |
|
4431 TInt strLength = Length(); |
|
4432 TText16* start = WPtr(); |
|
4433 const TText16* end = Ptr() + strLength; |
|
4434 TText16* next; |
|
4435 TUint currentChar; |
|
4436 TInt int16Index = 0; |
|
4437 TInt status = KErrNone; |
|
4438 FOREVER |
|
4439 { |
|
4440 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4441 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4442 if (status == KErrNotFound) |
|
4443 break; |
|
4444 TCharLC c(currentChar); |
|
4445 // at present, c and currentChar always in the same plane |
|
4446 if (TChar::IsSupplementary(c)) |
|
4447 { |
|
4448 start[int16Index] = TChar::GetHighSurrogate(c); |
|
4449 start[int16Index+1] = TChar::GetLowSurrogate(c); |
|
4450 } |
|
4451 else |
|
4452 { |
|
4453 start[int16Index] = (TText16)c; |
|
4454 } |
|
4455 int16Index = (next - start); |
|
4456 } |
|
4457 } |
|
4458 |
|
4459 EXPORT_C void TDes16::UpperCase2() |
|
4460 /** |
|
4461 The surrogate aware version of UpperCase(). |
|
4462 |
|
4463 Converts the content of this descriptor to upper case. |
|
4464 |
|
4465 Conversion is implemented as appropriate to the current locale. |
|
4466 |
|
4467 @panic USER 217 if corrupt surrogate found in the descriptor. |
|
4468 |
|
4469 @see TDes16::UpperCase() |
|
4470 */ |
|
4471 { |
|
4472 TInt strLength = Length(); |
|
4473 TText16* start = WPtr(); |
|
4474 const TText16* end = Ptr() + strLength; |
|
4475 TText16* next; |
|
4476 TUint currentChar; |
|
4477 TInt int16Index = 0; |
|
4478 TInt status = KErrNone; |
|
4479 FOREVER |
|
4480 { |
|
4481 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4482 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4483 if (status == KErrNotFound) |
|
4484 break; |
|
4485 TCharUC c(currentChar); |
|
4486 // at present, c and currentChar always in the same plane |
|
4487 if (TChar::IsSupplementary(c)) |
|
4488 { |
|
4489 start[int16Index] = TChar::GetHighSurrogate(c); |
|
4490 start[int16Index+1] = TChar::GetLowSurrogate(c); |
|
4491 } |
|
4492 else |
|
4493 { |
|
4494 start[int16Index] = (TText16)c; |
|
4495 } |
|
4496 int16Index = (next - start); |
|
4497 } |
|
4498 } |
|
4499 |
|
4500 EXPORT_C void TDes16::Capitalize2() |
|
4501 /** |
|
4502 The surrogate aware version of Capitalize(). |
|
4503 |
|
4504 Capitalises the content of this descriptor. |
|
4505 |
|
4506 Capitalisation is implemented as appropriate to the current locale. |
|
4507 |
|
4508 @panic USER 217 if corrupt surrogate found in the descriptor. |
|
4509 |
|
4510 @see TDes16::Capitalize() |
|
4511 */ |
|
4512 { |
|
4513 TInt strLength = Length(); |
|
4514 TText16* start = WPtr(); |
|
4515 const TText16* end = Ptr() + strLength; |
|
4516 TText16* next; |
|
4517 TUint currentChar; |
|
4518 TInt int16Index = 0; |
|
4519 TInt status = KErrNone; |
|
4520 |
|
4521 // the first character: title case |
|
4522 status = ::ProceedOneCharacter(start, end, next, currentChar); |
|
4523 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4524 TChar c = User::TitleCase(currentChar); |
|
4525 // at present, c and currentChar always in the same plane |
|
4526 if (TChar::IsSupplementary(c)) |
|
4527 { |
|
4528 start[0] = TChar::GetHighSurrogate(c); |
|
4529 start[1] = TChar::GetLowSurrogate(c); |
|
4530 } |
|
4531 else |
|
4532 { |
|
4533 start[0] = (TText16)c; |
|
4534 } |
|
4535 int16Index = (next - start); |
|
4536 |
|
4537 // following characters: lower case |
|
4538 FOREVER |
|
4539 { |
|
4540 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4541 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4542 if (status == KErrNotFound) |
|
4543 break; |
|
4544 TChar c = User::LowerCase(currentChar); |
|
4545 // at present, c and currentChar always in the same plane |
|
4546 if (TChar::IsSupplementary(c)) |
|
4547 { |
|
4548 start[int16Index] = TChar::GetHighSurrogate(c); |
|
4549 start[int16Index+1] = TChar::GetLowSurrogate(c); |
|
4550 } |
|
4551 else |
|
4552 { |
|
4553 start[int16Index] = (TText16)c; |
|
4554 } |
|
4555 int16Index = (next - start); |
|
4556 } |
|
4557 } |
|
4558 |
|
4559 EXPORT_C void TDes16::CopyF2(const TDesC16 &aDes) |
|
4560 /** |
|
4561 The surrogate aware version of CopyF(). |
|
4562 |
|
4563 Copies and folds data from the specified descriptor into this descriptor replacing |
|
4564 any existing data. |
|
4565 |
|
4566 The length of this descriptor is set to reflect the new |
|
4567 data. |
|
4568 |
|
4569 Note that folding is locale-independent behaviour. It is also important to |
|
4570 note that there can be no guarantee that folding is in any way culturally |
|
4571 appropriate, and should not be used when dealing with strings in natural |
|
4572 language. |
|
4573 |
|
4574 @param aDes A 16-bit non-modifiable descriptor. |
|
4575 |
|
4576 @panic USER 11 if the length of aDes is greater than the maximum length of |
|
4577 this target descriptor. |
|
4578 |
|
4579 @panic USER 217 if corrupt surrogate found in aDes or in the descriptor. |
|
4580 |
|
4581 @see TDes16::CopyF() |
|
4582 */ |
|
4583 { |
|
4584 TText16* pT = WPtr(); |
|
4585 TInt len = 0; |
|
4586 const TInt maxLen = MaxLength(); |
|
4587 |
|
4588 // iterate through aDes |
|
4589 TInt strLength = aDes.Length(); |
|
4590 const TText16* start = aDes.Ptr(); |
|
4591 const TText16* end = aDes.Ptr() + strLength; |
|
4592 TText16* next; |
|
4593 TUint currentChar; |
|
4594 TInt int16Index = 0; |
|
4595 TInt status = KErrNone; |
|
4596 FOREVER |
|
4597 { |
|
4598 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4599 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4600 if (status == KErrNotFound) |
|
4601 break; |
|
4602 int16Index = (next - start); |
|
4603 TCharF c(currentChar); |
|
4604 if (TChar::IsSupplementary(c)) |
|
4605 { |
|
4606 len += 2; |
|
4607 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4608 pT[len-2] = TChar::GetHighSurrogate(c); |
|
4609 pT[len-1] = TChar::GetLowSurrogate(c); |
|
4610 } |
|
4611 else |
|
4612 { |
|
4613 ++len; |
|
4614 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4615 pT[len-1] = (TText16)c; |
|
4616 } |
|
4617 } |
|
4618 SetLength(len); |
|
4619 } |
|
4620 |
|
4621 EXPORT_C void TDes16::CopyC2(const TDesC16 &aDes) |
|
4622 /** |
|
4623 The surrogate aware version of CopyC(). |
|
4624 |
|
4625 Copies and collates data from the specified descriptor |
|
4626 into this descriptor replacing any existing data. |
|
4627 |
|
4628 The length of this descriptor is set to reflect the new data. |
|
4629 |
|
4630 @param aDes A 16-bit non-modifiable descriptor. |
|
4631 |
|
4632 @panic USER 11 if the length of aDes is greater than the maximum length of |
|
4633 this target descriptor. |
|
4634 |
|
4635 @panic USER 217 if corrupt surrogate found in aDes or in the descriptor. |
|
4636 |
|
4637 @see TDes16::CopyC() |
|
4638 */ |
|
4639 { |
|
4640 TText16* pT = WPtr(); |
|
4641 TInt len = 0; |
|
4642 const TInt maxLen = MaxLength(); |
|
4643 |
|
4644 // iterate through aDes |
|
4645 TInt strLength = aDes.Length(); |
|
4646 const TText16* start = aDes.Ptr(); |
|
4647 const TText16* end = aDes.Ptr() + strLength; |
|
4648 TText16* next; |
|
4649 TUint currentChar; |
|
4650 TInt int16Index = 0; |
|
4651 TInt status = KErrNone; |
|
4652 FOREVER |
|
4653 { |
|
4654 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4655 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4656 if (status == KErrNotFound) |
|
4657 break; |
|
4658 int16Index = (next - start); |
|
4659 TChar c = User::Collate(currentChar); |
|
4660 if (TChar::IsSupplementary(c)) |
|
4661 { |
|
4662 len += 2; |
|
4663 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4664 pT[len-2] = TChar::GetHighSurrogate(c); |
|
4665 pT[len-1] = TChar::GetLowSurrogate(c); |
|
4666 } |
|
4667 else |
|
4668 { |
|
4669 ++len; |
|
4670 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4671 pT[len-1] = (TText16)c; |
|
4672 } |
|
4673 } |
|
4674 SetLength(len); |
|
4675 } |
|
4676 |
|
4677 EXPORT_C void TDes16::CopyLC2(const TDesC16 &aDes) |
|
4678 /** |
|
4679 The surrogate aware version of CopyLC(). |
|
4680 |
|
4681 Copies text from the specified descriptor and converts it to lower case before |
|
4682 putting it into this descriptor, replacing any existing data. |
|
4683 |
|
4684 The length of this descriptor is set to reflect the new data. |
|
4685 |
|
4686 Conversion to lower case is implemented as appropriate to the current locale. |
|
4687 |
|
4688 @param aDes A 16-bit non modifiable descriptor. |
|
4689 |
|
4690 @panic USER 11 if the length of aDes is greater than the maximum length of |
|
4691 this target descriptor. |
|
4692 |
|
4693 @panic USER 217 if corrupt surrogate found in aDes or in the descriptor. |
|
4694 |
|
4695 @see TDes16::CopyLC() |
|
4696 */ |
|
4697 { |
|
4698 TText16* pT = WPtr(); |
|
4699 TInt len = 0; |
|
4700 const TInt maxLen = MaxLength(); |
|
4701 |
|
4702 // iterate through aDes |
|
4703 TInt strLength = aDes.Length(); |
|
4704 const TText16* start = aDes.Ptr(); |
|
4705 const TText16* end = aDes.Ptr() + strLength; |
|
4706 TText16* next; |
|
4707 TUint currentChar; |
|
4708 TInt int16Index = 0; |
|
4709 TInt status = KErrNone; |
|
4710 FOREVER |
|
4711 { |
|
4712 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4713 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4714 if (status == KErrNotFound) |
|
4715 break; |
|
4716 int16Index = (next - start); |
|
4717 TCharLC c(currentChar); |
|
4718 if (TChar::IsSupplementary(c)) |
|
4719 { |
|
4720 len += 2; |
|
4721 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4722 pT[len-2] = TChar::GetHighSurrogate(c); |
|
4723 pT[len-1] = TChar::GetLowSurrogate(c); |
|
4724 } |
|
4725 else |
|
4726 { |
|
4727 ++len; |
|
4728 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4729 pT[len-1] = (TText16)c; |
|
4730 } |
|
4731 } |
|
4732 SetLength(len); |
|
4733 } |
|
4734 |
|
4735 EXPORT_C void TDes16::CopyUC2(const TDesC16 &aDes) |
|
4736 /** |
|
4737 The surrogate aware version of CopyUC(). |
|
4738 |
|
4739 Copies text from the specified descriptor and converts it to upper case before |
|
4740 putting it into this descriptor, replacing any existing data. |
|
4741 |
|
4742 The length of this descriptor is set to reflect the new data. |
|
4743 |
|
4744 Conversion to upper case is implemented as appropriate to the current locale. |
|
4745 |
|
4746 @param aDes A 16-bit non modifiable descriptor. |
|
4747 |
|
4748 @panic USER 11 if the length of aDes is greater than the maximum length of |
|
4749 this target descriptor. |
|
4750 |
|
4751 @panic USER 217 if corrupt surrogate found in aDes or in the descriptor. |
|
4752 |
|
4753 @see TDes16::CopyUC() |
|
4754 */ |
|
4755 { |
|
4756 TText16* pT = WPtr(); |
|
4757 TInt len = 0; |
|
4758 const TInt maxLen = MaxLength(); |
|
4759 |
|
4760 // iterate through aDes |
|
4761 TInt strLength = aDes.Length(); |
|
4762 const TText16* start = aDes.Ptr(); |
|
4763 const TText16* end = aDes.Ptr() + strLength; |
|
4764 TText16* next; |
|
4765 TUint currentChar; |
|
4766 TInt int16Index = 0; |
|
4767 TInt status = KErrNone; |
|
4768 FOREVER |
|
4769 { |
|
4770 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4771 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4772 if (status == KErrNotFound) |
|
4773 break; |
|
4774 int16Index = (next - start); |
|
4775 TCharUC c(currentChar); |
|
4776 if (TChar::IsSupplementary(c)) |
|
4777 { |
|
4778 len += 2; |
|
4779 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4780 pT[len-2] = TChar::GetHighSurrogate(c); |
|
4781 pT[len-1] = TChar::GetLowSurrogate(c); |
|
4782 } |
|
4783 else |
|
4784 { |
|
4785 ++len; |
|
4786 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4787 pT[len-1] = (TText16)c; |
|
4788 } |
|
4789 } |
|
4790 SetLength(len); |
|
4791 } |
|
4792 |
|
4793 EXPORT_C void TDes16::CopyCP2(const TDesC16 &aDes) |
|
4794 /** |
|
4795 The surrogate aware version of CopyCP(). |
|
4796 |
|
4797 Copies text from the specified descriptor and capitalises it before putting |
|
4798 it into this descriptor, replacing any existing data. |
|
4799 |
|
4800 The length of this descriptor is set to reflect the new data. |
|
4801 |
|
4802 Capitalisation is implemented as appropriate to the current locale. |
|
4803 |
|
4804 @param aDes A 16-bit non-modifiable descriptor. |
|
4805 |
|
4806 @panic USER 11 if the length of aDes is greater than the maximum length of |
|
4807 this target descriptor. |
|
4808 |
|
4809 @panic USER 217 if corrupt surrogate found in aDes or in the descriptor. |
|
4810 |
|
4811 @see TDes16::CopyCP() |
|
4812 */ |
|
4813 { |
|
4814 TText16* pT = WPtr(); |
|
4815 TInt len = 0; |
|
4816 const TInt maxLen = MaxLength(); |
|
4817 |
|
4818 // iterate through aDes |
|
4819 TInt strLength = aDes.Length(); |
|
4820 const TText16* start = aDes.Ptr(); |
|
4821 const TText16* end = aDes.Ptr() + strLength; |
|
4822 TText16* next; |
|
4823 TUint currentChar; |
|
4824 TInt int16Index = 0; |
|
4825 TInt status = KErrNone; |
|
4826 |
|
4827 // first character: title case |
|
4828 status = ::ProceedOneCharacter(start, end, next, currentChar); |
|
4829 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4830 int16Index = (next - start); |
|
4831 TChar c(currentChar); |
|
4832 c.TitleCase(); |
|
4833 if (TChar::IsSupplementary(c)) |
|
4834 { |
|
4835 len += 2; |
|
4836 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4837 pT[len-2] = TChar::GetHighSurrogate(c); |
|
4838 pT[len-1] = TChar::GetLowSurrogate(c); |
|
4839 } |
|
4840 else |
|
4841 { |
|
4842 ++len; |
|
4843 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4844 pT[len-1] = (TText16)c; |
|
4845 } |
|
4846 |
|
4847 // following characters: lower case |
|
4848 FOREVER |
|
4849 { |
|
4850 status = ::ProceedOneCharacter(start+int16Index, end, next, currentChar); |
|
4851 __ASSERT_ALWAYS(status != KErrCorruptSurrogateFound, Panic(ECorruptSurrogateFound)); |
|
4852 if (status == KErrNotFound) |
|
4853 break; |
|
4854 int16Index = (next - start); |
|
4855 TCharLC c(currentChar); |
|
4856 if (TChar::IsSupplementary(c)) |
|
4857 { |
|
4858 len += 2; |
|
4859 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4860 pT[len-2] = TChar::GetHighSurrogate(c); |
|
4861 pT[len-1] = TChar::GetLowSurrogate(c); |
|
4862 } |
|
4863 else |
|
4864 { |
|
4865 ++len; |
|
4866 __ASSERT_ALWAYS(len<=maxLen, Panic(ETDes16Overflow)); |
|
4867 pT[len-1] = (TText16)c; |
|
4868 } |
|
4869 } |
|
4870 SetLength(len); |
|
4871 } |
|
4872 |
|
4873 |
3386 #if !defined(__DES16_MACHINE_CODED__) | defined(__EABI_CTORS__) |
4874 #if !defined(__DES16_MACHINE_CODED__) | defined(__EABI_CTORS__) |
3387 EXPORT_C TPtrC16::TPtrC16() |
4875 EXPORT_C TPtrC16::TPtrC16() |
3388 : TDesC16(EPtrC,0),iPtr(0) |
4876 : TDesC16(EPtrC,0),iPtr(0) |
3389 /** |
4877 /** |
3390 Constructs an empty 16-bit non-modifiable pointer descriptor. |
4878 Constructs an empty 16-bit non-modifiable pointer descriptor. |