Escape and Insert

This section explains the concept of escape and insert, which is necessary for avoiding conflicts of characters and interpreting URI correctly.

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 Escape encoding and decoding .

The following 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, first convert to utf8, escape encode, re-convert to 16-bit, and then insert the escaped version of the path segment.