本文整理汇总了C++中TDesC::Locate方法的典型用法代码示例。如果您正苦于以下问题:C++ TDesC::Locate方法的具体用法?C++ TDesC::Locate怎么用?C++ TDesC::Locate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDesC
的用法示例。
在下文中一共展示了TDesC::Locate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetSelection
EXPORT_C TInt CIpuTestHarness::GetSelection(const TDesC& ourPrompt, const TDesC& validChoices)
//
// Present the user with a list of options, and get their selection
{
// If we're scripting, try reading from script first
TInt readScriptErr = KErrNotFound;
if (iScriptRunning)
{
TBuf<1> oneCharBuf;
readScriptErr = ReadLineFromScript(oneCharBuf);
if (!readScriptErr)
{
return validChoices.Locate((TChar)oneCharBuf[0]);
}
}
// Either not scripting, or hit end of script - continue with user input
TKeyCode key = EKeyNull;
iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
iTest.Console()->Printf(_L("%S "), &ourPrompt);
iTest.Console()->Printf(_L("[%S] :"), &validChoices);
TInt retVal = KErrNotFound;
while (retVal == KErrNotFound)
{
key = iTest.Getch();
// Check that key is in the list of valid choices
retVal = validChoices.Locate((TChar)key);
}
iTest.Console()->Printf(_L("%c\n\n"), key);
return retVal;
}
示例2: validateName
LOCAL_C TInt validateName(const TDesC &aName)
//
// Return KErrBadName if the name is invalid.
//
{
if (aName.Locate('*')!=KErrNotFound || aName.Locate('?')!=KErrNotFound || aName.Locate(':')!=KErrNotFound)
return(KErrBadName);
return(KErrNone);
}
示例3: GetPhysicalPathL
/**
Utility method used to construct physical path for a given file name
@param aPhysicalFileName in/out paramter; file name to which physical path will be append
@param aSecuredFileName secured file name
*/
void CPplContactsFile::GetPhysicalPathL(TDes& aPhysicalFileName, const TDesC& aSecuredFileName)
{
const TUint16 KDriveDelimiter = ':';
// Check for the drive delimiter.
__ASSERT_ALWAYS(aSecuredFileName.Length() > 2 &&
aSecuredFileName[1] == KDriveDelimiter, User::Leave(KErrBadName));
// Check for malformed file name (path included explicitly).
__ASSERT_ALWAYS(aSecuredFileName.Locate('\\') == KErrNotFound, User::Leave(KErrBadName));
// Get the private path from the file session.
const TInt KMaxPrivatePathLength = 32;
TBuf<KMaxPrivatePathLength> privatePath;
LocalFsL();
iLocalFs.PrivatePath(privatePath);
aPhysicalFileName = aSecuredFileName.Left(KDriveNameWidth);
// Set current drive.
iDatabaseDrive = aPhysicalFileName;
aPhysicalFileName.Append(privatePath);
// Make sure private path exists.
TInt err = iLocalFs.MkDirAll(aPhysicalFileName);
if (err != KErrNone && err != KErrAlreadyExists)
{
User::Leave(err);
}
}
示例4: ExtractInt
static TBuf<20> ExtractInt(const TDesC& aBuf, TInt& aExtractedInt)
{
TBuf<20> buf = aBuf.Right(aBuf.Length() - aBuf.Locate(':')-1);
TBuf<5> handle;
handle.FillZ();
handle = buf.Left(buf.Locate(':'));
aExtractedInt = Str2Int(handle);
return buf;
}
示例5: GetL
TPtrC TfrLex::GetL( TLex& aLex, const TDesC& aList )
{
// Skip spaces and mark the token's start point.
aLex.SkipSpace();
TLexMark mark;
aLex.Mark(mark);
if ( aLex.Peek() == '"' )
{
// Skip the " and do find next " followed by eos, space or any char
// in the aList.
aLex.Inc();
TChar x;
while ( x = aLex.Get(), !x.Eos() )
{
if ( x == '"' )
{
// Found a " character - but is it the end of the token?
x = aLex.Peek();
if ( x.Eos() || x.IsSpace() || aList.Locate(x) < 0 )
// End of token: return token.
return aLex.MarkedToken(mark);
}
}
// Unget and L E A V E because did not find the end " of token.
aLex.UnGetToMark(mark);
User::Leave(KErrArgument);
return aLex.MarkedToken(mark); // never reached (l e a v e).
}
else
{
// Is not a "*" token: find eos or the next space or any char
// in the aList and return the token.
TChar x;
while ( x = aLex.Peek(), !x.Eos() && !x.IsSpace() && aList.Locate(x) < 0 )
aLex.Inc();
return aLex.MarkedToken(mark);
}
}
示例6: TimeSet
void CRuleManager::TimeSet(const TDesC& aDes,TTime& aTime)
{
TTime time;
time.HomeTime();
TDateTime date;
date = time.DateTime();
TInt pos = aDes.Locate(':');
if (pos != KErrNotFound)
{
date.SetHour(CCommonUtils::StrToInt(aDes.Left(pos)));
date.SetMinute(CCommonUtils::StrToInt(aDes.Mid(pos+1)));
date.SetSecond(0);
date.SetMicroSecond(0);
}
aTime = TTime(date);
}
示例7: ConstructL
void CUrl::ConstructL(const TDesC& aUrl)
//
// Non-trivial c'tor - can be used for all general urls
{
// Stripe any leading whitespace
TPtrC url = aUrl;
while( url.Locate(' ') == 0 )
{
// Remove the leading whitespace -> set pointer to second character
url.Set(url.Mid(1));
}
iUrlDes = url.AllocL();
// Check to see if there's ':' at start of aUrl
TInt colonPos = aUrl.Locate(':');
if (colonPos == 0)
User::Leave(EWapErrCorruptUrl);
TPtrC scheme(Component(EUrlScheme));
CheckSchemeValidL(scheme);
}
示例8: ret
// -----------------------------------------------------------------------------
// CSensorDataCompensatorItem::TItemType::Set
// -----------------------------------------------------------------------------
//
TInt CSensorDataCompensatorItem::TItemType::Set( const TDesC& aType )
{
FUNC_LOG;
iType = EUnknownCompensationItem; // Reset
iNumber = KUndefinedCompensationItemNum;
TInt ret( KErrNotFound );
TInt len( aType.Length() );
TInt splitEndPos( aType.Locate( KDot ) );
if ( splitEndPos >= 0 && splitEndPos < len )
{
TInt splitStartPos( KErrNotFound );
iType = GetCompensationType( aType );
if ( iType == EUICompensationItem )
{
splitStartPos = KUiText().Length();
ret = KErrNone;
}
else if ( iType == EDeviceCompensationItem )
{
splitStartPos = KDeviceText().Length();
ret = KErrNone;
}
if ( ret == KErrNone && splitStartPos >= 0 && splitStartPos < splitEndPos )
{
TPtrC num( aType.Mid( splitStartPos, splitEndPos - splitStartPos ) );
ret = ParseInt( iNumber, num );
}
}
if ( ret != KErrNone )
{
iType = EUnknownCompensationItem;
iNumber = KUndefinedCompensationItemNum;
}
ERROR( ret, "CSensorDataCompensatorItem::TItemType::Set() - Fail");
return ret;
}
示例9: DegAndMinutesToGeo
void DegAndMinutesToGeo(const TDesC& aMin, TDes& aInto, TInt aSign)
{
aInto.Zero();
if (aMin.Compare(_L("0000.0000"))==0 || aMin.Compare(_L("00000.0000"))==0 || aMin.Length()<3) {
return;
}
TInt decpos=aMin.Locate('.');
if (decpos==KErrNotFound || decpos<3) return;
TReal deg, min;
{
TLex lex(aMin.Left(decpos-2));
if (lex.Val(deg)!=KErrNone) {
return;
}
}
{
TLex lex(aMin.Mid(decpos-2));
if (lex.Val(min)!=KErrNone) {
return;
}
if (deg==TReal(0) && min==TReal(0)) return;
min/=TReal(60);
}
deg+=min;
if (deg > TReal(180)) return;
deg*=aSign;
TRealFormat fmt; fmt.iTriLen=0;
fmt.iPoint='.'; fmt.iPlaces=8;
fmt.iType=KRealFormatCalculator;
aInto.Num(deg, fmt);
}
示例10: SetAttributeL
// -----------------------------------------------------------------------------
// SetAttributeL: The implemented function will be called from CSvgContentHandler.
//
// From CSvgElementImpl
//
// There will be two attributes been set: begin and xlink:href.
// If xlink:href is not specified, the target element will be parent element
// If begin time is not specifid, the target element will be remove immdeiately.
//
// Returns: ETrue always in this case.
// -----------------------------------------------------------------------------
//
TInt CSvgDiscardElementImpl::SetAttributeL( const TDesC& aName,
const TDesC& aValue )
{
_LIT( KTmpXlinkHref, "xlink:href" );
_LIT( KTmpBegin, "begin" );
// If not xlink:href, it must be attribute "begin"
if ( aName == KTmpXlinkHref )
{
// STEP 1 - Get the reference element
// If the first char is '#' then remove it
// This is possible if coming from cXML parser and not the Decoder
iHrefValueDefined = ETrue;
TInt pos = aValue.Locate( '#' );
if ( pos == 0 )
{
if (iTargetId)
{
delete iTargetId;
iTargetId = NULL;
}
iTargetId = aValue.AllocL();
TPtr tPtr = iTargetId->Des();
tPtr.Delete(pos, 1);
}
}
else if ( aName == KTmpBegin )
{
CSvgAnimTimingParser* atParser = CSvgAnimTimingParser::NewLC( aValue, this );
TInt32 clockValue;
TReal32 lRepeatBeginValue;
atParser->Parse( iBeginSyncElementId,
iBeginReferenceEvent,
clockValue,
lRepeatBeginValue,
ETrue);
iAbsoluteBeginTime = clockValue;
if ( iBeginSyncElementId.Size() != 0 )
{
iSyncValueDefined = ETrue;
}
if ( iBeginReferenceEvent != ESvgEventNone )
{
iEventValueDefined = ETrue;
iRefBeginTime = clockValue;
iAbsoluteBeginTime = KTimeIndefinite;
if (iBeginReferenceEvent == ESvgEventKey)
{
iKeyValue = atParser->AccekeyValue();
}
}
CleanupStack::PopAndDestroy( 1 ); // atParser
}
CSvgElementImpl::SetAttributeL(aName,aValue);
return KErrNone;
}
示例11: IsAdaptiveFindMatch
/**
* Checks if @c aItemText matches @c aSearchText in the sense described in
* S60. Calls UpdateNextCharsL() if findutil is not supported.
*
* @since 5.0
* @param aItemText list box item text.
* @param aSearchText search text.
* @param aNextChars reference to the next characters for the adaptive search grid
* @param aDigraphs digraphs and trigraph text.
*
* @return @c ETrue if list box item text matches aSearchText EFalse otherwise.
*/
inline TBool IsAdaptiveFindMatch( const TDesC& aItemString,
const TDesC& aSearchText, HBufC*& aNextChars, TInt /*aInputLang*/, const TDesC& aDigraphs )
{
HBufC16* searchText = NULL;
TRAPD( error, searchText = HBufC16::NewL( KMatchingBufferLength ) );
TBool wildchar = EFalse;
if ( error == KErrNone )
{
TInt itemStringLength = aItemString.Length();
TInt searchTextLength = aSearchText.Length();
if ( searchTextLength < KMatchingBufferLength )
{
searchText->Des().Append( aSearchText );
}
else
{
searchText->Des().Append( aSearchText.Left(KMatchingBufferLength-1) );
}
// To disable the wildchar matching provided by MatchC
if ( aSearchText.Locate( KLitQuestion ) != KErrNotFound ||
aSearchText.Locate( KLitStar ) != KErrNotFound )
{
wildchar = IsAdaptiveFindMatchClassic( aItemString, aSearchText );
if ( wildchar == EFalse )
{
delete searchText;
return wildchar;
}
else
{
TInt val;
searchText->Des().Append( KLitStar );
for( TInt i = 0; i < itemStringLength; i++ )
{
if ( i == 0 || IsFindWordSeparator( aItemString[i-1] ) )
{
val = MyFindC( aItemString, aSearchText );
if( (val == i) && (i < (itemStringLength-searchTextLength)))
{
if( !(IsThaiSpecialCharacter(aItemString[i+searchTextLength])) && !(IsVietnameseSpecialCharacter( aItemString[i+searchTextLength]) ))
{
TRAP_IGNORE( UpdateNextCharsL( aNextChars, aItemString[i+searchTextLength]) );
}
}
}
} // for
delete searchText;
return wildchar;
}
}
searchText->Des().Append( KLitStar );
searchText->Des().UpperCase();
TBool isCommonChars = EFalse;
TInt all_result = KErrNotFound;
TLanguage lang = User::Language();
for( TInt i = 0; i < itemStringLength; i++ )
{
if ( i == 0 || IsFindWordSeparator( aItemString[i-1] ) )
{
TInt result = KErrNotFound;
//Some vowels of Thai can not be searched with MatchC().
if( aDigraphs.Length() != 0 || lang == ELangThai )
{
result = aItemString.Mid(i).Match( searchText->Des() );
}
else
{
result = aItemString.Mid(i).MatchC( searchText->Des() );
}
if( result != KErrNotFound )
{
all_result = result;
if( i < (itemStringLength-searchTextLength) )
{
if( !(IsThaiSpecialCharacter( aItemString[i+searchTextLength])) && !(IsVietnameseSpecialCharacter( aItemString[i+searchTextLength]) ))
{
TRAP_IGNORE( UpdateNextCharsL( aNextChars, aItemString[i+searchTextLength]) );
if ( aDigraphs.Length() != 0 )
{
TBuf<2> digraph;
//.........这里部分代码省略.........
示例12: ContainsWildCards
// ---------------------------------------------------------------------------
// ContainsWildCards
// ---------------------------------------------------------------------------
//
static TBool ContainsWildCards( const TDesC& aString )
{
return ( aString.Locate( KWild1 ) != KErrNotFound ||
aString.Locate( KWild2 ) != KErrNotFound );
}
示例13: 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);
//.........这里部分代码省略.........
示例14: Part
void CUrl::Part(TComponent aComponent, const TDesC& aUrl, TInt& aStartPos, TInt& aEndPos) const
//
// Takes a descriptor as a url and parses it for the start and end positions of a particular component.
// KCUrlInvalidCharPos is used to indicate that component is not in url.
//
// Based on RFC2396
{
aStartPos = aEndPos = KCUrlInvalidCharPos;
TPtrC url = aUrl;
// search for first of ':' | '/' | '?' | '#'
TInt stripped =0;
TInt colonPos = aUrl.Locate(':');
__ASSERT_ALWAYS(colonPos != 0,Panic(EInvalidUrl)); // if ':' is first character then it is invalid
TInt hashPos = aUrl.Locate('#');
TInt slashPos = aUrl.Locate('/');
TInt queryPos = aUrl.Locate('?');
colonPos = colonPos == KErrNotFound ? KMaxTInt : colonPos;
hashPos = hashPos == KErrNotFound ? KMaxTInt : hashPos;
slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;
queryPos = queryPos == KErrNotFound ? KMaxTInt : queryPos;
// if ':' is before others then there is a scheme so extract it
if (colonPos < hashPos && colonPos < slashPos && colonPos < queryPos)
{
if (aComponent == EUrlScheme)
{
aStartPos = stripped;
aEndPos = colonPos -1;
return;
}
if (url.Length() == colonPos + 1) // reached the end of the url
return;
url.Set(url.Mid(colonPos+1));
stripped += colonPos+1;
hashPos -= colonPos+1;
slashPos -= colonPos+1;
queryPos -= colonPos+1;
}
// if first 2 characters are '//' then a host exists,
if (url.Find(KUrlLoc) == 0)
{
TInt urlLocLength = KUrlLoc().Length();
if (url.Length() == urlLocLength) // reached the end of the url
return;
// extract '//' and rescan for '/'
url.Set(url.Mid(urlLocLength));
stripped += urlLocLength;
hashPos -= urlLocLength;
queryPos -= urlLocLength;
slashPos = url.Locate('/');
slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;
// host is ended by first of '#' | '?' | '/' | end of url
TInt hostEndCharPos = slashPos;
hostEndCharPos = hashPos < hostEndCharPos ? hashPos : hostEndCharPos;
hostEndCharPos = queryPos < hostEndCharPos ? queryPos : hostEndCharPos;
hostEndCharPos = url.Length() < hostEndCharPos ? url.Length() : hostEndCharPos;
if (aComponent == EUrlAuthority)
{
aStartPos = stripped;
aEndPos = hostEndCharPos+stripped-1;
return;
}
if (aComponent == EUrlLocation ||
aComponent == EUrlUsername ||
aComponent == EUrlPassword)
{
aStartPos = stripped;
aEndPos = hostEndCharPos+stripped-1;
// We need part of the authority. Extract it
PartOfAuthority(aComponent, aUrl, aStartPos, aEndPos);
return;
}
// Have we reached the end of the url
if (url.Length() == hostEndCharPos)
return;
// extract host
url.Set(url.Mid(hostEndCharPos));
stripped += hostEndCharPos;
slashPos -= hostEndCharPos;
hashPos -= hostEndCharPos;
queryPos -= hostEndCharPos;
}
// If first character is '/' | this is the start of a relative url | there is no authority then path exists
// as long as it isn't just a query or fragment
if ((slashPos == 0 || stripped == 0 || stripped == colonPos +1 ) && hashPos != 0 && queryPos !=0)
{
TInt pathEndCharPos = queryPos;
pathEndCharPos = hashPos < pathEndCharPos ? hashPos : pathEndCharPos;
pathEndCharPos = url.Length() < pathEndCharPos ? url.Length() : pathEndCharPos;
if (aComponent == EUrlPath)
{
aStartPos = stripped;
//.........这里部分代码省略.........