sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FBaseUtilUri.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FBaseUtilUri.h
20  * @brief               This is the header file for the %Uri class.
21  *
22  * This header file contains the declarations of the %Uri class.
23  */
24 #ifndef _FBASE_UTIL_URI_H_
25 #define _FBASE_UTIL_URI_H_
26
27 #include <FBaseObject.h>
28 #include <FBaseString.h>
29 #include <FBaseBuffer.h>
30
31
32 namespace Tizen { namespace Base { namespace Utility
33 {
34
35 /**
36  * @class       Uri
37  * @brief       This class provides useful methods for URI.
38  *
39  * @since 2.0
40  *
41  * The %Uri class represents a Uniform Resource Identifier (URI) as defined by RFC2396 and provides accessors
42  * which access the URI component.
43  * It also provides methods for creating, accessing, normalizing, resolving, and relativizing %Uri instances.
44  *
45  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/uri.htm">URI</a>.
46  *
47  * The following example demonstrates how to use the %Uri class.
48  *
49  * @code
50  *
51  * #include <FBase.h>
52  *
53  * using namespace Tizen::Base;
54  * using namespace Tizen::Base::Utility;
55  *
56  * void
57  * MyClass::UriSample(void)
58  * {
59  *              String base(L"http://www.samsung.com");
60  *              String against(L"/osp/framework/index.html");
61  *              String resolveString(L"http://www.samsung.com/osp/framework/index.html");
62  *
63  *              Uri baseUri;
64  *              baseUri.SetUri(base);
65  *
66  *              Uri againstUri;
67  *              againstUri.SetUri(against);
68  *
69  *              Uri resultUri;
70  *              baseUri.Resolve(againstUri, resultUri);
71  *
72  *              String resultString = resultUri.ToString();
73  *              if (resultString.Equals(resolveString))
74  *              {
75  *                      // ...
76  *              }
77  *
78  * }
79  * @endcode
80  */
81 class _OSP_EXPORT_ Uri
82         : public Tizen::Base::Object
83 {
84 public:
85         /**
86          * This is the default constructor for this class.
87          *
88          * @since 2.0
89          */
90         Uri(void);
91
92         /**
93          * Copying of objects using this copy constructor is allowed.
94          *
95          * @since 2.0
96          *
97          *  @param[in]  uri             An instance of %Uri to copy
98          */
99         Uri(const Uri& uri);
100
101         /**
102          * This destructor overrides Tizen::Base::Object::~Object().
103          *
104          * @since 2.0
105          */
106         virtual ~Uri(void);
107
108         /**
109          * Sets the current %Uri instance to the value of the specified instance of %Uri.
110          *
111          * @since 2.0
112          *
113          * @param[in]   uri             An instance of %Uri
114          */
115         void SetUri(const Uri& uri);
116
117         /**
118          * Sets the current %Uri instance by parsing a given string.
119          *
120          * @since 2.0
121          *
122          * @return              An error code
123          * @param[in]   str             A string to parse into a URI
124          * @exception   E_SUCCESS                               The method is successful.
125          * @exception   E_INVALID_ARG                   The specified @c str is an empty string.
126          * @exception   E_INVALID_FORMAT                The specified @c str violates the URI syntax (RFC 2396).
127          */
128         result SetUri(const Tizen::Base::String& str);
129
130         /**
131          * Sets an absolute %Uri instance with given components.
132          *
133          * @since 2.0
134          *
135          * @return              An error code
136          * @param[in]   scheme                  The scheme
137          * @param[in]   ssp                             The scheme-specific-part
138          * @param[in]   fragment                The fragment
139          * @exception   E_SUCCESS                               The method is successful.
140          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
141          */
142         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& ssp, const Tizen::Base::String& fragment);
143
144         /**
145          * Sets an absolute and hierarchical %Uri instance with the given components.
146          *
147          * @since 2.0
148          *
149          * @return              An error code
150          * @param[in]   scheme                  The scheme
151          * @param[in]   userInfo                The user name and authorization
152          * @param[in]   host                    The host name
153          * @param[in]   port                    The port number
154          * @param[in]   path                    The path
155          * @param[in]   query                   The query
156          * @param[in]   fragment                The fragment
157          * @exception   E_SUCCESS                               The method is successful.
158          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
159          */
160         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& userInfo, const Tizen::Base::String& host, int port, const Tizen::Base::String& path, const Tizen::Base::String& query, const Tizen::Base::String& fragment);
161
162         /**
163          * Sets an absolute and hierarchical %Uri instance with the given components.
164          *
165          * @since 2.0
166          *
167          * @return              An error code
168          * @param[in]   scheme                  The scheme
169          * @param[in]   host                    The host name
170          * @param[in]   path                    The path
171          * @param[in]   fragment                The fragment
172          * @exception   E_SUCCESS                               The method is successful.
173          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
174          * @remarks     The authority and query component are left empty, and the port is set to @c -1.
175          */
176         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& host, const Tizen::Base::String& path, const Tizen::Base::String& fragment);
177
178         /**
179          * Sets an absolute and hierarchical %Uri instance with the given components.
180          *
181          * @since 2.0
182          *
183          * @return              An error code
184          * @param[in]   scheme                  The scheme
185          * @param[in]   authority               The authority
186          * @param[in]   path                    The path
187          * @param[in]   query                   The query
188          * @param[in]   fragment                The fragment
189          * @exception   E_SUCCESS                               The method is successful.
190          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
191          */
192         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& authority, const Tizen::Base::String& path, const Tizen::Base::String& query, const Tizen::Base::String& fragment);
193
194         /**
195          * Copying of objects using this copy assignment operator is allowed.
196          *
197          * @since 2.0
198          *
199          * @return              A reference to the calling instance
200          * @param[in]   rhs             An instance of %Uri
201          */
202         Uri& operator =(const Uri& rhs);
203
204         /**
205          * Gets the value of the authority component.
206          *
207          * @since 2.0
208          *
209          * @return              The value of the authority component, @n
210          *                              else an empty string if the authority component is undefined
211          * @remarks             The string returned by this method is equal to the string returned by GetEncodedAuthority(),
212          *                              except that all sequences of the escaped octets are decoded.
213          */
214         Tizen::Base::String GetAuthority(void) const;
215
216         /**
217          * Gets the value of the fragment component.
218          *
219          * @since 2.0
220          *
221          * @return              The value of the fragment component, @n
222          *                              else an empty string if the fragment component is undefined
223          * @remarks             The string returned by this method is equal to the string returned by GetEncodedFragment(),
224          *                              except that all sequences of the escaped octets are decoded.
225          */
226         Tizen::Base::String GetFragment(void) const;
227
228         /**
229          * Gets the value of the host component.
230          *
231          * @since 2.0
232          *
233          * @return              The value of the host component, @n
234          *                              else an empty string if the host component is undefined
235          */
236         Tizen::Base::String GetHost(void) const;
237
238         /**
239          * Gets the value of the path component.
240          *
241          * @since 2.0
242          *
243          * @return              The value of the path component, @n
244          *                              else an empty string if the path component is undefined
245          * @remarks             The string returned by this method is equal to the string returned by GetEncodedPath(),
246          *                              except that all sequences of the escaped octets are decoded.
247          */
248         Tizen::Base::String GetPath(void) const;
249
250
251         /**
252          * Gets the value of the port component.
253          *
254          * @since 2.0
255          *
256          * @return              The value of the port component, @n
257          *                              else @c -1 if the port component is undefined
258          */
259         int GetPort(void) const;
260
261
262         /**
263          * Gets the value of the query component.
264          *
265          * @since 2.0
266          *
267          * @return              The value of the query component, @n
268          *                              else an empty string if the query component is undefined
269          * @remarks             The string returned by this method is equal to the string returned by GetEncodedQuery(),
270          *                              except that all sequences of the escaped octets are decoded.
271          */
272         Tizen::Base::String GetQuery(void) const;
273
274
275         /**
276          * Gets the value of the scheme component.
277          *
278          * @since 2.0
279          *
280          * @return              The value of the query scheme, @n
281          *                              else an empty string if the query scheme is undefined
282          */
283         Tizen::Base::String GetScheme(void) const;
284
285
286         /**
287          * Gets the value of the scheme-specific-part component.
288          *
289          * @since 2.0
290          *
291          * @return              The value of the scheme-specific-part component, @n
292          *                              else an empty string if the scheme-specific-part component is undefined
293          * @remarks             The string returned by this method is equal to the string returned by GetEncodedSchemeSpecificPart(),
294          *                              except that all sequences of the escaped octets are decoded.
295          */
296         Tizen::Base::String GetSchemeSpecificPart(void) const;
297
298
299         /**
300          * Gets the value of the user-info component.
301          *
302          * @since 2.0
303          *
304          * @return              The value of the user-info component, @n
305          *                              else an empty string if the user-info component is undefined
306          * @remarks             The string returned by this method is equal to the string returned by GetEncodedUserInfo(),
307          *                              except that all sequences of the escaped octets are decoded.
308          */
309         Tizen::Base::String GetUserInfo(void) const;
310
311
312         /**
313          * Gets the encoded value of the authority component. @n
314          * The non-US-ASCII characters in the authority component are encoded to escaped octets.
315          *
316          * @since 2.0
317          *
318          * @return              The encoded value of the authority component, @n
319          *                              else an empty string if the authority component is undefined
320          */
321         Tizen::Base::String GetEncodedAuthority(void) const;
322
323
324         /**
325          * Gets the encoded value of the fragment component. @n
326          * The non-US-ASCII characters in the fragment component are encoded to escaped octets.
327          *
328          * @since 2.0
329          *
330          * @return              The encoded value of the fragment component, @n
331          *                              else an empty string if the fragment component is undefined
332          */
333         Tizen::Base::String GetEncodedFragment(void) const;
334
335
336         /**
337          * Gets the encoded value of the path component. @n
338          * The non-US-ASCII characters in the path component are encoded to escaped octets.
339          *
340          * @since 2.0
341          *
342          * @return              The encoded value of the path component, @n
343          *                              else an empty string if the path component is undefined
344          */
345         Tizen::Base::String GetEncodedPath(void) const;
346
347
348         /**
349          * Gets the encoded value of the query component. @n
350          * The non-US-ASCII characters in the query component are encoded to escaped octets.
351          *
352          * @since 2.0
353          *
354          * @return              The encoded value of the query component, @n
355          *                              else an empty string if the query component is undefined
356          */
357         Tizen::Base::String GetEncodedQuery(void) const;
358
359
360         /**
361          * Gets the encoded value of the scheme-specific-part component. @n
362          * The non-US-ASCII characters in the scheme-specific-part component are encoded to escaped octets.
363          *
364          * @since 2.0
365          *
366          * @return              The encoded value of the scheme-specific-part component, @n
367          *                              else an empty string if the scheme-specific-part component is undefined
368          */
369         Tizen::Base::String GetEncodedSchemeSpecificPart(void) const;
370
371         /**
372         * Gets the encoded value of a user-info component,
373         * or returns an empty string if the user-info component is undefined. @n
374         * The non-US-ASCII characters in the user-info component are encoded to escaped octets.
375         *
376         * @since 2.0
377         *
378         * @return               The encoded value of user-info, @n
379         *                               else an empty string if the user-info component is undefined
380         */
381         Tizen::Base::String GetEncodedUserInfo(void) const;
382
383
384         /**
385          * Checks whether the current %Uri instance is an absolute URI.
386          *
387          * @since 2.0
388          *
389          * @return              @c true if the current %Uri instance is an absolute URI, @n
390          *                              else @c false
391          */
392         bool IsAbsolute(void) const;
393
394
395         /**
396          * Checks whether the calling %Uri instance is an opaque URI.
397          *
398          * @since 2.0
399          *
400          * @return              @c true if the current %Uri instance is an opaque URI, @n
401          *                              else @c false
402          */
403         bool IsOpaque(void) const;
404
405
406         /**
407          * Gets the encoded US-ASCII string.
408          *
409          * @since 2.0
410          *
411          * @return              The encoded US-ASCII string
412          * @remarks             If this URI does not contain any non US_ASCII characters,
413          *                              then the string returned by this method is equal to the string returned by ToString().
414          *
415          * The following example demonstrates how to use the %GetEncodedString() method.
416          *
417          * @code
418          * String str(L"http://www.sec.com/osp?currency==\u20ac");
419          *
420          *       Uri uri;
421          *       uri.SetUri(str);
422          *
423          *       String encode = uri.GetEncodedString();        // encode == L"http://www.sec.com/osp?currency==%E2%82%AC"
424          *
425          * @endcode
426          */
427         Tizen::Base::String GetEncodedString(void) const;
428
429         /**
430          * Compares the calling URI instance to the specified %Uri instance. @n
431          * When comparing corresponding components of two URIs, if one component in the current instance is undefined
432          * but the other is defined, then the current instance is considered to be less than the given object.
433          *
434          * @since 2.0
435          *
436          * @return              The result of the comparison
437          * @code
438          * < 0  if the current instance is less than the given object
439          * = 0  if the current instance is equal to the given object
440          * > 0  if the current instance is greater than the given object
441          * @endcode
442          * @param[in]   uri                     An instance of %Uri
443          * @remarks
444          *
445          * Ordering of URIs
446          * 1. Scheme
447          *    Two URIs are ordered according to the ordering of schemes, without regard to case.
448          * 2. Hierarchical URI vs. Opaque URI
449          *    A hierarchical URI is less than an opaque URI if they have an identical scheme.
450          * 3. Scheme-specific-part
451          *    If two opaque URIs have an identical scheme, they are ordered according to
452          *    the scheme-specific-part, without regard to %case.
453          * 4. Fragment
454          *    If two opaque URIs have identical schemes and scheme-specific-parts, they are ordered according
455          *    to the ordering of fragments, without regard to case.
456          * 5. Authority
457          *    If two hierarchical URIs have identical schemes, they are ordered according to the authority,
458          *    without regard to the case.
459          *       5-1. Server-based authority
460          *             If two URIs are server-based, they are ordered according to their user-information,
461          *             without regard to case.
462          *             If the hosts are identical, then the URIs are ordered according to the ordering of ports.
463          * 6. Path
464          *    If two hierarchical URIs have identical schemas and authority components, they are ordered according to the
465          *    ordering of paths, without regard to the case.
466          *    If their paths are identical, their queries are compared. And if the queries are the same, then their fragments
467          *    are compared.
468          *
469          */
470         int CompareTo(const Uri& uri) const;
471
472
473         /**
474          *      Compares the specified instance to the current instance.
475          *
476          *  @since 2.0
477          *
478          *      @return         @c true if the two instances are equal, @n
479          *                              else @c false
480          *      @param[in]      obj     The object to compare with the current instance
481          *      @remarks        Two equal instances must return the same hash value. The default
482          *                              implementation of this method returns @c true if two instances
483          *                              have the same address. @n
484          *                              The method can be overridden to support value equality. Furthermore, the Equals()
485          *                              method must return the same results as the equality operator.
486          */
487         virtual bool Equals(const Tizen::Base::Object& obj) const;
488
489
490         /**
491          *      Gets the hash value of the current instance.
492          *
493          *  @since 2.0
494          *
495          *      @return         The hash value of the current instance
496          *      @remarks        Two equal instances must return the same hash value. For better performance,
497          *                              the used hash function must generate a random distribution for all inputs.
498          */
499         virtual int GetHashCode(void) const;
500
501
502         /**
503          * Normalizes the current URI.
504          *
505          * @since 2.0
506          *
507          * @return              The normalized URI, @n
508          *                              else the current URI in case any error occurs
509          * @remarks     Normalization is the process of removing unnecessary "." and ".." segments from the path component of the
510          *                      hierarchical URI. All "." segments are removed and If a ".." segment is preceded by a non-".." segment,
511          *                      both of these segments are removed. If a URI is opaque, the normalization has no effect.
512          *
513          * The following example demonstrates how to use the %Normalize() method.
514          *
515          * @code
516          *       Uri uri1;
517          *       uri1.SetUri(L"http://www.example.com/a/b/../c/./d.html");
518          *
519          *       Uri uriNormalized = uri1.Normalize();
520          *       String uriStr = uriNormalized.ToString();              // uriStr == L"http://www.example.com/a/c/d.html"
521          *
522          * @endcode
523          */
524         Uri Normalize(void);
525
526
527         /**
528          * Parses the server-based authority component, if defined.
529          *
530          * @since 2.0
531          *
532          * @return              An error code
533          * @param[out]  uri                                     The parsed URI
534          * @exception   E_SUCCESS                       The method is successful.
535          * @exception   E_INVALID_FORMAT        The authority component is defined but cannot be parsed as a server-based authority.
536          * @remarks             This method is provided because the generic URI syntax cannot always distinguish a malformed server-based authority from a legitimate registry-based authority.
537          *                              For example, the authority component in the URI string "//foo:bar/" is not a legal
538          *                              server-based authority but it is legal as a registry-based authority.
539          */
540         result ParseAuthority(Uri& uri);
541
542
543         /**
544          * Relativizes the specified %Uri instance against the calling %Uri instance.
545          *
546          * @since 2.0
547          *
548          * @return              An error code
549          * @param[in]   uri                                     The %Uri to relativize against the calling %Uri
550          * @param[out]  resultUri                       The relativized URI
551          * @exception   E_SUCCESS                       The method is successful.
552          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
553          * @remarks             Relativization is the opposite of Resolution. It is used
554          *                              to divide a URI into the base URI and the relative URI.
555          */
556         result Relativize(const Uri& uri, Uri& resultUri);
557
558
559         /**
560          * Resolves the specified %Uri instance against the calling %Uri instance.
561          *
562          * @since 2.0
563          *
564          * @return              An error code
565          * @param[in]   uri                                     The URI to resolve against this URI
566          * @param[out]  resultUri                       The resolved URI
567          * @exception   E_SUCCESS                       The method is successful.
568          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
569          * @remarks             Resolution is the process of resolving a URI against another, base URI. For hierarchical URI,
570          *                              the path of the original is resolved against the path of the base URI and then normalized. @n
571          *
572          *                              For example, to resolve the URI "/osp/framework/index.html" against the base URI "http://www.samsung.com" ,
573          *                              the resultant URI is "http://www.samsung.com/osp/framework/index.html".
574          *
575          */
576         result Resolve(const Uri& uri, Uri& resultUri);
577
578
579         /**
580          * Sets the authority component to the specified String instance.
581          *
582          * @since 2.0
583          *
584          * @return              An error code
585          * @param[in]   authority                       The authority
586          * @exception   E_SUCCESS                       The method is successful.
587          * @exception   E_INVALID_FORMAT        The specified string is invalid.
588          */
589         result SetAuthority(const Tizen::Base::String& authority);
590
591
592         /**
593          * Sets the fragment component to the specified String instance.
594          *
595          * @since 2.0
596          *
597          * @return              An error code
598          * @param[in]   fragment                        The new fragment
599          * @exception   E_SUCCESS                       The method is successful.
600          * @exception   E_INVALID_FORMAT        The specified string is invalid.
601          */
602         result SetFragment(const Tizen::Base::String& fragment);
603
604
605         /**
606          * Sets the host component to the specified String instance.
607          *
608          * @since 2.0
609          *
610          * @return              An error code
611          * @param[in]   host                            The new host
612          * @exception   E_SUCCESS                       The method is successful.
613          * @exception   E_INVALID_FORMAT        The specified string is invalid.
614          */
615         result SetHost(const Tizen::Base::String& host);
616
617
618         /**
619          * Sets the path component to the specified String instance.
620          *
621          * @since 2.0
622          *
623          * @return              An error code
624          * @param[in]   path                            The new path component
625          * @exception   E_SUCCESS                       The method is successful.
626          * @exception   E_INVALID_FORMAT        The specified string is invalid.
627          */
628         result SetPath(const Tizen::Base::String& path);
629
630
631         /**
632          * Sets the port component to a given integer.
633          *
634          * @since 2.0
635          *
636          * @return              An error code
637          * @param[in]   port                            The new port component
638          * @exception   E_SUCCESS                       The method is successful.
639          * @exception   E_INVALID_ARG           The specified @c port is negative.
640          */
641         result SetPort(int port);
642
643
644         /**
645          * Sets the query component to the specified String instance.
646          *
647          * @since 2.0
648          *
649          * @return              An error code
650          * @param[in]   query                           The new query string
651          * @exception   E_SUCCESS                       The method is successful.
652          * @exception   E_INVALID_FORMAT        The specified string is invalid.
653          */
654         result SetQuery(const Tizen::Base::String& query);
655
656
657         /**
658          * Sets the scheme component to the specified String instance.
659          *
660          * @since 2.0
661          *
662          * @return              An error code
663          * @param[in]   scheme                          The new scheme
664          * @exception   E_SUCCESS                       The method is successful.
665          * @exception   E_INVALID_FORMAT        The specified string is invalid.
666          */
667         result SetScheme(const Tizen::Base::String& scheme);
668
669
670         /**
671          * Sets the scheme-specific-part component to the specified String instance.
672          *
673          * @since 2.0
674          *
675          * @return              An error code
676          * @param[in]   ssp                                     The new scheme-specific-part component
677          * @exception   E_SUCCESS                       The method is successful.
678          * @exception   E_INVALID_FORMAT        The specified string is invalid.
679          */
680         result SetSchemeSpecificPart(const Tizen::Base::String& ssp);
681
682
683         /**
684          * Sets the user-info component to the specified String instance.
685          *
686          * @since 2.0
687          *
688          * @return              An error code
689          * @param[in]   userInfo                        The new user-info string
690          * @exception   E_SUCCESS                       The method is successful.
691          * @exception   E_INVALID_FORMAT        The specified string is invalid.
692          */
693         result SetUserInfo(const Tizen::Base::String& userInfo);
694
695
696         /**
697          * Gets the content of the calling %Uri instance as a string containing escaped octets.
698          *
699          * @since 2.0
700          *
701          * @return              The content of this URI as a string containing escaped octets
702          */
703         Tizen::Base::String ToString(void) const;
704
705 private:
706         //
707         // Constructs an Uri instance with the given components.
708         // scheme, ssp(opaquePart), authority, user-info, host, port, path, query, fragment
709         //
710         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& opaque,
711                 const Tizen::Base::String& authority, const Tizen::Base::String& userInfo,
712                 const Tizen::Base::String& host, int port, const Tizen::Base::String& path,
713                 const Tizen::Base::String& query, const Tizen::Base::String& fragment);
714
715         //
716         // Appends a given scheme-specific-part to a String.
717         //
718         result AppendSchemeSpecificPart(Tizen::Base::String& strbuf, const Tizen::Base::String& opaque,
719                 const Tizen::Base::String& authority, const Tizen::Base::String& userInfo,
720                 const Tizen::Base::String& host, int port, const Tizen::Base::String& path,
721                 const Tizen::Base::String& query) const;
722
723         //
724         // Appends a given fragment to a String.
725         //
726         result AppendFragment(Tizen::Base::String& strbuf, const Tizen::Base::String& fragment) const;
727
728         //
729         // Appends a given authority component to a String.
730         //
731         result AppendAuthority(Tizen::Base::String& strbuf, const Tizen::Base::String& authority,
732                 const Tizen::Base::String& userInfo, const Tizen::Base::String& host, int port) const;
733
734         //
735         // Parses a given URI string.
736         //
737         result ParseUri(const Tizen::Base::String& str);
738
739         //
740         // Copies a given URI.
741         //
742         result CopyUri(const Uri& uri);
743
744         //
745         // Encodes all components - authority, fragment, path, query, and ssp.
746         //
747         void EncodeAllComponent(void);
748
749         //
750         // Parses a hierarchical URI string.
751         // @return              The start index of the fragment. If the operation fails, @c -1 is returned.
752         // @param[in]   startSsp                        The start index of scheme-specific-part
753         // @param[in] lengthOfUri               The length of the URI string
754         // @param[out] authority        A parsed authority component
755         // @param[out] path                     A parsed path component
756         // @param[out] query                    A parsed query component
757         //
758         result ParseHierarchicalUri(const Tizen::Base::String& str, int startSsp, Tizen::Base::String& authority,
759                 Tizen::Base::String& path, Tizen::Base::String& query, int& index);
760
761
762         //
763         // Parses a server_based authority component.
764         // server_based authority: [user-info@]<host>[:port]
765         //
766         result ParseAuthority(const Tizen::Base::String& str, int curIndex, Tizen::Base::String& newAuth,
767                 Tizen::Base::String& userInfo, Tizen::Base::String& host, int& port);
768
769         void SetAndEncodeAuthority(const Tizen::Base::String& authority,
770                 const Tizen::Base::String& path, const Tizen::Base::String& query);
771
772         //
773         // Parses a server_based authority component.
774         // Assigns user-info, host and port to their member variable.
775         //
776         result ParseServerAuthority(const Tizen::Base::String& str, Tizen::Base::String& user, Tizen::Base::String& host, int& port);
777
778         //
779         // Parses an IPv4 address.
780         //
781         result ParseIpv4(const Tizen::Base::String& str, int index, int& count);
782
783         //
784         // Parses an IPv6 address.
785         // It will be implemented.
786         //
787         result ParseIpv6(const Tizen::Base::String& ip6, Tizen::Base::String& outIpv6);
788
789         //
790         // Parses a host name and returns a host name as an out-param.
791         //
792         result ParseHostName(const Tizen::Base::String& str, int index, Tizen::Base::String& host);
793
794         //
795         // These methods verify components.
796         // If a given component is valid, return @c true, else, @c false.
797         // @param[in]   str             A component
798         //
799         bool VerifyScheme(const Tizen::Base::String& str) const;
800         bool VerifyAuthority(const Tizen::Base::String& str) const;
801         bool VerifyHost(const Tizen::Base::String& str) const;
802         bool VerifyPath(const Tizen::Base::String& str) const;
803         bool VerifyUserInfo(const Tizen::Base::String& str) const;
804         bool VerifyUriChar(const Tizen::Base::String& str) const;
805
806         //
807         // Checks that a given string only consists of server_based characters.
808         // @return              @c true if a string consists of only server_based characters, @n
809         //                      else @c false
810         //
811         bool VerifyServerAuthority(const Tizen::Base::String& str) const;
812
813         //
814         //  Checks that a given string only consists of registry_based characters.
815         // @return              @c true if a string consists of only registry_based characters, @n
816         //                              else @c false
817         //
818         bool VerifyRegistryAuthority(const Tizen::Base::String& str) const;
819
820         //
821         // Checks whether a given char is a user-info character or not.
822         // user-info char: alphabet, digit, -_.!~*'(), ;:&=+$,
823         //
824         bool IsUserInfo(wchar_t mch) const;
825
826         //
827         // Returns true if a given wchar_t is a mark character.
828         // mark char : -_.!~*'()
829         //
830         bool IsMark(wchar_t mch) const;
831
832         //
833         // Returns true if two given wchar_ts are hexadecimals.
834         //
835         bool IsEscapedChar(wchar_t ch1, wchar_t ch2) const;
836
837         //
838         // Returns true if a given string is already encoded.
839         //
840         bool IsEncoded(const Tizen::Base::String& str) const;
841
842         //
843         // Returns true if a given wchar_t is an ISO control character.
844         //
845         bool IsControlChar(wchar_t ch) const;
846
847         //
848         // Compares @c pStr1 with @c pStr2. @n
849         // If @c pStr1 is greater than @c pStr2, returns @c 1.
850         // If two strings are the same, return @c 0.
851         // If @c pStr1 is less than @c pStr2, returns @c -1.
852         //
853         int Compare(const Tizen::Base::String& pStr1, const Tizen::Base::String& pStr2) const;
854
855         //
856         // Adds leading dots.
857         // If the normalized path is relative, and if the first segment could be parsed as a scheme name,
858         // then prepend a '.' segment
859         //
860         void AddLeadingDot(Tizen::Base::WcharBuffer& path, int* segments, int numSegments);
861
862         //
863         // Finds the first character in stopString.
864         // If there is not a character in stopString, the last index is returned.
865         //
866         int Scan(const Tizen::Base::String& str, int start, const Tizen::Base::String& stopString);
867
868         //
869         // Normalizes a given string and removes unnecessary dots.
870         //
871         Tizen::Base::String InternalNormalize(const Tizen::Base::String& path);
872
873         //
874         // Returns the number of segments from a given path.
875         //
876         int GetNumberOfSegments(const Tizen::Base::String& path) const;
877
878         // Join the segments in the given path according to the given segment-index array,
879         // ignoring those segments whose index entries have been set to @c -1, and inserting slashes as needed.
880         // Return the length of the resulting path.
881         //
882         // Preconditions:
883         //   segs[i] == @c -1 implies segment i is to be ignored
884         //   path computed by split, as above, with '\0' having replaced '/'
885         //
886         // Postconditions:
887         //  path[0] .. path[return value] == Resulting path
888         //
889         int Join(Tizen::Base::WcharBuffer& path, int* segments, int segCount);
890
891         //
892         // Removes unnecessary dots and segment pairs consisting of a non-".." segment
893         // followed by a ".." segment
894         //
895         void RemoveDots(const Tizen::Base::WcharBuffer& mb, int* segments, int segCount, int length);
896
897         //
898         // Splits a path component into segments.
899         //
900         void SplitIntoSegments(Tizen::Base::WcharBuffer& mb, int* segments, int segCount);
901
902         //
903         // Implements Uri resolution in RFC2396 5.2
904         //
905         result Resolve(const Uri& baseUri, const Uri& childUri, Uri& resultUri);
906
907         //
908         // Resolves the path of the base and child URI.
909         //
910         Tizen::Base::String ResolvePath(const Tizen::Base::String& path, const Tizen::Base::String& resolve, bool isAbsolute);
911
912         bool EqualsComponent(const Tizen::Base::String& comp1, const Tizen::Base::String& comp2);
913         result Relativize(const Uri& baseUri, const Uri& childUri, Uri& resultUri);
914
915         //
916         // Converts a component represented by UTF8 to a component represented by Unicode.
917         //
918         Tizen::Base::String Decode(const Tizen::Base::String& str);
919
920         //
921         // Converts a component represented by Unicode to a component represented by UTF8.
922         //
923         Tizen::Base::String Encode(const Tizen::Base::String& str) const;
924
925         static result AppendEscape(Tizen::Base::String& strbuf, byte b);
926
927         //
928         // Clears the current instance.
929         //
930         void Clear(void);
931
932         // Component
933         Tizen::Base::String __scheme;
934         Tizen::Base::String __ssp;
935         Tizen::Base::String __authority;
936         Tizen::Base::String __host;
937         Tizen::Base::String __fragment;
938         Tizen::Base::String __path;
939         Tizen::Base::String __userInfo;
940         Tizen::Base::String __query;
941         Tizen::Base::String __ipv4;
942         Tizen::Base::String __ipv6;
943
944         // Encoded Component
945         Tizen::Base::String __encodedAuth;
946         Tizen::Base::String __encodedFragment;
947         Tizen::Base::String __encodedPath;
948         Tizen::Base::String __encodedQuery;
949         Tizen::Base::String __encodedSsp;
950         Tizen::Base::String __encodedUserInfo;
951
952         int __port;
953         bool __hasScheme;
954         int __ipv6ByteCount;
955
956         friend class _UriImpl;
957         class _UriImpl* __pUriImpl;
958
959 }; // Uri
960
961 }}} // Tizen::Base::Utility
962
963 #endif //_FBASE_UTIL_URI_H_