Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include "T_LangUtilsTestShareFunc.h"
19 void DoCopyFileL(RFs& aFs, const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
21 CFileMan* fileMan=CFileMan::NewL(aFs);
22 CleanupStack::PushL(fileMan);
23 User::LeaveIfError(fileMan->Copy(aSourceFullName,aTargetFullName,aSwitch));
24 CleanupStack::PopAndDestroy(); // fileMan
28 TInt LangUtilsTest::CopyFile(RFs& aFs, const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
29 /** Copies one or more files.
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)
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
45 TRAPD(err,DoCopyFileL(aFs,aSourceFullName,aTargetFullName,aSwitch));
49 TBool LangUtilsTest::FileExists(const RFs& aFileSession,const TDesC& aFileName)
50 /** Checks if the specified file exists.
52 @param aFs File server session
53 @param aFileName File to check
54 @return ETrue if the file exists, otherwise EFalse */
57 return(aFileSession.Entry(aFileName,entry)==KErrNone);
60 void DoDeleteFileL(RFs& aFs, const TDesC& aSourceFullName, TUint aSwitch)
62 CFileMan* fileMan=CFileMan::NewL(aFs);
63 CleanupStack::PushL(fileMan);
64 User::LeaveIfError(fileMan->Delete(aSourceFullName,aSwitch));
65 CleanupStack::PopAndDestroy(); // fileMan
69 EXPORT_C TInt LangUtilsTest::DeleteFile(RFs& aFs, const TDesC& aSourceFullName, TUint aSwitch)
70 /** Deletes one or more files.
73 @see CFileMan::Delete().
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
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
84 TRAPD(err,DoDeleteFileL(aFs,aSourceFullName,aSwitch));
88 NONSHARABLE_CLASS(TKeyDesC16Array) : public TKeyArrayFix
91 TKeyDesC16Array(TKeyCmpText aType);
93 TInt Compare(TInt aLeft,TInt aRight) const;
96 TKeyDesC16Array::TKeyDesC16Array(TKeyCmpText aType)
97 : TKeyArrayFix(0,aType,0)
101 TInt TKeyDesC16Array::Compare(TInt aLeft,TInt aRight) const
103 TDesC16* left=(*(TDesC16**)At(aLeft));
104 TDesC16* right=(*(TDesC16**)At(aRight));
108 return(left->CompareF(*right));
110 return(left->CompareC(*right));
114 return(left->Compare(*right));
117 EXPORT_C CDesC16Array::CDesC16Array(TBufRep aRep,TInt aGranularity)
118 : CArrayFixBase(aRep,sizeof(HBufC16*),aGranularity)
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
130 EXPORT_C void CDesC16Array::Reset()
131 /** Deletes all descriptors from the array and frees the memory allocated to the
134 @see CDesC16Array::Delete() */
139 EXPORT_C void CDesC16Array::Delete(TInt aIndex)
146 * Deletes one or more logically contiguous descriptor elements from the
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
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.
178 EXPORT_C void CDesC16Array::Delete(TInt aIndex,TInt aCount)
181 for (TInt ii=aIndex; count--; ii++)
182 User::Free(*(HBufC16**)At(ii));
183 CArrayFixBase::Delete(aIndex,aCount);
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().
190 @return The number of descriptor elements. */
195 EXPORT_C TPtrC16 CDesC16Array::MdcaPoint(TInt anIndex) const
196 /** Indexes into a descriptor array. The function implements the interface MDesC16Array::MdcaPoint().
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. */
206 HBufC16* temp=(*(HBufC16**)At(anIndex));
207 return (TPtrC16)(*temp);
210 EXPORT_C void CDesC16Array::AppendL(const TDesC16& aPtr)
211 /** Appends a descriptor onto the end of any existing descriptor elements in the
214 @param aPtr A reference to the descriptor to be appended to the array. */
216 InsertL(Count(),aPtr);
219 EXPORT_C void CDesC16Array::InsertL(TInt aPos,const TDesC16& aPtr)
220 /** Inserts a descriptor into the array at the specified position.
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.
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. */
232 HBufC16* bufPtr=aPtr.AllocLC();
233 CArrayFixBase::InsertL(aPos,&bufPtr);
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
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.
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
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. */
255 HBufC16* bufPtr=aPtr.AllocLC();
256 TKeyDesC16Array key(aTextComparisonType);
257 TInt found=CArrayFixBase::InsertIsqL(&bufPtr,key);
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.
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.
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.
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. */
282 HBufC16* bufPtr=aPtr.AllocLC();
283 TKeyDesC16Array key(aTextComparisonType);
284 TInt found=CArrayFixBase::InsertIsqAllowDuplicatesL(&bufPtr,key);
289 EXPORT_C void CDesC16Array::Sort(TKeyCmpText aTextComparisonType)
290 /** Sorts the descriptor elements into sequence.
292 The sequence is determined by comparing descriptors using one of the member
293 functions of the descriptor base class TDesC.
295 @param aTextComparisonType An enumeration which defines the type of comparison
296 to be made between descriptors. By default the comparison type is ECmpFolded. */
298 TKeyDesC16Array key(aTextComparisonType);
299 CArrayFixBase::Sort(key);
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.
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.
311 Where an array has duplicate descriptor elements, the function only supplies
312 the position of the first descriptor element.
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
325 @return Zero, if a matching descriptor element is found. Non-zero, if no matching
326 descriptor element can be found. */
328 TKeyDesC16Array key(aTextComparisonType);
329 const TDesC16* tmp=(&aPtr);
330 return(CArrayFixBase::Find(&tmp,key,aPos));
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.
338 Descriptors are compared using one of the TDesC comparison functions. The
339 enumeration aTextComparisonType governs how the descriptors are to be compared.
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
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
356 @return Zero, if a matching descriptor element is found. Non-zero, if no matching
357 descriptor element can be found. */
359 TKeyDesC16Array key(aTextComparisonType);
360 const TDesC16* tmp=(&aPtr);
361 return(CArrayFixBase::FindIsq(&tmp,key,aPos));
365 EXPORT_C CDesC16ArraySeg::CDesC16ArraySeg(TInt aGranularity)
366 : CDesC16Array((TBufRep)CBufSeg::NewL,aGranularity)
367 /** Construct a segmented descriptor array with the specified granularity.
369 No memory is allocated to the array buffer by this C++ constructor.
371 @param aGranularity The granularity of the array. This value must be positive
372 otherwise the constructor raises an E32USER-CBase 18 panic. */
374 __DECLARE_NAME(_S("CDesC16ArraySeg"));
377 EXPORT_C CDesC16ArraySeg::~CDesC16ArraySeg()
378 /** Frees all resources owned by the object, prior to its destruction. */
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
396 TInt Dll::SetTls(TAny* aPtr)