Beispiel #1
0
// -----------------------------------------------------------------------------
// Shared by GetBtEskFilename and GetIrdaEskFilename
// -----------------------------------------------------------------------------
static void GetEskFilename( TDes& aBuff, const TDesC& aFileName )
{
    TInt maxLen = aBuff.MaxLength();
    aBuff.SetLength(maxLen);
    ::GetModuleFileName(NULL, &(aBuff[0]), maxLen);
    aBuff[aBuff.MaxLength() - 1] = 0;
    aBuff.SetLength(User::StringLength(aBuff.Ptr()));
    aBuff.SetLength(aBuff.LocateReverse('\\') + 1);
    aBuff.Append(_L( "z\\private\\101f7989\\ESock\\"));
    aBuff.Append(aFileName);
    aBuff.ZeroTerminate();
}
Beispiel #2
0
TBool CLog::ReadLogLineL(TDes& aLine)
	{
	TBuf8<2> character=_L8("  ");
	TBuf8<4> lineEndTestBuf=_L8("    ");

	aLine.SetLength(0);
	while (lineEndTestBuf!=KUnicodeLineEnd)
		{
		User::LeaveIfError(iLogFile.Read(character,2));
		if (character.Length()>0)
			{
			lineEndTestBuf[0]=lineEndTestBuf[2];
			lineEndTestBuf[1]=lineEndTestBuf[3];
			lineEndTestBuf[2]=character[0];
			lineEndTestBuf[3]=character[1];

			const TPtrC16 widePtr((TUint16*)character.Ptr(),1);
			aLine.Append(widePtr);
			}
		else
			{
			return EFalse;
			}
		}

	aLine=aLine.Left(aLine.Length()-2); // Strip off \n\r.
	return ETrue;
	}
TInt StopModeDebug::CopyAndExpandDes(const TDesC& aSrc, TDes& aDest)
	{
	//check bounds
	if(aSrc.Length() * 2 > aDest.MaxLength())
		{
		return KErrArgument;
		}

	//get a pointer to the start of the destination descriptor
	TUint16* destPtr = (TUint16*)aDest.Ptr();

	//get pointers to the start and end of the aSrc descriptor
	const TUint8* srcPtr = aSrc.Ptr();
	const TUint8* srcEnd = srcPtr + aSrc.Length();

	//copy the characters from aSrc into aDest, expanding to make them 16-bit characters
	while(srcPtr < srcEnd)
		{
		*destPtr = (TUint16)*srcPtr;
		destPtr++;
		srcPtr++;
		}

	//set aDest's length to reflect the new contents
	aDest.SetLength(2*aSrc.Length());
	return KErrNone;
	}
// -----------------------------------------------------------------------------
// CNSPTestConsoleApp::GetStringFromConsole
// -----------------------------------------------------------------------------
// 
TKeyCode CNSPTestConsoleApp::GetStringFromConsoleL( TDes& aBuffer )
	{
    TKeyCode input = EKeyNull;
    const TInt startPos = iConsole->WhereX();
	iConsole->Write( aBuffer );
	
    do  {
    	input = iConsole->Getch();
    	
    	if ( ( EKeyBackspace == input || EKeyDelete == input ) &&
    		 startPos < iConsole->WhereX() ) // Backspace & Delete
            {
            iConsole->SetPos( iConsole->WhereX() - 1 );
            iConsole->ClearToEndOfLine();
            
            aBuffer.SetLength(  0 < aBuffer.Length() ?
            					aBuffer.Length() - 1 :
            					aBuffer.Length() );
            }
    	else{
    		TChar chr( input );
    		
    		if ( chr.IsPrint() )
    			{
    			aBuffer.Append( chr );
    			iConsole->Printf( _L("%c"), input );
    			}
    		}
    	}
    while ( EKeyEnter != input && EKeyEscape != input );
    
    return input;
	}
Beispiel #5
0
void CCntItemBuilder::SetRandomAlphaNumericString(TDes& aBuf,TInt aLength)
{
    aBuf.SetLength(aLength);
    for (TInt ii = 0; ii < aLength; ++ii)
    {
        aBuf[ii]=RandomAlphaNumbericCharCode();
    }
}
/**
Helper function to strip extension
*/
void CGsaFlexiMergeManyFilesTest::StripExtension(TDes& aFilename)
	{
	TInt dot = aFilename.Find(_L("."));

	if(KErrNotFound != dot)
		{
		aFilename.SetLength(dot);
		}
	}
Beispiel #7
0
void CCntItemBuilder::SetRandomAlphaString(TDes& aBuf,TInt aLength)
{
    aBuf.SetLength(aLength);

    for (TInt i=0; i<aLength; ++i)
    {
        aBuf[i]=RandomAlphaCharCode();
    }
}
void CCmdTestSsmCommand::StripExtension( TDes& aFilename )
	{
	TInt dot = aFilename.Find( _L(".") );
	
	if( KErrNotFound != dot)
		{
		aFilename.SetLength( dot );
		}
	}	
