Ejemplo n.º 1
0
void CIntTestParameter::Construct(TDes& aValue)
	{
	TLex lexValue(aValue);

	if(aValue.Left(2) == _L("0x"))
		{
		// its a hex number 
		TUint hexValue;
		TLex hexLex(aValue.Mid(2));

		if(hexLex.Val(hexValue, EHex)!=KErrNone)
			return;
		// checks if hexLex is at end of string, if not there was garbage in the string
		// so throw it out
		else if(!hexLex.Eos())
			return;

		iValue = STATIC_CAST(TInt,hexValue);
		}
	else if(lexValue.Val(iValue)!=KErrNone)
		return;
		// checks if lexValue is at end of string, if not there was garbage in the string
		// so throw it out
	else if(!lexValue.Eos())
		return;

	iValid = ETrue;
	}
Ejemplo n.º 2
0
void CIntRangeTestParameter::Construct(TDes& aValue)
	{
	if(aValue.Find(_L("..")) != KErrNotFound)
		{
		TInt pos = aValue.Find(_L(".."));
		TLex startLex(aValue.Left(pos));
		TLex endLex(aValue.Mid(pos+2));

		if(startLex.Val(iStart)!=KErrNone)
			return;
			// checks if startLex is at end of string, if not there was garbage in the string so throw it out
		else if(!startLex.Eos())
			return;

		if(endLex.Val(iFinish)!=KErrNone)
			return;
			// checks if startLex is at end of string, if not there was garbage in the string so throw it out
		else if(!endLex.Eos())
			return;
		// checks if range is doable
		if(iStart > iFinish)
			return;
		}
	else
		return;
	iValid = ETrue;
	}
void CT_AddressStringTokenizerStep::TestAddressStringTokenizers(CTulAddressStringTokenizer* aAddressStringTokenizer, TFileText& aReader, TDes& aText)
	{
    TBuf<KReadBufSize> fileBuffer;

    // Get count of found items.
    TInt count(aAddressStringTokenizer->ItemCount());
	TEST(count > 0);
	TPtrC result;

    // SFoundItem instance
    CTulAddressStringTokenizer::SFoundItem item;

    TBool found = aAddressStringTokenizer->Item(item);
    TEST(found);
    for(TInt i = 0; i < count; i++)
		{
        result.Set(aText.Mid(item.iStartPos, item.iLength));
		aReader.Read(fileBuffer);

		//Comparing parsed result to what read buffer reads from the file.
		TEST(!fileBuffer.Compare(result) );
		if (fileBuffer.Compare(result))
			{
			INFO_PRINTF2(_L("Buffer : %S"), &fileBuffer);
			INFO_PRINTF2(_L("Result : %S"), &result);
			}
        aAddressStringTokenizer->NextItem(item);
        }
	}
Ejemplo n.º 4
0
// This function is used to update month and day in aBufLocalTime
// to actual month and day to be passed to TTime() constructor.
// Remember using TTime::FormatL() in thelpers.cpp 
// has added extra month and a day to aBufLocalTime.
// aBufLocalTime is in format YYMMDD:HHMMSS.MMMMMM
// see TTime::Set() for aBufLocalTime expected format details.
TInt UpdateToActualMonthAndDay(TDes& aBufUTCTime)
	{	
	TInt mVal 	= 0;
	TInt dVal 	= 0;
	
	TBuf <4> tempBuf;
	_LIT(KFormat, "%02d");
	
	//Get the position of colon separator	
	TInt colon 	= aBufUTCTime.Locate(':');
		
	// Get Month & Day if Present	
	switch(colon)
		{
		case 0: break;
		case 8:
			{
			TLex month 	= aBufUTCTime.Mid(4,2);
			TLex day 	= aBufUTCTime.Mid(6,2);
			month.Val(mVal);
			day.Val(dVal);			
			}
			break;
		default:
			{
			// If the colon is at the wrong position
			return (KErrArgument);
			}
				
		}
		
		// Deduct extra month and a day and update aBufLocalTime
		if(mVal > 0 && dVal > 0)
			{
			mVal-=1;
			dVal-=1;
				
			tempBuf.Format(KFormat, mVal);
			aBufUTCTime.Replace(4,2, tempBuf);
				
			tempBuf.Format(KFormat, dVal);
			aBufUTCTime.Replace(6,2, tempBuf);				
			}
			
		return(KErrNone);		
	}
