LCOV - code coverage report
Current view: top level - include/rtl - uri.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 19 19 100.0 %
Date: 2014-11-03 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_RTL_URI_HXX
      21             : #define INCLUDED_RTL_URI_HXX
      22             : 
      23             : #include <rtl/malformeduriexception.hxx>
      24             : #include <rtl/uri.h>
      25             : #include <rtl/textenc.h>
      26             : #include <rtl/ustring.hxx>
      27             : #include <sal/types.h>
      28             : 
      29             : namespace rtl {
      30             : 
      31             : /** A wrapper around the C functions from <rtl/uri.h>.
      32             :  */
      33             : class Uri
      34             : {
      35             : public:
      36             :     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
      37             :         an array of 128 booleans as char class.
      38             :      */
      39             :     static inline rtl::OUString encode(rtl::OUString const & rText,
      40             :                                        sal_Bool const * pCharClass,
      41             :                                        rtl_UriEncodeMechanism eMechanism,
      42             :                                        rtl_TextEncoding eCharset);
      43             : 
      44             :     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
      45             :         a predefined rtl_UriCharClass enumeration member.
      46             :      */
      47             :     static inline rtl::OUString encode(rtl::OUString const & rText,
      48             :                                        rtl_UriCharClass eCharClass,
      49             :                                        rtl_UriEncodeMechanism eMechanism,
      50             :                                        rtl_TextEncoding eCharset);
      51             : 
      52             :     /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there).
      53             :      */
      54             :     static inline rtl::OUString decode(rtl::OUString const & rText,
      55             :                                        rtl_UriDecodeMechanism eMechanism,
      56             :                                        rtl_TextEncoding eCharset);
      57             : 
      58             :     /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there).
      59             : 
      60             :         @exception MalformedUriException
      61             :         Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a
      62             :         malformed base URI.
      63             :      */
      64             :     static inline rtl::OUString convertRelToAbs(
      65             :         rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef);
      66             : 
      67             : private:
      68             :     /** not implemented */
      69             :     Uri();
      70             : 
      71             :     /** not implemented */
      72             :     Uri(Uri &);
      73             : 
      74             :     /** not implemented */
      75             :     ~Uri();
      76             : 
      77             :     /** not implemented */
      78             :     void operator =(Uri);
      79             : };
      80             : 
      81           2 : inline rtl::OUString Uri::encode(rtl::OUString const & rText,
      82             :                                  sal_Bool const * pCharClass,
      83             :                                  rtl_UriEncodeMechanism eMechanism,
      84             :                                  rtl_TextEncoding eCharset)
      85             : {
      86           2 :     rtl::OUString aResult;
      87             :     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
      88             :                   pCharClass,
      89             :                   eMechanism,
      90             :                   eCharset,
      91           2 :                   &aResult.pData);
      92           2 :     return aResult;
      93             : }
      94             : 
      95       25438 : inline rtl::OUString Uri::encode(rtl::OUString const & rText,
      96             :                                  rtl_UriCharClass eCharClass,
      97             :                                  rtl_UriEncodeMechanism eMechanism,
      98             :                                  rtl_TextEncoding eCharset)
      99             : {
     100       25438 :     rtl::OUString aResult;
     101             :     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
     102             :                   rtl_getUriCharClass(eCharClass),
     103             :                   eMechanism,
     104             :                   eCharset,
     105       25438 :                   &aResult.pData);
     106       25438 :     return aResult;
     107             : }
     108             : 
     109      142575 : inline rtl::OUString Uri::decode(rtl::OUString const & rText,
     110             :                                  rtl_UriDecodeMechanism eMechanism,
     111             :                                  rtl_TextEncoding eCharset)
     112             : {
     113      142575 :     rtl::OUString aResult;
     114             :     rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData,
     115             :                   eMechanism,
     116             :                   eCharset,
     117      142575 :                   &aResult.pData);
     118      142575 :     return aResult;
     119             : }
     120             : 
     121      121186 : inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef,
     122             :                                           rtl::OUString const & rRelUriRef)
     123             : {
     124      121186 :     rtl::OUString aResult;
     125      242372 :     rtl::OUString aException;
     126      121186 :     if (!rtl_uriConvertRelToAbs(
     127             :             const_cast< rtl::OUString & >(rBaseUriRef).pData,
     128             :             const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData,
     129      121186 :             &aException.pData))
     130           2 :         throw MalformedUriException(aException);
     131      242368 :     return aResult;
     132             : }
     133             : 
     134             : }
     135             : 
     136             : #endif // INCLUDED_RTL_URI_HXX
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10