//------------------------------------------------------------------------------------------------------------   
void CPerfDbCreator::SetRandomAlphaNumericString(TDes& aBuf,TInt aLength, TBool aWithSeed)
	{
	aBuf.SetLength(aLength);

	for (TInt ii=0;ii<aLength;++ii)
		{
		aBuf[ii]=RandomAlphaNumbericCharCode();
		}
   
   if (aWithSeed)
      aBuf.Replace(0,8, iTextSeed);		
	}
Beispiel #10
0
static void ReadDesc(TDes& aDes, const TDesC& aFilename, RFs& aFs)
	{
	RFile file;
	TInt err = file.Open(aFs, aFilename, EFileRead);
	TheTest(err == KErrNone);
	CleanupClosePushL(file);
	
	TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(aDes.Ptr())), aDes.MaxSize());
	err = file.Read(ptr);
	TheTest(err == KErrNone);
	aDes.SetLength(ptr.Length() / sizeof(TText));
	CleanupStack::PopAndDestroy(&file);
	}
Beispiel #11
0
EXPORT_C void TextUtils::TruncateToNumChars(TDes& aBuffer, TInt numChars)
/** Truncates text to a number of characters.

If truncation is required (because aBuffer contains more than numChars 
characters), an ellipsis is added to the text as the last character.

@param aBuffer On return, contains the truncated text.
@param numChars The number of characters. */
	{
	if (aBuffer.Length() <= numChars)
		return;
	aBuffer.SetLength(numChars-1);
	aBuffer.Append(KTextUtilClipEndChar);
	}
EXPORT_C void CTestUtils::AppendText(const TDesC& aToken, TDes& aTxt, TInt aMaxTokenLength)
	{
	TInt totalLen = aTxt.Length() + aMaxTokenLength;

	aTxt.Append(aToken);
	aTxt.TrimRight();

	if (aTxt.Length() < totalLen)
		{
		aTxt.AppendFill(' ', totalLen - aTxt.Length());
		}

	aTxt.SetLength(totalLen);
	}
Beispiel #13
0
//Replaces:
// 1) "%lld" with "%ld"
// 2) "%s" with "%S"
//These are the differences in format specification between RDebig::Print and OST functions.
//The new format spec length should be less or equal than the old format spec length.
static void ReplaceFmtSpec(TDes& aFormat, const TDesC& aFmtSpec, const TDesC& aNewFmtSpec)
	{
	TInt fmtLength = aFormat.Length();
	const TInt KDiff = aFmtSpec.Length() - aNewFmtSpec.Length();
    TPtr ptr((TText*)aFormat.Ptr(), fmtLength, fmtLength);
    TInt pos;
    while((pos = ptr.Find(aFmtSpec)) >= 0)
    	{
		ptr.Replace(pos, aFmtSpec.Length(), aNewFmtSpec);
		fmtLength -= KDiff;
		ptr.Set(ptr.MidTPtr(pos));
    	}
    aFormat.SetLength(fmtLength);
	}
// ---------------------------------------------------------
// Adjust language name
// ---------------------------------------------------------
//
void CGSPenInputModel::AdjustLanguageName(TInt aLangId, TDes& aLangName)
    {
    switch(aLangId)
        {
        case ELangPrcChinese:
        case ELangHongKongChinese:
        case ELangTaiwanChinese:
            {
            TInt index = aLangName.Find(KLeftBracket);
            if( index != KErrNotFound)
                {
                aLangName.SetLength(index);
                }
            }
        }
    }
//*******************************************************************************
// Method      : CTestAppConsole::GetAddrFromConsole()
// Purpose     : 
// Parameters  : 
// Return Value: 
//*******************************************************************************
TKeyCode CTestAppConsole::GetStringFromConsole(TDes &aAddr)
    {
	// Get a line from console
    TKeyCode input = EKeyNull;
    const TInt start_pos = iConsole->WhereX();
    aAddr.Zero();

    // loop until descriptor full or EKeyEnter or EKeyEscape entered
    do {
        // get one character
        input = iConsole->Getch();
        // process it
        if(input == EKeyBackspace  ||  input == EKeyDelete)
            {
            // backspace or delete
            if(iConsole->WhereX() > start_pos)
                {
				iConsole->SetPos(iConsole->WhereX() - 1);
				iConsole->ClearToEndOfLine();
				if(aAddr.Length() > 0) 
                    {
					aAddr.SetLength(aAddr.Length() - 1);
                    }
                }
            }
        else
            {
            // other than backspace or delete
            TChar ch(input);
            if(ch.IsPrint())
                {
                aAddr.Append(ch);
                iConsole->Printf(_L("%c"), input);
                }
            }   
        } 
    while(aAddr.Length() < aAddr.MaxLength()  &&  input != EKeyEnter  &&  input != EKeyEscape);

    DisplayMsg(KTxtLineBreak);
    return input;
    }