Ejemplo n.º 5
0
void GetFileNameByPath(const TDesC& aFilePath, TDes& aFileName)
{
	TInt filePathLength = aFileName.LocateReverse('\\') + 1;
	aFileName = aFileName.Mid(filePathLength);
}
/**
Finds the keystring from the source string and replaces it with the
replacement string. The formated string is stored in the destination
descriptor.
*/
TInt CResourceLoader::Formater(TDes& aDest, const TDesC& aSource, const TDesC& aKey, const TDesC& aSubs, TBidiText::TDirectionality aDirectionality)    
    {
    // substitute string must not contain KSubStringSeparator, 
    // or results will be unpredictable 
    __ASSERT_DEBUG(aSubs.Locate(KSubStringSeparator) == KErrNotFound, 
        User::Panic(KPanicCategory, EInvalidSubstitute));

    TInt keylength(aKey.Length());

    //aDest must be empty.
    aDest.Zero();

    // offset indicates end of last handled key in source
    TInt offset(0);

    // offset in destination string
    TInt desOffset(0);

    // Substring directionalities are adjusted after all changes are done.
    TBool checkSubstringDirectionalities(EFalse);

    // count is the position in the source from which the substring starts
    TInt count(0);

    // Replaced parameters count
    TInt replaceCount(0);

    while (count != KErrNotFound)
        {
        // desCount is the position of the substring starts in destination.
        TInt desCount(0);

        TPtrC remainder = aSource.Right(aSource.Length() - offset);
        count = remainder.Find(aKey);

        TInt maxSubLength = -1;
        if (count != KErrNotFound)
            {
            replaceCount++;
            desOffset += count;
            offset += count;
            count = offset;
            desCount = desOffset;

            // copy source to destination if first time
            if (aDest.Length() == 0)
                aDest.Append(aSource);

            // delete found key from destination
            aDest.Delete(desCount, keylength);

            offset += keylength; // increase offset by key length

            if (count + keylength < (aSource.Length()-1)) // aKey is not at the end of string
                {
                if (aSource[count+keylength] == '[') // Key includes max datalength
                    {
                    maxSubLength = 10*(aSource[count+keylength+1]-'0') 
                                   + (aSource[count+keylength+2]-'0');
                    aDest.Delete(desCount,4); // Length information stored->delete from descriptor
                    offset += 4; // increase offset by max sub length indicator
                    }
                }
         
            aDest.Insert(desCount, aSubs);
        
            desOffset = desCount + aSubs.Length();

            if (maxSubLength > 0 && aSubs.Length() > maxSubLength)
                {
                aDest.Delete(desCount+maxSubLength-1, aSubs.Length()+1-maxSubLength);     
                TText ellipsis(KEllipsis);
                aDest.Insert(desCount+maxSubLength-1, TPtrC(&ellipsis,1));
                desOffset = desCount + maxSubLength;
                }

            TBidiText::TDirectionality subsDir =
                TBidiText::TextDirectionality(aDest.Mid(desCount, desOffset - desCount));

            // If inserted string has different directionality,
            // insert directionality markers so that bidi algorithm works in a desired way.
            if (aDirectionality != subsDir)
                {
                checkSubstringDirectionalities = ETrue;

                TInt freeSpace = aDest.MaxLength() - aDest.Length();

                // Protect the directionality of the inserted string.
                if (freeSpace >= KExtraSpaceForSubStringDirMarkers)
                    {
                    TBuf<1> subsMarker;
                    subsMarker.Append(subsDir == TBidiText::ELeftToRight ?
                        KLRMarker : KRLMarker);

                    aDest.Insert(desOffset, subsMarker);
                    aDest.Insert(desCount, subsMarker);
                    desOffset += KExtraSpaceForSubStringDirMarkers;
                    }
                }
            }
        }

    // Adjust substring directionality markers if necessary
    // and if there is enough room in destination string
    if (checkSubstringDirectionalities)
        {
        TText mainMarker = (aDirectionality == TBidiText::ELeftToRight ? 
            KLRMarker : KRLMarker);

        TInt freeSpace = aDest.MaxLength() - aDest.Length();

        // If not already done, protect the directionality of the original string
        // and all of the KSubStringSeparator separated substrings.
        if (freeSpace > 0 
            && aDest.Length()
            && aDest[0] != mainMarker 
            && aDest[0] != KSubStringSeparator
            && aDest[0] != KDirNotFound)  
            {
            aDest.Insert(0, TPtrC(&mainMarker, 1));
            freeSpace--;
            }

        // Find and protect KSubStringSeparator separated substrings.
        // Go through string backwards so that any changes will not affect indexes 
        // that are not yet checked.
        TInt j(aDest.Length()-1);
        while (freeSpace > 0 && j >= 0) 
            {
            if (aDest[j] == KSubStringSeparator && j < (aDest.Length() - 1) 
                && aDest[j+1] != mainMarker && aDest[j+1] != KDirNotFound)
                {
                aDest.Insert(j+1, TPtrC(&mainMarker, 1));
                freeSpace--;
                }
            j--;
            }
        }

    return replaceCount;
    }
