1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textandlocutils/nearestlangutils/tsrc/T_LangUtilsTestShareFunc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,408 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <langutil.h>
1.20 +#include "T_LangUtilsTestShareFunc.h"
1.21 +
1.22 +void DoCopyFileL(RFs& aFs, const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
1.23 + {
1.24 + CFileMan* fileMan=CFileMan::NewL(aFs);
1.25 + CleanupStack::PushL(fileMan);
1.26 + User::LeaveIfError(fileMan->Copy(aSourceFullName,aTargetFullName,aSwitch));
1.27 + CleanupStack::PopAndDestroy(); // fileMan
1.28 + }
1.29 +
1.30 +
1.31 +TInt LangUtilsTest::CopyFile(RFs& aFs, const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
1.32 +/** Copies one or more files.
1.33 +
1.34 +For more details,
1.35 +@see CFileMan::Copy()
1.36 +@since 5.1
1.37 +@param aFs File server session
1.38 +@param aSourceFullName Path indicating the file(s) to be copied. Any path
1.39 +components that are not specified here will be taken from the session path.
1.40 +@param aTargetFullName Path indicating the directory into which the file(s)
1.41 +are to be copied
1.42 +@param aSwitch=CFileMan::EOverWrite Set this to zero for no overwriting and
1.43 +no recursion; CFileMan::EOverWrite to overwrite files with the same name; or
1.44 +CFileMan::ERecurse for recursion.
1.45 +@return KErrNone if successful, otherwise another of the system-wide error
1.46 +codes.*/
1.47 + {
1.48 + TRAPD(err,DoCopyFileL(aFs,aSourceFullName,aTargetFullName,aSwitch));
1.49 + return err;
1.50 + }
1.51 +
1.52 +TBool LangUtilsTest::FileExists(const RFs& aFileSession,const TDesC& aFileName)
1.53 +/** Checks if the specified file exists.
1.54 +
1.55 +@param aFs File server session
1.56 +@param aFileName File to check
1.57 +@return ETrue if the file exists, otherwise EFalse */
1.58 + { // static
1.59 + TEntry entry;
1.60 + return(aFileSession.Entry(aFileName,entry)==KErrNone);
1.61 + }
1.62 +
1.63 +void DoDeleteFileL(RFs& aFs, const TDesC& aSourceFullName, TUint aSwitch)
1.64 + {
1.65 + CFileMan* fileMan=CFileMan::NewL(aFs);
1.66 + CleanupStack::PushL(fileMan);
1.67 + User::LeaveIfError(fileMan->Delete(aSourceFullName,aSwitch));
1.68 + CleanupStack::PopAndDestroy(); // fileMan
1.69 + }
1.70 +
1.71 +
1.72 +EXPORT_C TInt LangUtilsTest::DeleteFile(RFs& aFs, const TDesC& aSourceFullName, TUint aSwitch)
1.73 +/** Deletes one or more files.
1.74 +
1.75 +For more details,
1.76 +@see CFileMan::Delete().
1.77 +@since 5.1
1.78 +@param aFs File server session
1.79 +@param aSourceFullName Path indicating the file(s) to be deleted. May either
1.80 +be a full path, or relative to the session path. Use wildcards to specify
1.81 +more than one file.
1.82 +@param aSwitch=0 Specify CFileMan::ERecurse for recursion,
1.83 +zero for no recursion.
1.84 +@return KErrNone if successful, otherwise another of the system-wide error
1.85 +codes. */
1.86 + {
1.87 + TRAPD(err,DoDeleteFileL(aFs,aSourceFullName,aSwitch));
1.88 + return err;
1.89 + }
1.90 +
1.91 +NONSHARABLE_CLASS(TKeyDesC16Array) : public TKeyArrayFix
1.92 + {
1.93 +public:
1.94 + TKeyDesC16Array(TKeyCmpText aType);
1.95 +private: // from TKey
1.96 + TInt Compare(TInt aLeft,TInt aRight) const;
1.97 + };
1.98 +
1.99 +TKeyDesC16Array::TKeyDesC16Array(TKeyCmpText aType)
1.100 + : TKeyArrayFix(0,aType,0)
1.101 + {
1.102 + }
1.103 +
1.104 +TInt TKeyDesC16Array::Compare(TInt aLeft,TInt aRight) const
1.105 + {
1.106 + TDesC16* left=(*(TDesC16**)At(aLeft));
1.107 + TDesC16* right=(*(TDesC16**)At(aRight));
1.108 + switch (iCmpType)
1.109 + {
1.110 + case ECmpFolded:
1.111 + return(left->CompareF(*right));
1.112 + case ECmpCollated:
1.113 + return(left->CompareC(*right));
1.114 + default:
1.115 + break;
1.116 + }
1.117 + return(left->Compare(*right));
1.118 + }
1.119 +
1.120 +EXPORT_C CDesC16Array::CDesC16Array(TBufRep aRep,TInt aGranularity)
1.121 + : CArrayFixBase(aRep,sizeof(HBufC16*),aGranularity)
1.122 + {
1.123 + }
1.124 +
1.125 +EXPORT_C CDesC16Array::~CDesC16Array()
1.126 +/** Frees all resources owned by the object, prior to its destruction. In particular,
1.127 +it deletes all descriptors from the array and frees the memory allocated to
1.128 +the array buffer. */
1.129 + {
1.130 + Reset();
1.131 + }
1.132 +
1.133 +EXPORT_C void CDesC16Array::Reset()
1.134 +/** Deletes all descriptors from the array and frees the memory allocated to the
1.135 +array buffer.
1.136 +
1.137 +@see CDesC16Array::Delete() */
1.138 + {
1.139 + Delete(0,Count());
1.140 + }
1.141 +
1.142 +EXPORT_C void CDesC16Array::Delete(TInt aIndex)
1.143 + {
1.144 + Delete(aIndex,1);
1.145 + }
1.146 +
1.147 +/**
1.148 + *
1.149 + * Deletes one or more logically contiguous descriptor elements from the
1.150 + * array.
1.151 + *
1.152 + * The deletion starts at the specified position.Deleting descriptor
1.153 + * elements from the array frees the memory occupied by the associated
1.154 + * heap descriptors and removes their pointers from the array buffer but
1.155 + * does not cause the array buffer to be automatically compressed. Call
1.156 + * the Compress() function to return excess space in the array buffer to
1.157 + * the heap.
1.158 + *
1.159 + * @param " TInt aPos "
1.160 + * The starting position in the array from which
1.161 + * descriptor elements are to be deleted. The position is
1.162 + * relative to zero, i.e. zero implies the first
1.163 + * descriptor element. This value must not be negative
1.164 + * and must not be greater than the number of descriptor
1.165 + * elements currently in the array, otherwise the
1.166 + * functions raise an E32USER-CBase 21 panic.
1.167 + * @param " TInt aCount "
1.168 + * If specified, the number of contiguous descriptor
1.169 + * elements to be deleted from the array. This value must
1.170 + * not be negative otherwise the function raises an
1.171 + * E32USER-CBase 22 panic. This value must not be
1.172 + * negative otherwise the function raises an
1.173 + * E32USER-CBase 22 panic. This value must not be
1.174 + * negative otherwise the function raises an
1.175 + * E32USER-CBase 22 panic. This value plus the value of
1.176 + * the starting position must not be greater than the
1.177 + * number of descriptor elements in the array, otherwise
1.178 + * the function raises an E32USER-CBase 29 panic. If not
1.179 + * specified, one element is assumed.
1.180 + */
1.181 +EXPORT_C void CDesC16Array::Delete(TInt aIndex,TInt aCount)
1.182 + {
1.183 + TInt count=aCount;
1.184 + for (TInt ii=aIndex; count--; ii++)
1.185 + User::Free(*(HBufC16**)At(ii));
1.186 + CArrayFixBase::Delete(aIndex,aCount);
1.187 + }
1.188 +
1.189 +EXPORT_C TInt CDesC16Array::MdcaCount() const
1.190 +/** Returns the number of descriptor elements in the array. The function implements
1.191 +the function interface MDesC16Array::MdcaCount().
1.192 +
1.193 +@return The number of descriptor elements. */
1.194 + {
1.195 + return Count();
1.196 + }
1.197 +
1.198 +EXPORT_C TPtrC16 CDesC16Array::MdcaPoint(TInt anIndex) const
1.199 +/** Indexes into a descriptor array. The function implements the interface MDesC16Array::MdcaPoint().
1.200 +
1.201 + @param aIndex The position of the descriptor element within the array. The
1.202 + position is relative to zero; i.e. zero implies the first descriptor element
1.203 + in the array. This value must be non-negative and less than the number of
1.204 + descriptors currently within the array otherwise the operator panics with
1.205 + EArrayIndexOutOfRange.
1.206 + @return A non-modifiable pointer descriptor representing the descriptor element
1.207 + located at position aIndex within the array. */
1.208 + {
1.209 + HBufC16* temp=(*(HBufC16**)At(anIndex));
1.210 + return (TPtrC16)(*temp);
1.211 + }
1.212 +
1.213 +EXPORT_C void CDesC16Array::AppendL(const TDesC16& aPtr)
1.214 +/** Appends a descriptor onto the end of any existing descriptor elements in the
1.215 +array.
1.216 +
1.217 +@param aPtr A reference to the descriptor to be appended to the array. */
1.218 + {
1.219 + InsertL(Count(),aPtr);
1.220 + }
1.221 +
1.222 +EXPORT_C void CDesC16Array::InsertL(TInt aPos,const TDesC16& aPtr)
1.223 +/** Inserts a descriptor into the array at the specified position.
1.224 +
1.225 +If the specified position is the same as the current number of descriptor
1.226 +elements in the array, this has the effect of appending the element.
1.227 +
1.228 +@param aPos The position within the array where the descriptor element is
1.229 +to be inserted. The position is relative to zero, i.e. zero implies the first
1.230 +descriptor element. This value must not be negative and must not be greater
1.231 +than the number of descriptor elements currently in the array, otherwise the
1.232 +function raises an E32USER-CBase 21 panic.
1.233 +@param aPtr The descriptor to be inserted into the array. */
1.234 + {
1.235 + HBufC16* bufPtr=aPtr.AllocLC();
1.236 + CArrayFixBase::InsertL(aPos,&bufPtr);
1.237 + CleanupStack::Pop();
1.238 + }
1.239 +
1.240 +EXPORT_C TInt CDesC16Array::InsertIsqL(const TDesC16& aPtr,TKeyCmpText aTextComparisonType)
1.241 +/** Inserts a descriptor into the array at a position which maintains the sequence
1.242 +of the descriptors.
1.243 +
1.244 +The sequence is determined by comparing descriptors using one of the TDesC
1.245 +comparison functions. The enumeration aTextComparisonType governs how the
1.246 +descriptors are to be compared.
1.247 +
1.248 +The array should already be in sequence, otherwise the position of the new
1.249 +descriptor element is unpredictable. Descriptor elements which are the same
1.250 +are not permitted.
1.251 +
1.252 +@param aPtr A reference to the descriptor to be inserted into the array.
1.253 +@param aTextComparisonType An enumeration which determines the type of comparison
1.254 +to be made between descriptors for the purpose of choosing the insertion position.
1.255 +If no parameter is explicitly passed, ECmpFolded is used by default.
1.256 +@return The position within the array of the inserted descriptor. */
1.257 + {
1.258 + HBufC16* bufPtr=aPtr.AllocLC();
1.259 + TKeyDesC16Array key(aTextComparisonType);
1.260 + TInt found=CArrayFixBase::InsertIsqL(&bufPtr,key);
1.261 + CleanupStack::Pop();
1.262 + return(found);
1.263 + }
1.264 +
1.265 +EXPORT_C TInt CDesC16Array::InsertIsqAllowDuplicatesL(const TDesC16& aPtr,TKeyCmpText aTextComparisonType)
1.266 +/** Inserts a descriptor into the array at a position which maintains the sequence
1.267 +of the descriptors; allows duplicates.
1.268 +
1.269 +The sequence is determined by comparing descriptors using one of the TDesC
1.270 +comparison functions. The enumeration aTextComparisonType governs how the
1.271 +descriptors are to be compared.
1.272 +
1.273 +The array should already be in sequence, otherwise the position of the new
1.274 +descriptor element is unpredictable. Descriptor elements which are the same
1.275 +are permitted; if the descriptor aPtr is a duplicate of an existing descriptor
1.276 +within the array, then the new descriptor element is positioned after the
1.277 +existing descriptor element.
1.278 +
1.279 +@param aPtr A reference to the descriptor to be inserted into the array.
1.280 +@param aTextComparisonType An enumeration which determines the type of comparison
1.281 +to be made between descriptors for the purpose of choosing the insertion position.
1.282 +If no parameter is explicitly passed, ECmpFolded is used by default.
1.283 +@return The position within the array of the inserted descriptor. */
1.284 + {
1.285 + HBufC16* bufPtr=aPtr.AllocLC();
1.286 + TKeyDesC16Array key(aTextComparisonType);
1.287 + TInt found=CArrayFixBase::InsertIsqAllowDuplicatesL(&bufPtr,key);
1.288 + CleanupStack::Pop();
1.289 + return(found);
1.290 + }
1.291 +
1.292 +EXPORT_C void CDesC16Array::Sort(TKeyCmpText aTextComparisonType)
1.293 +/** Sorts the descriptor elements into sequence.
1.294 +
1.295 +The sequence is determined by comparing descriptors using one of the member
1.296 +functions of the descriptor base class TDesC.
1.297 +
1.298 +@param aTextComparisonType An enumeration which defines the type of comparison
1.299 +to be made between descriptors. By default the comparison type is ECmpFolded. */
1.300 + {
1.301 + TKeyDesC16Array key(aTextComparisonType);
1.302 + CArrayFixBase::Sort(key);
1.303 + }
1.304 +
1.305 +EXPORT_C TInt CDesC16Array::Find(const TDesC16& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const
1.306 +/** Finds the position of a descriptor element within the array which matches the
1.307 +specified descriptor, using a sequential search.
1.308 +
1.309 +The array is searched sequentially for a matching descriptor element, starting
1.310 +with the first descriptor element in the array. Descriptors are compared using
1.311 +one of the TDesC comparison functions. The enumeration aTextComparisonType
1.312 +governs how the descriptors are to be compared.
1.313 +
1.314 +Where an array has duplicate descriptor elements, the function only supplies
1.315 +the position of the first descriptor element.
1.316 +
1.317 +@param aPtr A reference to a descriptor to be used for comparison.
1.318 +@param aPos If the descriptor element is found, this reference is set to the
1.319 +position of that descriptor element within the array. The position is relative
1.320 +to zero, (i.e. the first descriptor element in the array is at position 0).
1.321 +If the descriptor element is not found and the array is not empty, then the
1.322 +value of the reference is set to the number of descriptor elements in the
1.323 +array. If the descriptor element is not found and the array is empty, then
1.324 +the reference is set to zero.
1.325 +@param aTextComparisonType An enumeration which determines the type of comparison
1.326 +to be made between descriptors. If no parameter is explicitly passed,ECmpFolded
1.327 +is used by default.
1.328 +@return Zero, if a matching descriptor element is found. Non-zero, if no matching
1.329 +descriptor element can be found. */
1.330 + {
1.331 + TKeyDesC16Array key(aTextComparisonType);
1.332 + const TDesC16* tmp=(&aPtr);
1.333 + return(CArrayFixBase::Find(&tmp,key,aPos));
1.334 + }
1.335 +
1.336 +EXPORT_C TInt CDesC16Array::FindIsq(const TDesC16& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const
1.337 +/** Finds the position of a descriptor element within the array which matches the
1.338 +specified descriptor, using a binary search technique. The array must
1.339 +be in sequence, otherwise the outcome is unpredictable.
1.340 +
1.341 +Descriptors are compared using one of the TDesC comparison functions. The
1.342 +enumeration aTextComparisonType governs how the descriptors are to be compared.
1.343 +
1.344 +Where an array has duplicate descriptor elements, the function cannot guarantee
1.345 +which matching descriptor element it will return; except that it will find
1.346 +one of them.
1.347 +
1.348 +@param aPtr A reference to a descriptor to be used for comparison.
1.349 +@param aPos If the descriptor element is found, the reference is set to the
1.350 +position of that descriptor element within the array. The position is relative
1.351 +to zero, (i.e. the first descriptor element in the array is at position 0).
1.352 +If the descriptor element is not found and the array is not empty, then the
1.353 +reference is set to the position of the first descriptor element in the array
1.354 +whose content is greater than the content of aPtr. If the descriptor element
1.355 +is not found and the array is empty, then the reference is set to zero.
1.356 +@param aTextComparisonType An enumeration which determines the type of comparison
1.357 +to be made between descriptors. If no parameter is explicitly passed, ECmpFolded
1.358 +is used by default.
1.359 +@return Zero, if a matching descriptor element is found. Non-zero, if no matching
1.360 +descriptor element can be found. */
1.361 + {
1.362 + TKeyDesC16Array key(aTextComparisonType);
1.363 + const TDesC16* tmp=(&aPtr);
1.364 + return(CArrayFixBase::FindIsq(&tmp,key,aPos));
1.365 + }
1.366 +
1.367 +
1.368 +EXPORT_C CDesC16ArraySeg::CDesC16ArraySeg(TInt aGranularity)
1.369 + : CDesC16Array((TBufRep)CBufSeg::NewL,aGranularity)
1.370 +/** Construct a segmented descriptor array with the specified granularity.
1.371 +
1.372 +No memory is allocated to the array buffer by this C++ constructor.
1.373 +
1.374 +@param aGranularity The granularity of the array. This value must be positive
1.375 +otherwise the constructor raises an E32USER-CBase 18 panic. */
1.376 + {
1.377 + __DECLARE_NAME(_S("CDesC16ArraySeg"));
1.378 + }
1.379 +
1.380 +EXPORT_C CDesC16ArraySeg::~CDesC16ArraySeg()
1.381 +/** Frees all resources owned by the object, prior to its destruction. */
1.382 + {}
1.383 +
1.384 +
1.385 +/* The following 3 function is defined so that the functions IdealLanguage,
1.386 +SetIdealLanguage, ReleaseIdealLanguage will compile as part as an .exe
1.387 +These functions use a global TAny* to store the data that would have been
1.388 +stored in the TLS under normal compilation (ie If the BaUtils was compilled
1.389 +as part of a DLL).
1.390 +*/
1.391 +
1.392 +TAny* ptr(NULL);
1.393 +
1.394 +TAny* Dll::Tls()
1.395 + {
1.396 + return ptr;
1.397 + }
1.398 +
1.399 +TInt Dll::SetTls(TAny* aPtr)
1.400 + {
1.401 + ptr = aPtr;
1.402 + return KErrNone;
1.403 + }
1.404 +
1.405 +void Dll::FreeTls()
1.406 + {
1.407 + ptr = NULL;
1.408 + }
1.409 +
1.410 +
1.411 +