/**
Copies the content of a text column, identified by aColumnIndex, to the place refered by aDest parameter.

If the destination buffer is not big enough, the function will copy as much data as possible and will
return KErrOverflow.

@param aColumnIndex Column index
@param aDest Refers to the place where the column data will be copied.

@return KErrNone, if the function completes successfully,
                  otherwise one of the other system-wide error codes.

@panic SqlDb 5 Column index out of bounds.
@panic SqlDb 11 Statement cursor not positioned on a row
*/	
TInt CSqlStatementImpl::ColumnText(TInt aColumnIndex, TDes& aDest)
	{
	__ASSERT_ALWAYS((TUint)aColumnIndex < (TUint)iColumnCnt, __SQLPANIC(ESqlPanicBadColumnIndex));
	__ASSERT_ALWAYS(iState == CSqlStatementImpl::EAtRow, __SQLPANIC(ESqlPanicInvalidRow));
	iColumnValBufIt.MoveTo(aColumnIndex);		
	TInt err = KErrNone;
	//The text column value has not been transferred to the client side if its length is >= KSqlMaxDesLen characters.
	//In this case an additional call to the server is made to get the column value.
	if(!iColumnValBufIt.IsPresent())
		{
		if(iColumnValBufIt.Type() != ESqlText)
			{
			aDest.Zero();
			return err;
			}
		TPtr8 ptr(reinterpret_cast <TUint8*> (const_cast <TUint16*> (aDest.Ptr())), aDest.MaxLength() * sizeof(TUint16));
		err = iSqlStmtSession.ReadColumnValue(aColumnIndex, ptr);
		switch(err)
		    {
	        case KErrNone:
	        case KErrOverflow:
	            aDest.SetLength(ptr.Length() / sizeof(TUint16));
	            break;
	        default:
	            break;
		    }
		}
	else
		{
		TPtrC src = iColumnValBufIt.Text();
		TInt len = src.Length();
		if(len > aDest.MaxLength())
			{
			len = aDest.MaxLength();
			err = KErrOverflow;
			}
		aDest.Copy(src.Ptr(), len);
		}
	return err;
	}
Beispiel #17
0
EXPORT_C void TextUtils::ClipToFit(TDes& aBuffer,const CFont& aFont,TInt aMaxWidthInPixels,TChar aAlternativeEnd)
/** Clips text to fit into a maximum width.

If the text is too wide to fit in the width when displayed in aFont, 
it is truncated and the specified character (by default, 
a horizontal ellipsis) is appended to it.

@param aBuffer A buffer containing the text to clip.
@param aFont The font.
@param aMaxWidthInPixels The maximum width in pixels.
@param aAlternativeEnd The Unicode character to append to the buffer if truncated. 
By default, this is the horizontal ellipsis. */
	{
	TInt textWidth=aFont.TextWidthInPixels(aBuffer);
	if (textWidth<=aMaxWidthInPixels)
		return;
	TBuf<1> ellipse;
	ellipse.Append(aAlternativeEnd);
	TInt extraWidth=aFont.TextWidthInPixels(ellipse);
	TInt cutOff=aFont.TextCount(aBuffer,aMaxWidthInPixels-extraWidth);
	aBuffer.SetLength(cutOff);
	aBuffer.Append(ellipse);
	}
// ---------------------------------------------------------
//
// ---------------------------------------------------------
//
TInt TMmsFileText::Read( TDes& aDes )
/**
Reads single line text record into the specified descriptor.

The read operation begins at the current file position, and ends when
a line delimiter character is read or the caller's buffer is full or
the file ends;

If the line is longer than fits into user's buffer, of if the file does
not end with a terminator, KErrTooBig is returned.
The purpose is to inform the caller that a terminator should not be added
to the line when it is written elsewhere.

Next time the reading continues from the current position so that a long
line may be read in chunks and terminator added when the end of the line
has been reached.

If Read() is called when the current position is the end of the file (that 
is, after the last line delimiter in the file), KErrEof is returned, and the 
length of the buffer is set to zero.

@param aDes On return, contains the single record read from the file. Any 
            previous contents are overwritten.

@return KErrNone if successful, otherwise one of the other system-wide error 
        codes. KErrTooBig indicates that the line does not end with a
        terminator. Buffer is too short to hold the whole line or the line
        is the last line in the file and the file does not end with a 
        terminator character.
*/
	{
	TText* pD = ( TText* )aDes.Ptr();
	TInt len = aDes.MaxLength();
	TInt newLen = 0;
	TInt r = KErrNone;
    TBool terminate = EFalse;
	while ( newLen < len )
		{
		if ( iNext >= iEnd )
			{
			r = FillBuffer();
			if ( r != KErrNone && r != KErrEof )
			    {
				return r;
			    }
			if ( r == KErrEof )
				{
				aDes.SetLength( newLen );
				return ( newLen ? KErrTooBig : KErrEof );
				}
			continue;
			}
		terminate = newLen;
		r = CheckForTerminator( terminate );
		if ( r != KErrNone || terminate)
			{
			aDes.SetLength( newLen );
			return r;
			}
		*pD++ = ( *iNext++ );
		newLen++;
		}
	aDes.SetLength( newLen );
	terminate = newLen;
	r=CheckForTerminator( terminate );
	if ( r != KErrNone || terminate )
	    {
		return r;
	    }
// don't skip the rest of the line - return the rest the next time.
	return KErrTooBig;
	}