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