LCOV - code coverage report
Current view: top level - include/rtl - uri.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 10 19 52.6 %
Date: 2014-04-14 Functions: 2 4 50.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             :         SAL_THROW(());
      44             : 
      45             :     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
      46             :         a predefined rtl_UriCharClass enumeration member.
      47             :      */
      48             :     static inline rtl::OUString encode(rtl::OUString const & rText,
      49             :                                        rtl_UriCharClass eCharClass,
      50             :                                        rtl_UriEncodeMechanism eMechanism,
      51             :                                        rtl_TextEncoding eCharset)
      52             :         SAL_THROW(());
      53             : 
      54             :     /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there).
      55             :      */
      56             :     static inline rtl::OUString decode(rtl::OUString const & rText,
      57             :                                        rtl_UriDecodeMechanism eMechanism,
      58             :                                        rtl_TextEncoding eCharset)
      59             :         SAL_THROW(());
      60             : 
      61             :     /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there).
      62             : 
      63             :         @exception MalformedUriException
      64             :         Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a
      65             :         malformed base URI.
      66             :      */
      67             :     static inline rtl::OUString convertRelToAbs(
      68             :         rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef);
      69             : 
      70             : private:
      71             :     /** not implemented */
      72             :     Uri();
      73             : 
      74             :     /** not implemented */
      75             :     Uri(Uri &);
      76             : 
      77             :     /** not implemented */
      78             :     ~Uri();
      79             : 
      80             :     /** not implemented */
      81             :     void operator =(Uri);
      82             : };
      83             : 
      84           0 : inline rtl::OUString Uri::encode(rtl::OUString const & rText,
      85             :                                  sal_Bool const * pCharClass,
      86             :                                  rtl_UriEncodeMechanism eMechanism,
      87             :                                  rtl_TextEncoding eCharset)
      88             :     SAL_THROW(())
      89             : {
      90           0 :     rtl::OUString aResult;
      91             :     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
      92             :                   pCharClass,
      93             :                   eMechanism,
      94             :                   eCharset,
      95           0 :                   &aResult.pData);
      96           0 :     return aResult;
      97             : }
      98             : 
      99           0 : inline rtl::OUString Uri::encode(rtl::OUString const & rText,
     100             :                                  rtl_UriCharClass eCharClass,
     101             :                                  rtl_UriEncodeMechanism eMechanism,
     102             :                                  rtl_TextEncoding eCharset)
     103             :     SAL_THROW(())
     104             : {
     105           0 :     rtl::OUString aResult;
     106             :     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
     107             :                   rtl_getUriCharClass(eCharClass),
     108             :                   eMechanism,
     109             :                   eCharset,
     110           0 :                   &aResult.pData);
     111           0 :     return aResult;
     112             : }
     113             : 
     114       42514 : inline rtl::OUString Uri::decode(rtl::OUString const & rText,
     115             :                                  rtl_UriDecodeMechanism eMechanism,
     116             :                                  rtl_TextEncoding eCharset)
     117             :     SAL_THROW(())
     118             : {
     119       42514 :     rtl::OUString aResult;
     120             :     rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData,
     121             :                   eMechanism,
     122             :                   eCharset,
     123       42514 :                   &aResult.pData);
     124       42514 :     return aResult;
     125             : }
     126             : 
     127       42716 : inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef,
     128             :                                           rtl::OUString const & rRelUriRef)
     129             : {
     130       42716 :     rtl::OUString aResult;
     131       85432 :     rtl::OUString aException;
     132       42716 :     if (!rtl_uriConvertRelToAbs(
     133             :             const_cast< rtl::OUString & >(rBaseUriRef).pData,
     134             :             const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData,
     135       42716 :             &aException.pData))
     136           0 :         throw MalformedUriException(aException);
     137       85432 :     return aResult;
     138             : }
     139             : 
     140             : }
     141             : 
     142             : #endif // INCLUDED_RTL_URI_HXX
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10