|
||
InetProtTextUtils
provides various text parsing
utilities for manipulating the data in HTTP headers. This include:
removing the white space
converting the data.
You can remove any contiguous white spaces at either or both the ends
of the data, as specified by the mode (right, left, or both) using
InetProtTextUtils::RemoveWhiteSpace()
. A white space
includes blank spaces, tabs and separators (e.g. new line).
_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);
The code removes the white spaces on the left side of the URI. If the
white space is removed, it returns KErrNone
, otherwise 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()
.
The InetProtTextUtils
class provides various data
conversion methods. You can convert decimal and hex descriptors to its integer
representations and vice versa. The methods are shown below:
You can convert an integer into a decimal or hexademial number by
calling InetProtTextUtils::ConvertIntToDescriptorL()
or
InetProtTextUtils::ConvertHexToDescriptorL()
respectively.
// 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
.
The character representation of an integer can be converted into its
numeric value by calling
InetProtTextUtils::ConvertDescriptorToIntL()
. 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
The character representation of an integer can be converted to its
hexadecimal value by calling
InetProtTextUtils::ConvertDescriptorToHex()
.
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.
A quoted string within a URI can be extracted using
InetProtTextUtils::ExtractQuotedStringL()
.
_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);
InetProtTextUtils::ExtractQuotedStringL(ptr, ptr1); //ptr contains "outside quotes" and ptr1 contains "inside quotes"
where, ptr1
is a pointer that points to the quoted string
"inside quotes
"