kerneltest/e32test/buffer/t_match.cpp
changeset 90 947f0dc9f7a8
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
52:2d65c2f76d7b 90:947f0dc9f7a8
    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 
       
   119 
    78 
   120 ///***************** copied from locale euser source code ***********************
    79 ///***************** copied from locale euser source code ***********************
   121 static const TCollationMethod TheCollationMethod[] =
    80 static const TCollationMethod TheCollationMethod[] =
   122 	{
    81 	{
   123 		{
    82 		{
  1635     for(len=0;!lex.Eos();++len)
  1594     for(len=0;!lex.Eos();++len)
  1636         {
  1595         {
  1637         TUint32 code;
  1596         TUint32 code;
  1638         User::LeaveIfError(lex.Val(code, EHex));
  1597         User::LeaveIfError(lex.Val(code, EHex));
  1639         lex.Assign(lex.NextToken());
  1598         lex.Assign(lex.NextToken());
  1640         if (!IsSupplementary(code))
  1599         if (!TChar::IsSupplementary(code))
  1641         	{
  1600         	{
  1642         	aStr[1+len] = (TUint16)code;
  1601         	aStr[1+len] = (TUint16)code;
  1643         	}
  1602         	}
  1644         else
  1603         else
  1645         	{
  1604         	{
  1646         	aStr[1+len] = GetHighSurrogate(code);
  1605         	aStr[1+len] = TChar::GetHighSurrogate(code);
  1647         	++len;
  1606         	++len;
  1648         	aStr[1+len] = GetLowSurrogate(code);
  1607         	aStr[1+len] = TChar::GetLowSurrogate(code);
  1649         	}
  1608         	}
  1650         }
  1609         }
  1651     __ASSERT_ALWAYS(len > 0, User::Invariant());
  1610     __ASSERT_ALWAYS(len > 0, User::Invariant());
  1652     aStr.SetLength(1 + len);
  1611     aStr.SetLength(1 + len);
  1653     }
  1612     }
  1706         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1665         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1707         if(chCode == (TUint32)0x0130)
  1666         if(chCode == (TUint32)0x0130)
  1708             {
  1667             {
  1709             continue;
  1668             continue;
  1710             }
  1669             }
  1711         if (!IsSupplementary(chCode))
  1670         if (!TChar::IsSupplementary(chCode))
  1712         	{
  1671         	{
  1713         	candidate[KChPos] = (TUint16)chCode;
  1672         	candidate[KChPos] = (TUint16)chCode;
  1714         	}
  1673         	}
  1715         else
  1674         else
  1716         	{
  1675         	{
  1717             candidate[KChPos] = GetHighSurrogate(chCode);
  1676             candidate[KChPos] = TChar::GetHighSurrogate(chCode);
  1718             candidate[KChPos+1] = GetLowSurrogate(chCode);
  1677             candidate[KChPos+1] = TChar::GetLowSurrogate(chCode);
  1719         	}
  1678         	}
  1720         //"Character decomposition mapping" is the 5th field, starting from 0.
  1679         //"Character decomposition mapping" is the 5th field, starting from 0.
  1721         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1680         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1722         if(decomp.Length() > 1 && decomp[0] != '<')
  1681         if(decomp.Length() > 1 && decomp[0] != '<')
  1723             {
  1682             {
  1760         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1719         //"LATIN CAPITAL LETTER I WITH DOT ABOVE" - the searching algorithm does not work with it.
  1761         if(chCode == (TUint32)0x0130)
  1720         if(chCode == (TUint32)0x0130)
  1762             {
  1721             {
  1763             continue;
  1722             continue;
  1764             }
  1723             }
  1765         if (!IsSupplementary(chCode))
  1724         if (!TChar::IsSupplementary(chCode))
  1766         	{
  1725         	{
  1767         	candidate[KChPos] = (TUint16)chCode;
  1726         	candidate[KChPos] = (TUint16)chCode;
  1768         	candidate.SetLength(2);
  1727         	candidate.SetLength(2);
  1769         	}
  1728         	}
  1770         else
  1729         else
  1771         	{
  1730         	{
  1772             candidate[KChPos] = GetHighSurrogate(chCode);
  1731             candidate[KChPos] = TChar::GetHighSurrogate(chCode);
  1773             candidate.SetLength(3);
  1732             candidate.SetLength(3);
  1774             candidate[KChPos+1] = GetLowSurrogate(chCode);
  1733             candidate[KChPos+1] = TChar::GetLowSurrogate(chCode);
  1775         	}
  1734         	}
  1776         //"Character decomposition mapping" is the 5th field, starting from 0.
  1735         //"Character decomposition mapping" is the 5th field, starting from 0.
  1777         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1736         TPtrC8 decomp(GetUnicodeDataField(stmt, 5));
  1778         if(decomp.Length() > 1 && decomp[0] != '<')
  1737         if(decomp.Length() > 1 && decomp[0] != '<')
  1779             {
  1738             {
  2552 	test( 0 == buf01c5.MatchF( K01c6() ) );
  2511 	test( 0 == buf01c5.MatchF( K01c6() ) );
  2553 	
  2512 	
  2554 	test.Next(_L("MatchSurrogate"));
  2513 	test.Next(_L("MatchSurrogate"));
  2555 	for (ii=0;ii<KTestsSurrogate;++ii)
  2514 	for (ii=0;ii<KTestsSurrogate;++ii)
  2556 		{
  2515 		{
  2557 		TInt r=TPtrC16(TestsSurrogate[ii].iLeft).MatchF(TPtrC16(TestsSurrogate[ii].iRight));
  2516 		TInt r=TPtrC16(TestsSurrogate[ii].iLeft).Match2(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));
  2558 		test (r==TestsSurrogate[ii].iResult);
  2520 		test (r==TestsSurrogate[ii].iResult);
  2559 		}
  2521 		}
  2560 	
  2522 	
  2561 	_LIT( KD800, "\xd800" );
  2523 	_LIT( KD800, "\xd800" );
  2562 	_LIT( KQuestion, "?" );
  2524 	_LIT( KQuestion, "?" );
  2563 	_LIT( KDC00, "\xdc00" );
  2525 	_LIT( KDC00, "\xdc00" );
  2564 	_LIT( KDFFF, "\xdfff" );
  2526 	_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() ) ) );
  2565 
  2531 
  2566     test( KErrNotFound == TPtrC16( KD800() ).MatchF( TPtrC16( KQuestion() ) ) );
  2532     test( KErrNotFound == TPtrC16( KD800() ).MatchF( TPtrC16( KQuestion() ) ) );
  2567     test( 0 == TPtrC16( KD800() ).MatchF( TPtrC16( KD800() ) ) );
  2533     test( 0 == TPtrC16( KD800() ).MatchF( TPtrC16( KD800() ) ) );
  2568     test( KErrNotFound == TPtrC16( KDC00() ).MatchF( TPtrC16( KQuestion() ) ) );
  2534     test( KErrNotFound == TPtrC16( KDC00() ).MatchF( TPtrC16( KQuestion() ) ) );
  2569     test( KErrNotFound == TPtrC16( KDFFF() ).MatchF( TPtrC16( KQuestion() ) ) );
  2535     test( KErrNotFound == TPtrC16( KDFFF() ).MatchF( TPtrC16( KQuestion() ) ) );