Manipulating URI Data

This tutorial describes the steps to manipulate the URI data.


InetProtTextUtils provides various text parsing utilities for manipulating the data in HTTP headers. This includes:

  • removing the white space

  • converting the data.

Removing white spaces

InetProtTextUtils::RemoveWhiteSpace() removes any contiguous white spaces at either or both the ends of the data, as specified by the mode (right, left, or both). A white space includes blank spaces, tabs and separators. For example, new line.

The following code removes the white spaces on the left side of the URI.

_LIT( KFullUriPath," P:\\DV3\\gothere\\moveon.htm" ); // URI 
TPtrC uriName(KFullUriPath);                          //pointer to the URI
//Remove the white space on the left side of URI
Tint consumedWhiteSpacesLeft = InetProtTextUtils::RemoveWhiteSpace( uriName, InetProtTextUtils::ERemoveLeft );

If the white space is removed, it returns KErrNone, else it returns KErrNotFound. ERemoveRight or ERemoveBoth is used to remove white spaces on right side or both sides of the URI, respectively.

Note: The white spaces within the URI cannot be removed using RemoveWhiteSpace().

Converting the data

InetProtTextUtils class provides various data conversion methods. The methods can be used to convert decimal and hex descriptors into its integer representations and vice versa. The following are the methods:

Converting data from an integer to a string

Call InetProtTextUtils::ConvertIntToDescriptorL() or InetProtTextUtils::ConvertHexToDescriptorL() to convert an integer into a decimal or hexademial number respectively. The following code converts the integer value of the data to a string:

// Convert the integer value of the data to a string
TInt intVal = 489;
HBufC8* abuf = HBufC8::NewL( 32 );//a descriptor is allocated on the heap to hold the data.
InetProtTextUtils::ConvertIntToDescriptorL( intVal,abuf );// abuf contains "489", the extracted value.

where, intVal stores the data to be converted. The converted abuf contains the extracted descriptor.

TInt intVal=489;
HBufC8* abuf = HBufC8::NewL( 32 );
InetProtTextUtils::ConvertHexToDescriptorL( intVal,abuf );//abuf contains 1E9

where, intVal stores the data to be converted. The converted value will be stored in the buffer abuf.

Converting data from a string to a number

Call InetProtTextUtils::ConvertDescriptorToIntL() to convert the character representation of an integer into its numeric value. Preceding white space is ignored and the integer is delimited by either the end of the data, whitespace or any character other than 0 to 9.

//Convert the string to an integer
TInt intVal = 0;
_LIT8( KNumber,"489" );
InetProtTextUtils::ConvertDescriptorToInt( KNumber,intVal ); // the intVal now holds the integer 489

Call InetProtTextUtils::ConvertDescriptorToHex() to convert the character representation of an integer to its hexadecimal value.

TInt intVal = 0;
_LIT8( KNumber,"64" );
InetProtTextUtils::ConvertDescriptorToHex( KNumber,intVal ); //intVal = 100

This function extracts the value contained in the buffer intVal and considers a hexadecimal number.

Extracting the quoted string

InetProtTextUtils::ExtractQuotedStringL() extracts the quoted string within an URI.

_LIT8( KQuotedBuffer0,    "this is the \"inside quotes\" outside quotes" ); // the string to be manipulated
TBuf8<64>  quotedString;
TPtrC8 ptr( KQuotedBuffer0() ); //pointer to the string
TPtrC8 ptr1( quotedString );
//ptr contains "outside quotes" and ptr1 contains "inside quotes"
InetProtTextUtils::ExtractQuotedStringL( ptr, ptr1 ); 

where, ptr1 is a pointer that points to the quoted string "inside quotes "

See also

HTTP Utilities Library Overview