You can parse, add or remove the delimiter and segment within the URI
using CDelimitedXxxx8
classes.
Note: TDelimitedXxxxParser8
classes provide the
functionality for parsing only.
Classes CDelimitedPath8
,
CDelimitedPathSegment8
and
CDelimitedQuery8
are derived from
CDelimitedDataBase
to add and remove data and delimiters
from the respective component.
CDelimitedXxxx8
classes provide the following functionality:
SetDelimiter()
, Parse()
and
ParseReverse()
functions are used to set the delimiter and parse
the data. ParseReverse()
is used, for example, when you want to
extract the file name. For more details on parsing the delimited data, refer to
How to parse the delimited data.
Note: Delimiter needs to be set before the data is parsed.
The following are some of URI data and delimiter modifications that can be performed on a URI:
_LIT8(KPath,"c:/myfolder");
_LIT8(KLogs,"logs");
CDelimitedPath8* dpath = CDelimitedPath8::NewL(KPath); //Create CDelimitedPath8 object
dpath->PopFrontL();
const TDesC8& des = dpath->Parser().Des(); // remove first segment containing "c:"
The above code removes the first segment from the data. des
holds "/myfolder/logs
" after removing "c:". To remove the last
segment from the data, use PopBackL()
.
dpath->PushBackL(KLogs);
const TDesC8& des = dpath->Parser().Des(); // add "logs" at the end
The above code adds a new segment at the end of the data.
des
holds "c:/myfolder/logs
" after adding
"logs
". To add a new segment at the beginning of the data, use
PushFrontL()
.
dpath->TrimFrontDelimiterL();
const TDesC8& des = dpath->Parser().Des(); // remove delimiter "/" at the beginning
The above code removes the delimiter from the beginning of the data.
des
holds "myfolder/logs
" after removing
"/
". To add the delimiter at the beginning or at the end of the
data, use AddFrontDelimiterL()
and
AddBackDelimiterL()
respectively.
dpath->Parse(); //Parse before removing the segment
dpath->RemoveCurrentL(); //remove the current segment
const TDesC8& des = dpath->Parser().Des(); // parse the data after removing "myfolder"
The above code parses the data and removes the current segment of data.
des
holds "/logs
" after removing
"myfolder
". Note that the data need to be parsed after removing
the segment.
_LIT8(KHolyfolder,"Holyfolder"); // data to insert
dpath->InsertCurrentL(KHolyfolder); //insert a new segment before the current segment
const TDesC8& des = dpath->Parser().Des(); // parse the data after inserting "Holyfolder"
This code inserts a new segment before the current parsed segment.
des
holds "/Holyfolder/logs
" after inserting
"Holyfolder
".
In addition to functions from the base class, the above three classes provide the following functionality:
A character in the URI may not be available on the keyboard or might not be usable in contexts where it may conflict with a reserved character. In either case, the character can be encoded with a '%' followed by its ASCII hexadecimal equivalent code. For more information, refer to How to escape encode and decode.
The example shows how the character "#" is encoded with a "%" followed by its ASCII hexadecimal equivalent code "%23". To modify the data and escape encode, the following functions are used:
_LIT8(KInsertEscape,"file#1"); //data to insert
dpath->InsertAndEscapeCurrentL(KInsertEscape); //escape encode and insert segment
const TDesC8& des = dpath->Parser().Des(); //descritpor contains "/Myfolder/file%231/logs"
The code escape encodes the segment and inserts the escaped version
before the current parsed segment. des
holds
"/Myfolder/file%231/logs
" after inserting the escape encoded
segment "file%231
".
_LIT8(KPushEscape,"file#1");
dpath->PushAndEscapeFrontL(KPushEscape); //escape encode and insert the segment
const TDesC8& des6 = dpath->Parser().Des(); //descritpor contains "/file%231/Myfolder/logs"
The code escape encodes the segment
file#1
and inserts the escaped version at the beginning of the
path. des
holds "/file%231/Myfolder/logs
" after
inserting "file%231
". To insert an escape encoded version of the
segment at the end of the path, use
CDelimitedPath8::PushAndEscapeFrontL()
.
In all the three insert functions, the newly inserted segments should contain a single path segment, as any path delimiters in the segment will be converted to an escape triple.
Note : In case of Unicode data, you need to convert to utf8 first, escape encode, re-convert to 16-bit and then insert the escaped version of the path segment.