Ejemplo n.º 7
0
/*
-------------------------------------------------------------------------------

    Class: TStifUtil

    Method: CorrectFilePath

    Description: Checks if file path contains drive letter. If not file is serched
                 on all drives and first hit is added to file name.

    Parameters: TDes& aFilePath: in/out: file path to correct

    Return Values: None

    Errors/Exceptions: Leaves if some of called leaving methods leaves

-------------------------------------------------------------------------------
*/
EXPORT_C void TStifUtil::CorrectFilePathL( TDes& aFilePath )
	{
	_LIT( KDriveSelector, ":\\" );
	_LIT( KDriveSelectorFormat_1, "%c:" );                                                                  
	_LIT( KDriveSelectorFormat_2, "%c:\\" );                                                                
	TChar KDriveZ = EDriveZ;//'Z';                                                                          
	                                                                                                              
	_LIT( KBackslash, "\\" );                                                                              
	                                                                                                                
	TInt length = aFilePath.Length();                                                                      
	                                                                                                                
	if (length == 0 )                                                                                     
	   {                                                                                                  
	   return;                                                                                            
	   }                                                                                                  
	if (length > 2 )                                                                                      
	   {                                                                                                  
	   // Check if file path contains drive selector                                                      
	   if ( aFilePath.Mid( 1, 2 ) == KDriveSelector )                                                     
	       {                                                                                               
	       // File path contains selector letter so we have nothing to do here                             
	       return;                                                                                         
	       }                                                                                               
	   }                                                                                                  
	                                                                                                                
	// Check if file path contains backslash at the begining and                                          
	// select proper drive selector format according to this information                                  
	TInt driveSelectorFormat = 2;                                                                         
	if ( aFilePath.Mid( 0, 1 ) == KBackslash )                                                            
	   {                                                                                               
	   driveSelectorFormat = 1;                                                                        
	   }                                                                                               
	                                                                                                                
	RFs rfs;                                                                                              
	if ( rfs.Connect() != KErrNone )                                                                      
	   {                                                                                                  
	   return;                                                                                            
	   }                                                                                                  
	                                                                                                                
	// Get available drives list, revers it order and move z drive at                                     
	// the end of the list.  
	TDriveList drivesList; 
	rfs.DriveList(drivesList); 

	// Set drive variable to last drive (except for Z, which will be checked at the end)
	char drive = 'Y' ;

	// Loop through all the drives in following order: YX..CBAZ
	while(drive >= 'A' && drive <= 'Z')
	     {
	     // Do further action only if drive exists
	     TInt driveint;
	     rfs.CharToDrive(drive, driveint);
	     if(drivesList[driveint])
	          {
	          //further checking (drive selector and file existence)
	          
	          // Prepare drive selector                                                                         
	          TBuf<3> driveSelector;                                                                            
	          if ( driveSelectorFormat == 1 )                                                                   
	              {                                                                                           
	              driveSelector.Format( KDriveSelectorFormat_1, drive );                                    
	              }                                                                                           
	          else if ( driveSelectorFormat == 2 )                                                              
	              {                                                                                           
	              driveSelector.Format( KDriveSelectorFormat_2, drive );                                    
	              }                                                                                           
	                                                                                                                
	          aFilePath.Insert( 0, driveSelector );                                                             
	                                                                                                                
	          TEntry entry;                                                                                     
	          if ( rfs.Entry(aFilePath, entry) == KErrNone )                                                    
	              {                                                                                         
	              rfs.Close();                                                                                
	              return;                                                                                     
	              }                                                                                           
	                                                                                                                
	          // File does not exists on selected drive. Restoring orginal file path                            
	          aFilePath.Delete( 0, driveSelector.Length() );    	         
	          }//if(drivesList[driveint])       
	            
	   // Select next drive
	   if(drive == 'Z')
	       break; // the last driver
	   else if(drive ==  'A' )
	       drive = 'Z'; //after checking A check Z
	   else
	       drive =  (TChar)(TInt(drive)-1) ; //after checking Y check X and so on in reverse alphabetical order
	   } //while 
	rfs.Close(); 
	}