TBool CRefTestAgentManager::RecognizeFileL(const TDesC& aFileName, const TDesC8& aBuffer, TDes8& aFileMimeType, TDes8& aContentMimeType) const { TBool result = EFalse; // Check filename extension TPtrC extension(aFileName.Right(KRtaExtensionContent().Length())); if(extension.CompareF(KRtaExtensionContent) == 0) { // It's a content file ready for applications to read aFileMimeType.Copy(KRtaMimeContent()); CRefTestAgentArchive::GetDefaultMimeTypeFromHeaderL(aBuffer, aContentMimeType); result = ETrue; } else { extension.Set(aFileName.Right(KRtaExtensionContentRights().Length())); if(extension.CompareF(KRtaExtensionContentRights) == 0) { // It's a content and rights file ready for the supplier API aFileMimeType.Copy(KRtaMimeContentRights()); result = ETrue; } else { extension.Set(aFileName.Right(KRtaExtensionRights().Length())); if(extension.CompareF(KRtaExtensionRights) == 0) { // It's a content and rights file ready for the supplier API aFileMimeType.Copy(KXmlRORights()); result = ETrue; } } } return result; }
void CApaDRMRecognizer::DoRecognizeL( const TDesC& aName, const TDesC8& aBuffer ) { if ( aBuffer.Size() < 3) { return; } #ifdef RECOGNIZE_KEY_CHAIN // Recognize device key chain if ( aName.Length() > 3 && aName.Right(4).CompareF(_L(".dkc")) == 0) { iConfidence = ECertain; iDataType = TDataType( _L8("application/x-device-key-chain") ); return; } #endif #ifdef DRM_OMA2_ENABLED // Recognize ROAP Trigger if ( RecognizeRoapTrigger( aBuffer ) ) { return; } // Recognize DCFv2 if ( RecognizeODF( aBuffer ) ) { return; } #endif // Recognize DCFv1 TUint8 version = aBuffer[0]; TUint8 contentTypeLen = aBuffer[1]; TUint8 contentURILen = aBuffer[2]; if ( contentTypeLen < KMinContentTypeLen || contentURILen == 0 ) { return; } if ( version != KDCFVersionSupported ) { return; } // Too little data received if ( aBuffer.Size() < ( contentTypeLen + KDCFHeaderLength ) ) { return; } TPtrC8 mimeType = aBuffer.Mid( KDCFHeaderLength, contentTypeLen ); if ( mimeType.Locate( '/' ) != KErrNotFound ) { iConfidence = ECertain; iDataType=TDataType( mimeType ); } return; }
/** Counts the number of substrings (separated by KSubStringSeparators) in the text. Needed for correct memory allocations. */ TInt CResourceLoader::GetSubStringCount(const TDesC& aText) { TInt subCount = 0; TInt i = 0; while (i < aText.Length()) { TPtrC remainder = aText.Right(aText.Length() - i); TInt nextKey = remainder.Locate(KSubStringSeparator); i += nextKey; // Always increase subcount, as a string without any separators counts as one substring. // However, if string length is zero, then there are no substrings. subCount++; if (nextKey != KErrNotFound && i < aText.Length() - 1) { i++; // skip separator } else break; } return subCount; }
// ------------------------------------------------------------------------------------------------ // CNSmlDsProvisioningAdapter::CombineURILC() // Combines address and port to URI // ------------------------------------------------------------------------------------------------ TInt CNSmlDsProvisioningAdapter::CombineURILC( const TDesC& aAddr, const TDesC& aPort, HBufC*& aRealURI ) { TInt offset = 0; TInt i = 0; if( aAddr.Find( KNSmlDsProvisioningHTTP ) == 0 ) { offset = KNSmlDsProvisioningHTTP().Length(); } else if( aAddr.Find( KNSmlDsProvisioningHTTPS ) == 0 ) { offset = KNSmlDsProvisioningHTTPS().Length(); } // after skipping double slashes seek next single slash for( i = offset; i < aAddr.Length(); i++ ) { if( aAddr[i] == KNSmlDMUriSeparator ) { break; } } aRealURI = HBufC::NewLC( aAddr.Length() + aPort.Length() + 1 ); TPtr uriPtr = aRealURI->Des(); uriPtr.Copy( aAddr.Ptr(), i ); uriPtr.Append( KNSmlDMColon ); uriPtr.Append( aPort ); uriPtr.Append( aAddr.Right( aAddr.Length() - i ) ); return KErrNone; }
TInt CSwisExpressionEnvironment::ParsePackageUid(const TDesC& aUidString, TUid& aUid) { // Check that the UID string matches the format _LIT(KVersionUidFormat,"0x????????"); if(aUidString.MatchF(KVersionUidFormat) != 0) { return KErrNotFound; } /** * Convert the string into a TUint32 representation and check that * the string is a valid hexadecimal value */ TLex lexUid(aUidString.Right(8)); TUint32 uidValue = 0; if(lexUid.Val(uidValue,EHex) == KErrNone && lexUid.Eos()) { aUid.iUid = uidValue; return KErrNone; } // Return an error if the UID value is not parsed correctly return KErrNotFound; }
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; }
EXPORT_C TInt AknPhoneNumberTextUtils::CharsThatFitOnRight( const TDesC& aText, TInt aLineWidth, const CFont& aFont ) { // Current candidate text for fitting text TPtrC currentText(aText); // These two variables are converged by this algorithm until they differ by one // Set max chars to be total length + 1, for the sake of the algorithm TInt minCharsFromRightThatDoNotFit( aText.Length() + 1 ); TInt maxCharsFromRightThatFit(0); // must start at 0 // some incidentally used lengths TInt currentLength(0); // arbitrary init value TInt charsThatFitOnLeft(0); // arbitrary init value TInt newLength(0); // arbitrary init value while ( (minCharsFromRightThatDoNotFit - maxCharsFromRightThatFit) != 1 ) { // At the top of the loop, all state is held by currentText itself, and the two // maxCharsXXX variables. currentLength = currentText.Length(); charsThatFitOnLeft = aFont.TextCount( currentText, aLineWidth); if ( charsThatFitOnLeft == currentLength ) // Does this text fit ? { maxCharsFromRightThatFit = Max( maxCharsFromRightThatFit, charsThatFitOnLeft ); // If this text cannot be made any bigger, and still fit, then bail out if ( (maxCharsFromRightThatFit + 1) >= minCharsFromRightThatDoNotFit ) { // We can exit the loop now. Just fall out and the while test will handle it. break; } else // if this string did fit, and it might have been too small, try making it bigger { // we know this is still be < minCharsFromRightThatDoNotFit newLength = maxCharsFromRightThatFit + 1; } } else // currentText does not fit. Repeat loop { // we know that this many characters did not fit on the line minCharsFromRightThatDoNotFit = Min( minCharsFromRightThatDoNotFit, currentLength ); // Try using the number that fit on the left as the number we will fit on the right. newLength = charsThatFitOnLeft; } currentText.Set(aText.Right(newLength)); } return maxCharsFromRightThatFit; }
// ============================= LOCAL FUNCTIONS =============================== // ----------------------------------------------------------------------------- // ThumbnailPath // ----------------------------------------------------------------------------- // static TBool ThumbnailPath( const TDesC& aFullPath ) { FUNC_LOG TInt len( KImagesThumbnailPath().Length() ); if ( aFullPath.Length() >= len && !aFullPath.Right( len ).CompareF( KImagesThumbnailPath ) ) { return ETrue; } return EFalse; }
TInt CRtaServer::CheckPermittedFileName(const TDesC& aFileName) { _LIT(KContentExtension,".content"); TInt err = KErrNone; if(aFileName.Length() >= KRightsDatabaseFileName().Length()) { TPtrC rightsDb = aFileName.Right(KRightsDatabaseFileName().Length()); if(rightsDb.CompareF(KRightsDatabaseFileName()) == 0) { err = KErrPermissionDenied; } } if(err == KErrNone && aFileName.Length() >= KContentExtension().Length()) { TPtrC ext = aFileName.Right(KContentExtension().Length()); if(ext.CompareF(KContentExtension()) != 0) { err = KErrNotSupported; } } return err; }
// --------------------------------------------------------- // RecognizerEx::DoRecognizeL() // Recognizes the file by name and/or head buffer // --------------------------------------------------------- // void CApaRecognizerEx::DoRecognizeL(const TDesC& aName, const TDesC8& /*aBuffer*/) { // To keep code simple, we only check file name extension if (aName.Length()>KRecRtFileExtensionsMightBeValid) { if (aName.Right(KRecRtFileExtensionsMightBeValid).CompareF(KExtension1)==0) { iConfidence=ECertain; // is certainly something totally new iDataType=TDataType(KDataType); return; } } }
TBool CRefTestAgentManager::IsRecognizedL(const TDesC& aUri, TContentShareMode /*aShareMode*/) const { TBool result = EFalse; // Check that the file has content only, otherwise it should // be put through the supplier API before it can be used TPtrC extension(aUri.Right(KRtaExtensionContent().Length())); if(extension.CompareF(KRtaExtensionContent) == 0) { result = ETrue; } return result; }
/** Returns the hash code(s) to use when matching the supplied phone number. If the number supplied has more actual phone digits (i.e. not including spaces) than KLowerSevenDigits, a second hash is generated to hold the remaining most significant phone digits. Extracts DTMF digits from the phone number if a parser is available, otherwise just removes the non-digit characters. @param aText Descriptor containing contacts phone number field. @param aLowerMatchlength Number of least significant phone digits to use. @param aUpperMatchLength Number of most significant phone digits to use. @return The hash code(s) to use when matching the supplied phone number. */ CPplCommAddrTable::TMatch CPplCommAddrTable::CreatePhoneMatchNumberL(const TDesC& aText, TInt aLowerMatchLength, TInt aUpperMatchLength) { __ASSERT_DEBUG( ((aLowerMatchLength == KLowerSevenDigits) && (aUpperMatchLength > 0) ) // upper 8 digits || ((aLowerMatchLength <= KLowerSevenDigits) && (aUpperMatchLength == 0) ), // lower 7 digits User::Leave(KErrNotSupported) ); const TInt KBufLength = KCntMaxTextFieldLength+1; TBuf<KBufLength> buf; CContactPhoneNumberParser* parser = iProperties.ContactPhoneParserL().Parser(); if (parser) { parser->ExtractRawNumber(aText.Left(KCntMaxTextFieldLength),buf); } else { if(aText.Length() <= KBufLength) { buf = aText; } else { buf = aText.Right(KBufLength); } TMatch::StripOutNonDigitChars(buf); } TMatch phoneNumber; if (buf.Length() == 0) { return phoneNumber; } // Generate a hash for the upper digits only if the phone number string is // large enough and more than 7 digits are to be matched. TInt phoneNumberlength = buf.Length(); if ( (phoneNumberlength > KLowerSevenDigits) && (aUpperMatchLength > 0) ) { TPtrC upperPart = buf.Left(phoneNumberlength - KLowerSevenDigits); phoneNumber.iUpperDigits = TMatch::CreateHashL(upperPart, aUpperMatchLength, phoneNumber.iNumUpperDigits); } // Generate a hash of the lower digits. phoneNumber.iLowerSevenDigits = TMatch::CreateHashL(buf, aLowerMatchLength, phoneNumber.iNumLowerDigits); return phoneNumber; }
void CTNonNativeRec::DoRecognizeL(const TDesC& aName, const TDesC8&) { // Compare if the file extension is known if (aName.Length() < 5) { iDataType = TDataType(KNullDesC8); iConfidence = ENotRecognized; return; } if (aName.Right(5).CompareF(KLitMimeExtensionNnt1) == 0) { iDataType = TDataType(KLit8_DataType_Gif); iConfidence = ECertain; } else if (aName.Right(5).CompareF(KLitMimeExtensionNnt2) == 0) { iDataType = TDataType(KLit8_DataType_Html); iConfidence = ECertain; } else if (aName.Right(5).CompareF(KLitMimeExtensionNnt3) == 0) { iDataType = TDataType(KLit8_DataType_Vcard); iConfidence = ECertain; } else if (aName.Right(5).CompareF(KLitMimeExtensionNnt4) == 0) { iDataType = TDataType(KLit8_DataType_plainText); iConfidence = ECertain; } else { iDataType = TDataType(KNullDesC8); iConfidence = ENotRecognized; } }
TTime CTestImpExvCardSuiteStepBase::FormatDateTime(const TDesC& aParamString) { // Format of buffer to construct a TTime is YYYYMMDD:HHMMSS (15 characters). // TTime uses zero-based values for month and day - which is confusing for scripting. // In our script, we use actual month and day numbers to make things simpler so we // must modify the string here to take account of this. TBuf<32> buf; TInt m, d; buf.Zero(); buf.Copy(aParamString.Left(4)); // The year TLex lexMonth = aParamString.Mid(4, 2); lexMonth.Val(m); TLex lexDay = aParamString.Mid(6, 2); lexDay.Val(d); buf.AppendFormat(_L("%02d%02d"), m - 1, d - 1); // The month and day buf.Append(aParamString.Right(7)); return TTime(buf); }
/* ------------------------------------------------------------------------------- Y-Browser will use this function to recognize file data NOTE: This is non-leaving functions, thus do not use leaving code or you have to use TRAP to trap the leaves.. ------------------------------------------------------------------------------- */ void CYBRecognizer1::RecognizeFile(CYBRecognitionResult& aResult,const TDesC& aFileName,const TDesC8& aBuffer) { // better to be sure that the pointer is actually non-NULL // before using it to avoif KERN-EXEC 3 happening if(aResult.iIdString) { aResult.iIdString->Des().Zero(); } // first we say that its not recognized by us... aResult.iConfidence = CYBRecognitionResult::ERecNotRecognized; _LIT(KtxZipExtension ,".zip"); // filenames can actually be shorter // than normal extension lenght, thus it needs to be checked if(aFileName.Length() > 4) { TBuf<4> ZipExt; // the extension can be in any case // thus we copy it to be in lower case // to make the identification easier ZipExt.CopyLC(aFileName.Right(4)); //this recognizer only recognize extensions // but you could also use aBuffer data to recognize the file if(ZipExt == KtxZipExtension) { aResult.iConfidence = CYBRecognitionResult::ERecProbable; // incase it was constructed before // we better delete it to avoid memory leak.. // I think this might change in future editions... delete aResult.iIdString; aResult.iIdString = NULL; aResult.iIdString = KtxType().Alloc();// non leaving !!! } } }
EXPORT_C TBool CMDXMLDocument::SetDocTypeTagL(const TDesC& aDocTypeTag) // // @param replacement tag, this must be complete, starting <!DOCTYPE and finishing > // @return ETrue if operation succeeds, EFalse if formal parameter does not // begin with <!DOCTYPE or does not end with an angle bracket // @leave can Leave due to OOM // { TBool returnValue = EFalse; // if correct tag frame if(aDocTypeTag.Left(TPtrC(KXMLDocumentTypes).Length()) == KXMLDocumentTypes && aDocTypeTag.Right(TPtrC(KXMLEndTag).Length()) == KXMLEndTag) { delete iDocTypeTag; iDocTypeTag = NULL; iDocTypeTag = aDocTypeTag.AllocL(); returnValue = ETrue; } return returnValue; }
EXPORT_C TBool CMDXMLDocument::SetVersionTagL(const TDesC& aVersionTag) // // @param replacement tag, this must be complete, starting <?xml and finishing > // @return ETrue if operation succeeds, EFalse if formal parameter does not // begin with <?xml or does not end with an > // @leave can Leave due to OOM // { TBool returnValue = EFalse; // if correct tag frame if(aVersionTag.Left(TPtrC(KXMLVersion).Length()) == KXMLVersion && aVersionTag.Right(TPtrC(KXMLEndTag).Length()) == KXMLEndTag) { delete iVersionTag; iVersionTag = NULL; iVersionTag = aVersionTag.AllocL(); returnValue = ETrue; } return returnValue; }
TInt ParseCopy(const TDesC& aString) { __LOGSTR("ParseCopy"); TBuf<256> aOld; TBuf<256> aNew; TInt found; TInt err = -1; found = aString.Find(KParseCopyString); __LOGSTR1("found parsered statement: %d",found); if(found != KErrNotFound) { aOld = aString.Left(found); aNew = aString.Right(aString.Length()-(found+3)); __LOGSTR1("aOld:%S",&aOld); __LOGSTR1("aNew:%S",&aNew); err = Copy(aOld,aNew); } return err; }
/** * Try Decode image */ void CAknsSrvWallpaperCache::TryDecodeImageL( RFs& aRFs,const TDesC& aFileName ) { if ( CachedImage( aFileName ) ) { return; } _LIT( KSvgFileExt, ".svg" ); TBool isSvgFormat = (aFileName.Right(4).CompareF( KSvgFileExt ) == 0); if ( !isSvgFormat ) { CFbsBitmap* bitmap = NULL; CFbsBitmap* mask = NULL; CAknsSrvImageConverter::DecodeImageL( aRFs, aFileName, TSize(-1,-1), bitmap, mask, TSize(4000,4000) ); delete bitmap; delete mask; } }
/* * Returns the hash code(s) to use when matching the supplied phone number. If the * number supplied has more actual phone digits (i.e. not including spaces) than * KLowerSevenDigits, a second hash is generated to hold the remaining most * significant phone digits. Removes the non-digit characters. * \param text Descriptor containing contacts phone number field. * \param lowerMatchlength Number of least significant phone digits to use. * \param upperMatchLength Number of most significant phone digits to use. * \param error Qt error code. * \return The hash code(s) to use when matching the supplied phone number. */ CntFilterDetail::TMatch CntFilterDetail::createPhoneMatchNumber( const TDesC& text, TInt lowerMatchLength, TInt upperMatchLength, QContactManager::Error* error) { const TInt KBufLength = KCntMaxTextFieldLength+1; TBuf<KBufLength> buf; if (text.Length() <= KBufLength) { buf = text; } else { buf = text.Right(KBufLength); } TMatch::stripOutNonDigitChars(buf); TMatch phoneNumber; if (buf.Length() == 0) { *error = QContactManager::BadArgumentError; return phoneNumber; } // Generate a hash for the upper digits only if the phone number string is // large enough and more than 7 digits are to be matched. TInt phoneNumberlength = buf.Length(); if ((phoneNumberlength > KLowerSevenDigits) && (upperMatchLength > 0)) { TPtrC upperPart = buf.Left(phoneNumberlength - KLowerSevenDigits); phoneNumber.iUpperDigits = TMatch::createHash(upperPart, upperMatchLength, phoneNumber.iNumUpperDigits); } // Generate a hash of the lower digits. phoneNumber.iLowerSevenDigits = TMatch::createHash(buf, lowerMatchLength, phoneNumber.iNumLowerDigits); return phoneNumber; }
/** Search algorithm for searching e-mail addresses @param aText Text that will be parsed @return ETrue if any EMail items were found else returns EFalse @leave KErrNone, if successful; otherwise one of the other system-wide error codes. @panic ETulPanicDescriptorLength in debug build if item's position and/or length is out of the document's range. */ TBool CTulAddressStringTokenizer::SearchMailAddressL( const TDesC& aText ) { TInt searchStart = 0; TInt searchResult = 0; const TInt end = aText.Length(); // end of document do { TPtrC segment = aText.Right( end - searchStart ); searchResult = segment.LocateF('@'); if (searchResult != KErrNotFound) { // @ found // There should be valid characters (not a period) before and after the @ character if ( searchResult == 0 // first char || (searchResult >= segment.Length() - 1) // last char || !(IsValidEmailChar(segment[searchResult - 1])) || !(IsValidEmailHostChar(segment[searchResult + 1])) || segment[searchResult - 1] == '.' || segment[searchResult + 1] == '.' ) { searchStart += searchResult + 1; continue; } TBool wasPeriod = EFalse; // To prevent sequential periods // Get TLex from the pointer to get a better API for parsing TLexMark startPos; TLexMark endPos; TLex token = segment; // Go to searchResult and un-get until the beginning of e-mail address is reached token.Inc( searchResult ); token.Mark(); do { token.UnGet(); if ( token.Peek() == '.' ) { // If it was a period if (wasPeriod) // and if the former was also -> break break; else // else mark that this one was a period wasPeriod = ETrue; } else wasPeriod = EFalse; } while (token.Offset() > 0 && IsValidEmailChar(token.Peek())); if (token.Offset() != 0 || !IsValidEmailChar(token.Peek())) token.Inc(); // Get rid of periods from the start of address // Does it have to start with a number or char(abc...). // If it does, the loop should check that it gets rid of all special chars also. while (token.Peek() == '.') token.Inc(); token.Mark( startPos ); // Mark the beginning of address token.UnGetToMark(); wasPeriod = EFalse; do // Go forward until a nonvalid character { token.Inc(); if ( token.Peek() == '.' ) { // If it was a period if ( wasPeriod ) // and if the former was also -> break break; else // else mark that this one was a period wasPeriod = ETrue; } else wasPeriod = EFalse; } while ( !token.Eos() && IsValidEmailHostChar( token.Peek() ) ); // If address ends with a period take it away token.UnGet(); if (token.Peek() != '.') token.Inc(); token.Mark( endPos ); // Mark the beginning of address // Append the found string to the array __ASSERT_DEBUG( searchStart + token.MarkedOffset( startPos ) + token.MarkedOffset( endPos ) - token.MarkedOffset( startPos ) <= aText.Length(), Panic(ETulPanicDescriptorLength) ); AddItemL( searchStart + token.MarkedOffset( startPos ), token.MarkedOffset( endPos ) - token.MarkedOffset( startPos ), EFindItemSearchMailAddressBin); searchStart += token.MarkedOffset( endPos ) + 1; } } while ( searchResult != KErrNotFound && searchStart < end ); return (iFoundItems->Count() > 0); }
/** 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; }
/** Counts the number of parameters in the text. Needed for correct memory allocations. */ TInt CResourceLoader::GetParamCount(const TDesC& aText, TInt aIndex) { TInt paramCount(0); TInt i(0); TBool singleIndex((aIndex < 0) || (aIndex > KNumOfParams) ? EFalse : ETrue); while (i < aText.Length()) { TPtrC remainder = aText.Right(aText.Length() - i); TInt nextKey = remainder.Locate(KKeyPrefix); i += nextKey; if (nextKey != KErrNotFound && i < aText.Length() - 1) { TInt lastCharInKey = i + 1; // skip possible key index TText t = aText[lastCharInKey]; TInt foundIndex(-1); if (t >= '0' && t <= '9') { lastCharInKey++; foundIndex = t - '0'; if (lastCharInKey < aText.Length()) { t = aText[lastCharInKey]; if (t >= '0' && t <= '9') { foundIndex *= 10; foundIndex += t - '0'; lastCharInKey++; } } } // lastCharInKey is now the index of 'N' or 'U' in the key if (lastCharInKey < aText.Length()) { // Only count parameter, if index matches if (!singleIndex || (foundIndex == aIndex)) { TText t = aText[lastCharInKey]; if (t == 'U' || t == 'N') { // found legit key, count it paramCount++; // continue search after index i = lastCharInKey + 1; } else if (t == '%') i = lastCharInKey; else // continue search after index i = lastCharInKey + 1; } else // continue search after index i = lastCharInKey + 1; } else // end of string encountered - stop break; } else // no key found - stop break; } return paramCount; }
//--------------------------------------------------------------- // CNativeMmsUtility::getByUrlL // @see header //--------------------------------------------------------------- const QString CNativeMmsUtility::getByUrlL(const TDesC& url) { #ifdef _DEBUG_TRACES_ qDebug() << " Enter CNativeMmsUtility::getByUrlL"; #endif CMsvAttachment* targetattachment = NULL; TBool found = EFalse; //newlc puts it on cleanupstack HBufC8* url8bit = HBufC8::NewLC(url.Length()); CUri16* decodedUri = NULL; TUriParser8 parser; //get the uri in display format if (url.MatchF(KContentIdString) == 0) { //Remove "cid:" from the beginning url8bit->Des().Copy(url.Right(url.Length() - KContentIdString().Length() + 1)); parser.Parse(*url8bit); } else { url8bit->Des().Copy(url); parser.Parse(*url8bit); } decodedUri = UriUtils::ConvertToDisplayFormL(parser); CleanupStack::PushL(decodedUri); //run through the attachements to check for a match TUint count = iattachmanager->AttachmentCount(); for (int i = 0; i < count && !found; i++) { CMsvAttachment *attachment = iattachmanager->GetAttachmentInfoL(i); CleanupStack::PushL(attachment); //restore mimeheaders from the attachment CMsvMimeHeaders* mimeheaders = CMsvMimeHeaders::NewL(); CleanupStack::PushL(mimeheaders); mimeheaders->RestoreL(*attachment); //check for a match with content-loc and then content-id if (resolvedByContentLocL(mimeheaders->ContentLocation(), *decodedUri) || resolvedByContentIdL(mimeheaders->ContentId(), *decodedUri)) { targetattachment = CMsvAttachment::NewL(*attachment); found = ETrue; } CleanupStack::PopAndDestroy(2, attachment); //mimeheaders, attachment } CleanupStack::PopAndDestroy(decodedUri); if (url8bit) CleanupStack::PopAndDestroy(url8bit); if (targetattachment) { #ifdef _DEBUG_TRACES_ qDebug() << " Exit CNativeMmsUtility::getByUrlL"; #endif return XQConversions::s60DescToQString(targetattachment->FilePath()); } else { #ifdef _DEBUG_TRACES_ qDebug() << " Exit CNativeMmsUtility::getByUrlL"; #endif return QString(); } }
/** 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::GetPhysicalFileNameL(TDes& aPhysicalFileName, const TDesC& aSecuredFileName) { GetPhysicalPathL(aPhysicalFileName, aSecuredFileName); aPhysicalFileName.Append(KSqLiteFilePrefix); aPhysicalFileName.Append(aSecuredFileName.Right(aSecuredFileName.Length() - KDriveNameWidth)); }
// --------------------------------------------------------------------------- // ContainsSingleWildCardEnding // --------------------------------------------------------------------------- // static TBool ContainsSingleWildCardEnding( const TDesC& aString ) { return ( aString.Right( 2 ) == KPreserveAll ); }