59
|
1 |
// Copyright (c) 1997-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 |
//
|
|
15 |
|
|
16 |
#include <langutil.h>
|
|
17 |
#include "T_LangUtilsTestShareFunc.h"
|
|
18 |
|
|
19 |
void DoCopyFileL(RFs& aFs, const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
|
|
20 |
{
|
|
21 |
CFileMan* fileMan=CFileMan::NewL(aFs);
|
|
22 |
CleanupStack::PushL(fileMan);
|
|
23 |
User::LeaveIfError(fileMan->Copy(aSourceFullName,aTargetFullName,aSwitch));
|
|
24 |
CleanupStack::PopAndDestroy(); // fileMan
|
|
25 |
}
|
|
26 |
|
|
27 |
|
|
28 |
TInt LangUtilsTest::CopyFile(RFs& aFs, const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
|
|
29 |
/** Copies one or more files.
|
|
30 |
|
|
31 |
For more details,
|
|
32 |
@see CFileMan::Copy()
|
|
33 |
@since 5.1
|
|
34 |
@param aFs File server session
|
|
35 |
@param aSourceFullName Path indicating the file(s) to be copied. Any path
|
|
36 |
components that are not specified here will be taken from the session path.
|
|
37 |
@param aTargetFullName Path indicating the directory into which the file(s)
|
|
38 |
are to be copied
|
|
39 |
@param aSwitch=CFileMan::EOverWrite Set this to zero for no overwriting and
|
|
40 |
no recursion; CFileMan::EOverWrite to overwrite files with the same name; or
|
|
41 |
CFileMan::ERecurse for recursion.
|
|
42 |
@return KErrNone if successful, otherwise another of the system-wide error
|
|
43 |
codes.*/
|
|
44 |
{
|
|
45 |
TRAPD(err,DoCopyFileL(aFs,aSourceFullName,aTargetFullName,aSwitch));
|
|
46 |
return err;
|
|
47 |
}
|
|
48 |
|
|
49 |
TBool LangUtilsTest::FileExists(const RFs& aFileSession,const TDesC& aFileName)
|
|
50 |
/** Checks if the specified file exists.
|
|
51 |
|
|
52 |
@param aFs File server session
|
|
53 |
@param aFileName File to check
|
|
54 |
@return ETrue if the file exists, otherwise EFalse */
|
|
55 |
{ // static
|
|
56 |
TEntry entry;
|
|
57 |
return(aFileSession.Entry(aFileName,entry)==KErrNone);
|
|
58 |
}
|
|
59 |
|
|
60 |
void DoDeleteFileL(RFs& aFs, const TDesC& aSourceFullName, TUint aSwitch)
|
|
61 |
{
|
|
62 |
CFileMan* fileMan=CFileMan::NewL(aFs);
|
|
63 |
CleanupStack::PushL(fileMan);
|
|
64 |
User::LeaveIfError(fileMan->Delete(aSourceFullName,aSwitch));
|
|
65 |
CleanupStack::PopAndDestroy(); // fileMan
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
EXPORT_C TInt LangUtilsTest::DeleteFile(RFs& aFs, const TDesC& aSourceFullName, TUint aSwitch)
|
|
70 |
/** Deletes one or more files.
|
|
71 |
|
|
72 |
For more details,
|
|
73 |
@see CFileMan::Delete().
|
|
74 |
@since 5.1
|
|
75 |
@param aFs File server session
|
|
76 |
@param aSourceFullName Path indicating the file(s) to be deleted. May either
|
|
77 |
be a full path, or relative to the session path. Use wildcards to specify
|
|
78 |
more than one file.
|
|
79 |
@param aSwitch=0 Specify CFileMan::ERecurse for recursion,
|
|
80 |
zero for no recursion.
|
|
81 |
@return KErrNone if successful, otherwise another of the system-wide error
|
|
82 |
codes. */
|
|
83 |
{
|
|
84 |
TRAPD(err,DoDeleteFileL(aFs,aSourceFullName,aSwitch));
|
|
85 |
return err;
|
|
86 |
}
|
|
87 |
|
|
88 |
NONSHARABLE_CLASS(TKeyDesC16Array) : public TKeyArrayFix
|
|
89 |
{
|
|
90 |
public:
|
|
91 |
TKeyDesC16Array(TKeyCmpText aType);
|
|
92 |
private: // from TKey
|
|
93 |
TInt Compare(TInt aLeft,TInt aRight) const;
|
|
94 |
};
|
|
95 |
|
|
96 |
TKeyDesC16Array::TKeyDesC16Array(TKeyCmpText aType)
|
|
97 |
: TKeyArrayFix(0,aType,0)
|
|
98 |
{
|
|
99 |
}
|
|
100 |
|
|
101 |
TInt TKeyDesC16Array::Compare(TInt aLeft,TInt aRight) const
|
|
102 |
{
|
|
103 |
TDesC16* left=(*(TDesC16**)At(aLeft));
|
|
104 |
TDesC16* right=(*(TDesC16**)At(aRight));
|
|
105 |
switch (iCmpType)
|
|
106 |
{
|
|
107 |
case ECmpFolded:
|
|
108 |
return(left->CompareF(*right));
|
|
109 |
case ECmpCollated:
|
|
110 |
return(left->CompareC(*right));
|
|
111 |
default:
|
|
112 |
break;
|
|
113 |
}
|
|
114 |
return(left->Compare(*right));
|
|
115 |
}
|
|
116 |
|
|
117 |
EXPORT_C CDesC16Array::CDesC16Array(TBufRep aRep,TInt aGranularity)
|
|
118 |
: CArrayFixBase(aRep,sizeof(HBufC16*),aGranularity)
|
|
119 |
{
|
|
120 |
}
|
|
121 |
|
|
122 |
EXPORT_C CDesC16Array::~CDesC16Array()
|
|
123 |
/** Frees all resources owned by the object, prior to its destruction. In particular,
|
|
124 |
it deletes all descriptors from the array and frees the memory allocated to
|
|
125 |
the array buffer. */
|
|
126 |
{
|
|
127 |
Reset();
|
|
128 |
}
|
|
129 |
|
|
130 |
EXPORT_C void CDesC16Array::Reset()
|
|
131 |
/** Deletes all descriptors from the array and frees the memory allocated to the
|
|
132 |
array buffer.
|
|
133 |
|
|
134 |
@see CDesC16Array::Delete() */
|
|
135 |
{
|
|
136 |
Delete(0,Count());
|
|
137 |
}
|
|
138 |
|
|
139 |
EXPORT_C void CDesC16Array::Delete(TInt aIndex)
|
|
140 |
{
|
|
141 |
Delete(aIndex,1);
|
|
142 |
}
|
|
143 |
|
|
144 |
/**
|
|
145 |
*
|
|
146 |
* Deletes one or more logically contiguous descriptor elements from the
|
|
147 |
* array.
|
|
148 |
*
|
|
149 |
* The deletion starts at the specified position.Deleting descriptor
|
|
150 |
* elements from the array frees the memory occupied by the associated
|
|
151 |
* heap descriptors and removes their pointers from the array buffer but
|
|
152 |
* does not cause the array buffer to be automatically compressed. Call
|
|
153 |
* the Compress() function to return excess space in the array buffer to
|
|
154 |
* the heap.
|
|
155 |
*
|
|
156 |
* @param " TInt aPos "
|
|
157 |
* The starting position in the array from which
|
|
158 |
* descriptor elements are to be deleted. The position is
|
|
159 |
* relative to zero, i.e. zero implies the first
|
|
160 |
* descriptor element. This value must not be negative
|
|
161 |
* and must not be greater than the number of descriptor
|
|
162 |
* elements currently in the array, otherwise the
|
|
163 |
* functions raise an E32USER-CBase 21 panic.
|
|
164 |
* @param " TInt aCount "
|
|
165 |
* If specified, the number of contiguous descriptor
|
|
166 |
* elements to be deleted from the array. This value must
|
|
167 |
* not be negative otherwise the function raises an
|
|
168 |
* E32USER-CBase 22 panic. This value must not be
|
|
169 |
* negative otherwise the function raises an
|
|
170 |
* E32USER-CBase 22 panic. This value must not be
|
|
171 |
* negative otherwise the function raises an
|
|
172 |
* E32USER-CBase 22 panic. This value plus the value of
|
|
173 |
* the starting position must not be greater than the
|
|
174 |
* number of descriptor elements in the array, otherwise
|
|
175 |
* the function raises an E32USER-CBase 29 panic. If not
|
|
176 |
* specified, one element is assumed.
|
|
177 |
*/
|
|
178 |
EXPORT_C void CDesC16Array::Delete(TInt aIndex,TInt aCount)
|
|
179 |
{
|
|
180 |
TInt count=aCount;
|
|
181 |
for (TInt ii=aIndex; count--; ii++)
|
|
182 |
User::Free(*(HBufC16**)At(ii));
|
|
183 |
CArrayFixBase::Delete(aIndex,aCount);
|
|
184 |
}
|
|
185 |
|
|
186 |
EXPORT_C TInt CDesC16Array::MdcaCount() const
|
|
187 |
/** Returns the number of descriptor elements in the array. The function implements
|
|
188 |
the function interface MDesC16Array::MdcaCount().
|
|
189 |
|
|
190 |
@return The number of descriptor elements. */
|
|
191 |
{
|
|
192 |
return Count();
|
|
193 |
}
|
|
194 |
|
|
195 |
EXPORT_C TPtrC16 CDesC16Array::MdcaPoint(TInt anIndex) const
|
|
196 |
/** Indexes into a descriptor array. The function implements the interface MDesC16Array::MdcaPoint().
|
|
197 |
|
|
198 |
@param aIndex The position of the descriptor element within the array. The
|
|
199 |
position is relative to zero; i.e. zero implies the first descriptor element
|
|
200 |
in the array. This value must be non-negative and less than the number of
|
|
201 |
descriptors currently within the array otherwise the operator panics with
|
|
202 |
EArrayIndexOutOfRange.
|
|
203 |
@return A non-modifiable pointer descriptor representing the descriptor element
|
|
204 |
located at position aIndex within the array. */
|
|
205 |
{
|
|
206 |
HBufC16* temp=(*(HBufC16**)At(anIndex));
|
|
207 |
return (TPtrC16)(*temp);
|
|
208 |
}
|
|
209 |
|
|
210 |
EXPORT_C void CDesC16Array::AppendL(const TDesC16& aPtr)
|
|
211 |
/** Appends a descriptor onto the end of any existing descriptor elements in the
|
|
212 |
array.
|
|
213 |
|
|
214 |
@param aPtr A reference to the descriptor to be appended to the array. */
|
|
215 |
{
|
|
216 |
InsertL(Count(),aPtr);
|
|
217 |
}
|
|
218 |
|
|
219 |
EXPORT_C void CDesC16Array::InsertL(TInt aPos,const TDesC16& aPtr)
|
|
220 |
/** Inserts a descriptor into the array at the specified position.
|
|
221 |
|
|
222 |
If the specified position is the same as the current number of descriptor
|
|
223 |
elements in the array, this has the effect of appending the element.
|
|
224 |
|
|
225 |
@param aPos The position within the array where the descriptor element is
|
|
226 |
to be inserted. The position is relative to zero, i.e. zero implies the first
|
|
227 |
descriptor element. This value must not be negative and must not be greater
|
|
228 |
than the number of descriptor elements currently in the array, otherwise the
|
|
229 |
function raises an E32USER-CBase 21 panic.
|
|
230 |
@param aPtr The descriptor to be inserted into the array. */
|
|
231 |
{
|
|
232 |
HBufC16* bufPtr=aPtr.AllocLC();
|
|
233 |
CArrayFixBase::InsertL(aPos,&bufPtr);
|
|
234 |
CleanupStack::Pop();
|
|
235 |
}
|
|
236 |
|
|
237 |
EXPORT_C TInt CDesC16Array::InsertIsqL(const TDesC16& aPtr,TKeyCmpText aTextComparisonType)
|
|
238 |
/** Inserts a descriptor into the array at a position which maintains the sequence
|
|
239 |
of the descriptors.
|
|
240 |
|
|
241 |
The sequence is determined by comparing descriptors using one of the TDesC
|
|
242 |
comparison functions. The enumeration aTextComparisonType governs how the
|
|
243 |
descriptors are to be compared.
|
|
244 |
|
|
245 |
The array should already be in sequence, otherwise the position of the new
|
|
246 |
descriptor element is unpredictable. Descriptor elements which are the same
|
|
247 |
are not permitted.
|
|
248 |
|
|
249 |
@param aPtr A reference to the descriptor to be inserted into the array.
|
|
250 |
@param aTextComparisonType An enumeration which determines the type of comparison
|
|
251 |
to be made between descriptors for the purpose of choosing the insertion position.
|
|
252 |
If no parameter is explicitly passed, ECmpFolded is used by default.
|
|
253 |
@return The position within the array of the inserted descriptor. */
|
|
254 |
{
|
|
255 |
HBufC16* bufPtr=aPtr.AllocLC();
|
|
256 |
TKeyDesC16Array key(aTextComparisonType);
|
|
257 |
TInt found=CArrayFixBase::InsertIsqL(&bufPtr,key);
|
|
258 |
CleanupStack::Pop();
|
|
259 |
return(found);
|
|
260 |
}
|
|
261 |
|
|
262 |
EXPORT_C TInt CDesC16Array::InsertIsqAllowDuplicatesL(const TDesC16& aPtr,TKeyCmpText aTextComparisonType)
|
|
263 |
/** Inserts a descriptor into the array at a position which maintains the sequence
|
|
264 |
of the descriptors; allows duplicates.
|
|
265 |
|
|
266 |
The sequence is determined by comparing descriptors using one of the TDesC
|
|
267 |
comparison functions. The enumeration aTextComparisonType governs how the
|
|
268 |
descriptors are to be compared.
|
|
269 |
|
|
270 |
The array should already be in sequence, otherwise the position of the new
|
|
271 |
descriptor element is unpredictable. Descriptor elements which are the same
|
|
272 |
are permitted; if the descriptor aPtr is a duplicate of an existing descriptor
|
|
273 |
within the array, then the new descriptor element is positioned after the
|
|
274 |
existing descriptor element.
|
|
275 |
|
|
276 |
@param aPtr A reference to the descriptor to be inserted into the array.
|
|
277 |
@param aTextComparisonType An enumeration which determines the type of comparison
|
|
278 |
to be made between descriptors for the purpose of choosing the insertion position.
|
|
279 |
If no parameter is explicitly passed, ECmpFolded is used by default.
|
|
280 |
@return The position within the array of the inserted descriptor. */
|
|
281 |
{
|
|
282 |
HBufC16* bufPtr=aPtr.AllocLC();
|
|
283 |
TKeyDesC16Array key(aTextComparisonType);
|
|
284 |
TInt found=CArrayFixBase::InsertIsqAllowDuplicatesL(&bufPtr,key);
|
|
285 |
CleanupStack::Pop();
|
|
286 |
return(found);
|
|
287 |
}
|
|
288 |
|
|
289 |
EXPORT_C void CDesC16Array::Sort(TKeyCmpText aTextComparisonType)
|
|
290 |
/** Sorts the descriptor elements into sequence.
|
|
291 |
|
|
292 |
The sequence is determined by comparing descriptors using one of the member
|
|
293 |
functions of the descriptor base class TDesC.
|
|
294 |
|
|
295 |
@param aTextComparisonType An enumeration which defines the type of comparison
|
|
296 |
to be made between descriptors. By default the comparison type is ECmpFolded. */
|
|
297 |
{
|
|
298 |
TKeyDesC16Array key(aTextComparisonType);
|
|
299 |
CArrayFixBase::Sort(key);
|
|
300 |
}
|
|
301 |
|
|
302 |
EXPORT_C TInt CDesC16Array::Find(const TDesC16& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const
|
|
303 |
/** Finds the position of a descriptor element within the array which matches the
|
|
304 |
specified descriptor, using a sequential search.
|
|
305 |
|
|
306 |
The array is searched sequentially for a matching descriptor element, starting
|
|
307 |
with the first descriptor element in the array. Descriptors are compared using
|
|
308 |
one of the TDesC comparison functions. The enumeration aTextComparisonType
|
|
309 |
governs how the descriptors are to be compared.
|
|
310 |
|
|
311 |
Where an array has duplicate descriptor elements, the function only supplies
|
|
312 |
the position of the first descriptor element.
|
|
313 |
|
|
314 |
@param aPtr A reference to a descriptor to be used for comparison.
|
|
315 |
@param aPos If the descriptor element is found, this reference is set to the
|
|
316 |
position of that descriptor element within the array. The position is relative
|
|
317 |
to zero, (i.e. the first descriptor element in the array is at position 0).
|
|
318 |
If the descriptor element is not found and the array is not empty, then the
|
|
319 |
value of the reference is set to the number of descriptor elements in the
|
|
320 |
array. If the descriptor element is not found and the array is empty, then
|
|
321 |
the reference is set to zero.
|
|
322 |
@param aTextComparisonType An enumeration which determines the type of comparison
|
|
323 |
to be made between descriptors. If no parameter is explicitly passed,ECmpFolded
|
|
324 |
is used by default.
|
|
325 |
@return Zero, if a matching descriptor element is found. Non-zero, if no matching
|
|
326 |
descriptor element can be found. */
|
|
327 |
{
|
|
328 |
TKeyDesC16Array key(aTextComparisonType);
|
|
329 |
const TDesC16* tmp=(&aPtr);
|
|
330 |
return(CArrayFixBase::Find(&tmp,key,aPos));
|
|
331 |
}
|
|
332 |
|
|
333 |
EXPORT_C TInt CDesC16Array::FindIsq(const TDesC16& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const
|
|
334 |
/** Finds the position of a descriptor element within the array which matches the
|
|
335 |
specified descriptor, using a binary search technique. The array must
|
|
336 |
be in sequence, otherwise the outcome is unpredictable.
|
|
337 |
|
|
338 |
Descriptors are compared using one of the TDesC comparison functions. The
|
|
339 |
enumeration aTextComparisonType governs how the descriptors are to be compared.
|
|
340 |
|
|
341 |
Where an array has duplicate descriptor elements, the function cannot guarantee
|
|
342 |
which matching descriptor element it will return; except that it will find
|
|
343 |
one of them.
|
|
344 |
|
|
345 |
@param aPtr A reference to a descriptor to be used for comparison.
|
|
346 |
@param aPos If the descriptor element is found, the reference is set to the
|
|
347 |
position of that descriptor element within the array. The position is relative
|
|
348 |
to zero, (i.e. the first descriptor element in the array is at position 0).
|
|
349 |
If the descriptor element is not found and the array is not empty, then the
|
|
350 |
reference is set to the position of the first descriptor element in the array
|
|
351 |
whose content is greater than the content of aPtr. If the descriptor element
|
|
352 |
is not found and the array is empty, then the reference is set to zero.
|
|
353 |
@param aTextComparisonType An enumeration which determines the type of comparison
|
|
354 |
to be made between descriptors. If no parameter is explicitly passed, ECmpFolded
|
|
355 |
is used by default.
|
|
356 |
@return Zero, if a matching descriptor element is found. Non-zero, if no matching
|
|
357 |
descriptor element can be found. */
|
|
358 |
{
|
|
359 |
TKeyDesC16Array key(aTextComparisonType);
|
|
360 |
const TDesC16* tmp=(&aPtr);
|
|
361 |
return(CArrayFixBase::FindIsq(&tmp,key,aPos));
|
|
362 |
}
|
|
363 |
|
|
364 |
|
|
365 |
EXPORT_C CDesC16ArraySeg::CDesC16ArraySeg(TInt aGranularity)
|
|
366 |
: CDesC16Array((TBufRep)CBufSeg::NewL,aGranularity)
|
|
367 |
/** Construct a segmented descriptor array with the specified granularity.
|
|
368 |
|
|
369 |
No memory is allocated to the array buffer by this C++ constructor.
|
|
370 |
|
|
371 |
@param aGranularity The granularity of the array. This value must be positive
|
|
372 |
otherwise the constructor raises an E32USER-CBase 18 panic. */
|
|
373 |
{
|
|
374 |
__DECLARE_NAME(_S("CDesC16ArraySeg"));
|
|
375 |
}
|
|
376 |
|
|
377 |
EXPORT_C CDesC16ArraySeg::~CDesC16ArraySeg()
|
|
378 |
/** Frees all resources owned by the object, prior to its destruction. */
|
|
379 |
{}
|
|
380 |
|
|
381 |
|
|
382 |
/* The following 3 function is defined so that the functions IdealLanguage,
|
|
383 |
SetIdealLanguage, ReleaseIdealLanguage will compile as part as an .exe
|
|
384 |
These functions use a global TAny* to store the data that would have been
|
|
385 |
stored in the TLS under normal compilation (ie If the BaUtils was compilled
|
|
386 |
as part of a DLL).
|
|
387 |
*/
|
|
388 |
|
|
389 |
TAny* ptr(NULL);
|
|
390 |
|
|
391 |
TAny* Dll::Tls()
|
|
392 |
{
|
|
393 |
return ptr;
|
|
394 |
}
|
|
395 |
|
|
396 |
TInt Dll::SetTls(TAny* aPtr)
|
|
397 |
{
|
|
398 |
ptr = aPtr;
|
|
399 |
return KErrNone;
|
|
400 |
}
|
|
401 |
|
|
402 |
void Dll::FreeTls()
|
|
403 |
{
|
|
404 |
ptr = NULL;
|
|
405 |
}
|
|
406 |
|
|
407 |
|
|
408 |
|