kerneltest/e32test/buffer/t_match.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
    73 #include <f32file.h>
    73 #include <f32file.h>
    74 #include <collate.h>
    74 #include <collate.h>
    75 #include "collateimp.h"
    75 #include "collateimp.h"
    76 #include "CompareImp.h"
    76 #include "CompareImp.h"
    77 #include "u32std.h"
    77 #include "u32std.h"
       
    78 
       
    79 static inline TBool IsSupplementary(TUint aChar)
       
    80 /**
       
    81 @param aChar The 32-bit code point value of a Unicode character.
       
    82 
       
    83 @return True, if aChar is supplementary character; false, otherwise.
       
    84 */
       
    85         {
       
    86         return (aChar > 0xFFFF);
       
    87         }
       
    88 
       
    89 static inline TText16 GetHighSurrogate(TUint aChar)
       
    90 /**
       
    91 Retrieve the high surrogate of a supplementary character.
       
    92 
       
    93 @param aChar The 32-bit code point value of a Unicode character.
       
    94 
       
    95 @return High surrogate of aChar, if aChar is a supplementary character;
       
    96         aChar itself, if aChar is not a supplementary character.
       
    97 
       
    98 @see TChar::GetLowSurrogate
       
    99 */
       
   100         {
       
   101         return STATIC_CAST(TText16, 0xD7C0 + (aChar >> 10));
       
   102         }
       
   103 
       
   104 static inline TText16 GetLowSurrogate(TUint aChar)
       
   105 /**
       
   106 Retrieve the low surrogate of a supplementary character.
       
   107 
       
   108 @param aChar The 32-bit code point value of a Unicode character.
       
   109 
       
   110 @return Low surrogate of aChar, if aChar is a supplementary character;
       
   111         zero, if aChar is not a supplementary character.
       
   112 
       
   113 @see TChar::GetHighSurrogate
       
   114 */
       
   115         {
       
   116         return STATIC_CAST(TText16, 0xDC00 | (aChar & 0x3FF));
       
   117         }
       
   118 
    78 
   119 
    79 ///***************** copied from locale euser source code ***********************
   120 ///***************** copied from locale euser source code ***********************
    80 static const TCollationMethod TheCollationMethod[] =
   121 static const TCollationMethod TheCollationMethod[] =
    81 	{
   122 	{
    82 		{
   123 		{
  1594     for(len=0;!lex.Eos();++len)
  1635     for(len=0;!lex.Eos();++len)
  1595         {
  1636         {
  1596         TUint32 code;
  1637         TUint32 code;
  1597         User::LeaveIfError(lex.Val(code, EHex));
  1638         User::LeaveIfError(lex.Val(code, EHex));
  1598         lex.Assign(lex.NextToken());
  1639         lex.Assign(lex.NextToken());
  1599         if (!TChar::IsSupplementary(code))
  1640         if (!IsSupplementary(code))
  1600         	{
  1641         	{
  1601         	aStr[1+len] = (TUint16)code;
  1642         	aStr[1+len] = (TUint16)code;
  1602         	}
  1643         	}
  1603         else
  1644         else
  1604         	{
  1645         	{
  1605         	aStr[1+len] = TChar::GetHighSurrogate(code);
  1646         	aStr[1+len] = GetHighSurrogate(code);
  1606         	++len;
  1647         	++len;
  1607         	aStr[1+len] = TChar::GetLowSurrogate(code);
  1648         	aStr[1+len] = GetLowSurrogate(code);
  1608         	}
  1649         	}
  1609         }
  1650         }
  1610     __ASSERT_ALWAYS(len > 0, User::Invariant());
  1651     __ASSERT_ALWAYS(len > 0, User::Invariant());
  1611     aStr.SetLength(1 + len);
  1652     aStr.SetLength(1 + len);
  1612     }
  1653     }
  1665         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1706         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1666         if(chCode == (TUint32)0x0130)
  1707         if(chCode == (TUint32)0x0130)
  1667             {
  1708             {
  1668             continue;
  1709             continue;
  1669             }
  1710             }
  1670         if (!TChar::IsSupplementary(chCode))
  1711         if (!IsSupplementary(chCode))
  1671         	{
  1712         	{
  1672         	candidate[KChPos] = (TUint16)chCode;
  1713         	candidate[KChPos] = (TUint16)chCode;
  1673         	}
  1714         	}
  1674         else
  1715         else
  1675         	{
  1716         	{
  1676             candidate[KChPos] = TChar::GetHighSurrogate(chCode);
  1717             candidate[KChPos] = GetHighSurrogate(chCode);
  1677             candidate[KChPos+1] = TChar::GetLowSurrogate(chCode);
  1718             candidate[KChPos+1] = GetLowSurrogate(chCode);
  1678         	}
  1719         	}
  1679         //"Character decomposition mapping" is the 5th field, starting from 0.
  1720         //"Character decomposition mapping" is the 5th field, starting from 0.
  1680         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1721         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1681         if(decomp.Length() > 1 && decomp[0] != '<')
  1722         if(decomp.Length() > 1 && decomp[0] != '<')
  1682             {
  1723             {
  1719         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1760         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1720         if(chCode == (TUint32)0x0130)
  1761         if(chCode == (TUint32)0x0130)
  1721             {
  1762             {
  1722             continue;
  1763             continue;
  1723             }
  1764             }
  1724         if (!TChar::IsSupplementary(chCode))
  1765         if (!IsSupplementary(chCode))
  1725         	{
  1766         	{
  1726         	candidate[KChPos] = (TUint16)chCode;
  1767         	candidate[KChPos] = (TUint16)chCode;
  1727         	candidate.SetLength(2);
  1768         	candidate.SetLength(2);
  1728         	}
  1769         	}
  1729         else
  1770         else
  1730         	{
  1771         	{
  1731             candidate[KChPos] = TChar::GetHighSurrogate(chCode);
  1772             candidate[KChPos] = GetHighSurrogate(chCode);
  1732             candidate.SetLength(3);
  1773             candidate.SetLength(3);
  1733             candidate[KChPos+1] = TChar::GetLowSurrogate(chCode);
  1774             candidate[KChPos+1] = GetLowSurrogate(chCode);
  1734         	}
  1775         	}
  1735         //"Character decomposition mapping" is the 5th field, starting from 0.
  1776         //"Character decomposition mapping" is the 5th field, starting from 0.
  1736         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1777         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1737         if(decomp.Length() > 1 && decomp[0] != '<')
  1778         if(decomp.Length() > 1 && decomp[0] != '<')
  1738             {
  1779             {
  2511 	test( 0 == buf01c5.MatchF( K01c6() ) );
  2552 	test( 0 == buf01c5.MatchF( K01c6() ) );
  2512 	
  2553 	
  2513 	test.Next(_L("MatchSurrogate"));
  2554 	test.Next(_L("MatchSurrogate"));
  2514 	for (ii=0;ii<KTestsSurrogate;++ii)
  2555 	for (ii=0;ii<KTestsSurrogate;++ii)
  2515 		{
  2556 		{
  2516 		TInt r=TPtrC16(TestsSurrogate[ii].iLeft).Match2(TPtrC16(TestsSurrogate[ii].iRight));
  2557 		TInt r=TPtrC16(TestsSurrogate[ii].iLeft).MatchF(TPtrC16(TestsSurrogate[ii].iRight));
  2517 		RDebug::Printf("    ii=%d, expect=%d, result=%d", ii, TestsSurrogate[ii].iResult, r);
       
  2518 		test (r==TestsSurrogate[ii].iResult);
       
  2519 		r=TPtrC16(TestsSurrogate[ii].iLeft).MatchF(TPtrC16(TestsSurrogate[ii].iRight));
       
  2520 		test (r==TestsSurrogate[ii].iResult);
  2558 		test (r==TestsSurrogate[ii].iResult);
  2521 		}
  2559 		}
  2522 	
  2560 	
  2523 	_LIT( KD800, "\xd800" );
  2561 	_LIT( KD800, "\xd800" );
  2524 	_LIT( KQuestion, "?" );
  2562 	_LIT( KQuestion, "?" );
  2525 	_LIT( KDC00, "\xdc00" );
  2563 	_LIT( KDC00, "\xdc00" );
  2526 	_LIT( KDFFF, "\xdfff" );
  2564 	_LIT( KDFFF, "\xdfff" );
  2527 	test( KErrCorruptSurrogateFound == TPtrC16( KD800() ).Match2( TPtrC16( KQuestion() ) ) );
       
  2528 	test( KErrCorruptSurrogateFound == TPtrC16( KD800() ).Match2( TPtrC16( KD800() ) ) );
       
  2529 	test( KErrCorruptSurrogateFound == TPtrC16( KDC00() ).Match2( TPtrC16( KQuestion() ) ) );
       
  2530 	test( KErrCorruptSurrogateFound == TPtrC16( KDFFF() ).Match2( TPtrC16( KQuestion() ) ) );
       
  2531 
  2565 
  2532     test( KErrNotFound == TPtrC16( KD800() ).MatchF( TPtrC16( KQuestion() ) ) );
  2566     test( KErrNotFound == TPtrC16( KD800() ).MatchF( TPtrC16( KQuestion() ) ) );
  2533     test( 0 == TPtrC16( KD800() ).MatchF( TPtrC16( KD800() ) ) );
  2567     test( 0 == TPtrC16( KD800() ).MatchF( TPtrC16( KD800() ) ) );
  2534     test( KErrNotFound == TPtrC16( KDC00() ).MatchF( TPtrC16( KQuestion() ) ) );
  2568     test( KErrNotFound == TPtrC16( KDC00() ).MatchF( TPtrC16( KQuestion() ) ) );
  2535     test( KErrNotFound == TPtrC16( KDFFF() ).MatchF( TPtrC16( KQuestion() ) ) );
  2569     test( KErrNotFound == TPtrC16( KDFFF() ).MatchF( TPtrC16( KQuestion() ) ) );