Parsing an URI

This tutorial describes the steps to parse an URI.

Introduction

Parsing is done before performing any of the following tasks:

  • Extracting the URI components

  • Modifying the URI components

  • Getting the file name

  • Modifying the delimiters

  • Resolving the URI

The URI is parsed into its components (scheme, authority, path, query and fragment) to check if they are syntactically correct. Also, the checks the validity of individual components that needs to be parsed, using TUriParser8::Parse().

Parsing an URI descriptor object

The following code fragment parses the URI descriptor object. It returns KErrNone if parsing is successful and EUriUtilsParserErrInvalidUri if the passed descriptor is invalid.


LIT8( KUri,"http://web.intra/Dev/Sysdoc/devlib.htm" );
TUriParser8 parser;                          // URI parser object
TInt result = parser.Parse( KUri );            // Parse the URI descriptor 
const TDesC8& des1 = parser.UriDes();        // Returns the parsed URI

where, KUri is the URI descriptor to be parsed. This code returns the descriptor containing http://web.intra/Dev/Sysdoc/devlib.htm, the parsed form of the URI.

TUriParser8::Parse() parses the URI components, except for SIP and SIPS scheme component.

Parsing an authority component

To make use of the authority parsing utilities, declare a TAuthorityParser8 parser object, and parse the descriptor containing the URI authority component. Call TAuthorityParser8::Parse() to parse the authority component.

_LIT8( KAuthorityDesc,    "http://user:[email protected]" );
TAuthorityParser8 authorityParser;                     // the authority parser object 
//Parse the authority component by passing authority descriptor   
authorityParser.Parse( KAuthorityDesc );  
const TDesC8& des = authorityParser.AuthorityDes();    //retrieve the parsed URI

where, des is a descriptor that contains the parsed URI.

See also

For related information, see HTTP Utilities Library Overview