本文整理汇总了C++中TDes::Mid方法的典型用法代码示例。如果您正苦于以下问题:C++ TDes::Mid方法的具体用法?C++ TDes::Mid怎么用?C++ TDes::Mid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDes
的用法示例。
在下文中一共展示了TDes::Mid方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Construct
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;
}
示例2: TestAddressStringTokenizers
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);
}
}
示例3: UpdateToActualMonthAndDay
// 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);
}
示例4: GetFileNameByPath
void GetFileNameByPath(const TDesC& aFilePath, TDes& aFileName)
{
TInt filePathLength = aFileName.LocateReverse('\\') + 1;
aFileName = aFileName.Mid(filePathLength);
}
示例5: Formater
/**
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);
//.........这里部分代码省略.........
示例6: CorrectFilePathL
/*
-------------------------------------------------------------------------------
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
//.........这里部分代码省略.........