|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // implementation for d32comp.h |
|
15 // |
|
16 // |
|
17 |
|
18 #include "UD_STD.H" |
|
19 #include "D32COMP.H" |
|
20 |
|
21 const TInt KCompareBufSize=0x200; // 0.5K |
|
22 |
|
23 // class Comp |
|
24 |
|
25 TInt Comp::Compare(TReal32 aLeft,TReal32 aRight) __SOFTFP |
|
26 { |
|
27 return aLeft<aRight ? -1 : aLeft!=aRight; |
|
28 } |
|
29 |
|
30 TInt Comp::Compare(TReal64 aLeft,TReal64 aRight) __SOFTFP |
|
31 { |
|
32 return aLeft<aRight ? -1 : aLeft!=aRight; |
|
33 } |
|
34 |
|
35 TInt Comp::Compare(const TInt64& aLeft,const TInt64& aRight) |
|
36 { |
|
37 return aLeft<aRight ? -1 : aLeft!=aRight; |
|
38 } |
|
39 |
|
40 TInt Comp::Compare8L(MStreamBuf& aBufL,MStreamBuf& aBufR,TInt aSize,const TTextOps& aTextOp) |
|
41 { |
|
42 const TInt KCompareBufLength=KCompareBufSize/sizeof(TText8); |
|
43 RReadStream left(&aBufL); |
|
44 RReadStream right(&aBufR); |
|
45 TText8 bufL[KCompareBufLength]; |
|
46 TText8 bufR[KCompareBufLength]; |
|
47 TInt read=KCompareBufLength; |
|
48 do |
|
49 { |
|
50 if (aSize<=read) |
|
51 read=aSize; |
|
52 left.ReadL(bufL,read); |
|
53 right.ReadL(bufR,read); |
|
54 TInt r=aTextOp.Compare(bufL,read,bufR,read); |
|
55 if (r!=0) |
|
56 return r; |
|
57 aSize-=KCompareBufLength; |
|
58 } while (aSize>0); |
|
59 return 0; |
|
60 } |
|
61 |
|
62 TInt Comp::Compare8L(MStreamBuf& aBuf,const TText8* aPtr,TInt aSize,const TTextOps& aTextOp) |
|
63 { |
|
64 const TInt KCompareBufLength=KCompareBufSize/sizeof(TText8); |
|
65 RReadStream strm(&aBuf); |
|
66 TText8 buf[KCompareBufLength]; |
|
67 TInt read=KCompareBufLength; |
|
68 do |
|
69 { |
|
70 if (aSize<read) |
|
71 read=aSize; |
|
72 strm.ReadL(buf,read); |
|
73 TInt r=aTextOp.Compare(buf,read,aPtr,read); |
|
74 if (r!=0) |
|
75 return r; |
|
76 aPtr+=KCompareBufLength; |
|
77 aSize-=KCompareBufLength; |
|
78 } while (aSize>0); |
|
79 return 0; |
|
80 } |
|
81 |
|
82 TInt Comp::Compare8L(MStreamBuf& aBuf,TInt aSize,const TDesC8& aDes,const TTextOps& aTextOp) |
|
83 { |
|
84 const TText8* ptr=aDes.Ptr(); |
|
85 TInt size=aDes.Length(); |
|
86 TInt r=Compare8L(aBuf,ptr,Min(size,aSize),aTextOp); |
|
87 return r ? r : aSize-size; |
|
88 } |
|
89 |
|
90 TInt Comp::Compare16L(MStreamBuf& aBufL,MStreamBuf& aBufR,TInt aSize,const TTextOps& aTextOp) |
|
91 { |
|
92 aSize >>= 1; |
|
93 const TInt KCompareBufLength=KCompareBufSize/sizeof(TText16); |
|
94 RReadStream left(&aBufL); |
|
95 RReadStream right(&aBufR); |
|
96 TText16 bufL[KCompareBufLength]; |
|
97 TText16 bufR[KCompareBufLength]; |
|
98 TInt read=KCompareBufLength; |
|
99 do |
|
100 { |
|
101 if (aSize<=read) |
|
102 read=aSize; |
|
103 left.ReadL(bufL,read); |
|
104 right.ReadL(bufR,read); |
|
105 TInt r=aTextOp.Order(bufL,read,bufR,read); |
|
106 if (r!=0) |
|
107 return r; |
|
108 aSize-=KCompareBufLength; |
|
109 } while (aSize>0); |
|
110 return 0; |
|
111 } |
|
112 |
|
113 TInt Comp::Compare16L(MStreamBuf& aBuf,const TText16* aPtr,TInt aSize,const TTextOps& aTextOp) |
|
114 { |
|
115 aSize >>= 1; |
|
116 const TInt KCompareBufLength=KCompareBufSize/sizeof(TText16); |
|
117 RReadStream strm(&aBuf); |
|
118 TText16 buf[KCompareBufLength]; |
|
119 TInt read=KCompareBufLength; |
|
120 do |
|
121 { |
|
122 if (aSize<read) |
|
123 read=aSize; |
|
124 strm.ReadL(buf,read); |
|
125 TInt r=aTextOp.Order(buf,read,aPtr,read); |
|
126 if (r!=0) |
|
127 return r; |
|
128 aPtr+=KCompareBufLength; |
|
129 aSize-=KCompareBufLength; |
|
130 } while (aSize>0); |
|
131 return 0; |
|
132 } |
|
133 |
|
134 static TInt DoCompare16L(MStreamBuf& aBuf,const TText16* aPtr,TInt aLen,const TTextOps& aTextOp) |
|
135 { |
|
136 const TInt KCompareBufLength=KCompareBufSize/sizeof(TText16); |
|
137 RReadStream strm(&aBuf); |
|
138 TText16 buf[KCompareBufLength]; |
|
139 TInt read=KCompareBufLength; |
|
140 do |
|
141 { |
|
142 if (aLen<read) |
|
143 read=aLen; |
|
144 strm.ReadL(buf,read); |
|
145 TInt r=aTextOp.Compare(buf,read,aPtr,read); |
|
146 if (r!=0) |
|
147 return r; |
|
148 aPtr+=KCompareBufLength; |
|
149 aLen-=KCompareBufLength; |
|
150 } while (aLen>0); |
|
151 return 0; |
|
152 } |
|
153 |
|
154 TInt Comp::Compare16L(MStreamBuf& aBuf,TInt aSize,const TDesC16& aDes,const TTextOps& aTextOp) |
|
155 { |
|
156 const TText16* ptr=aDes.Ptr(); |
|
157 TInt size=aDes.Length()<<1; |
|
158 TInt r=::DoCompare16L(aBuf,ptr,Min(size,aSize)>>1,aTextOp); |
|
159 return r ? r : aSize-size; |
|
160 } |
|
161 |