LCOV - code coverage report
Current view: top level - ucb/source/ucp/inc - urihelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 37 70.3 %
Date: 2015-06-13 12:38:46 Functions: 3 3 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_UCB_SOURCE_UCP_INC_URIHELPER_HXX
      21             : #define INCLUDED_UCB_SOURCE_UCP_INC_URIHELPER_HXX
      22             : 
      23             : #include "rtl/ustring.hxx"
      24             : #include "rtl/ustrbuf.hxx"
      25             : #include "rtl/uri.hxx"
      26             : 
      27             : 
      28             : 
      29             : namespace ucb_impl { namespace urihelper {
      30             : 
      31           8 :     inline OUString encodeSegment( const OUString & rSegment )
      32             :     {
      33             :         return rtl::Uri::encode( rSegment,
      34             :                                  rtl_UriCharClassPchar,
      35             :                                  rtl_UriEncodeIgnoreEscapes,
      36           8 :                                  RTL_TEXTENCODING_UTF8 );
      37             :     }
      38             : 
      39        2470 :     inline OUString decodeSegment( const OUString& rSegment )
      40             :     {
      41             :         return rtl::Uri::decode( rSegment,
      42             :                                  rtl_UriDecodeWithCharset,
      43        2470 :                                  RTL_TEXTENCODING_UTF8 );
      44             :     }
      45             : 
      46          30 :     inline OUString encodeURI( const OUString & rURI )
      47             :     {
      48          30 :         OUString aFragment;
      49          60 :         OUString aParams;
      50          60 :         OUString aURI;
      51             : 
      52          30 :         sal_Int32 nFragment = rURI.lastIndexOf( sal_Unicode( '#' ) );
      53          30 :         if ( nFragment != -1 )
      54           0 :             aFragment = rURI.copy( nFragment + 1 );
      55             : 
      56             :         sal_Int32 nParams = ( nFragment == -1 )
      57             :             ? rURI.lastIndexOf( sal_Unicode( '?' ) )
      58          30 :             : rURI.lastIndexOf( sal_Unicode( '?' ), nFragment );
      59          30 :         if ( nParams != -1 )
      60           0 :             aParams = ( nFragment == -1 )
      61             :                 ? rURI.copy( nParams + 1 )
      62           0 :                 : rURI.copy( nParams + 1, nFragment - nParams - 1 );
      63             : 
      64          60 :         aURI = ( nParams != -1 )
      65             :             ? rURI.copy( 0, nParams )
      66             :             : ( nFragment != -1 )
      67             :                   ? rURI.copy( 0, nFragment )
      68          30 :                   : rURI;
      69             : 
      70          30 :         if ( aFragment.getLength() > 1 )
      71           0 :             aFragment =
      72             :                 rtl::Uri::encode( aFragment,
      73             :                                   rtl_UriCharClassUric,
      74             :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
      75           0 :                                   RTL_TEXTENCODING_UTF8 );
      76             : 
      77          30 :         if ( aParams.getLength() > 1 )
      78           0 :             aParams =
      79             :                 rtl::Uri::encode( aParams,
      80             :                                   rtl_UriCharClassUric,
      81             :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
      82           0 :                                   RTL_TEXTENCODING_UTF8 );
      83             : 
      84          60 :         OUStringBuffer aResult;
      85          30 :         sal_Int32 nIndex = 0;
      86          45 :         do
      87             :         {
      88             :             aResult.append(
      89             :                 rtl::Uri::encode( aURI.getToken( 0, '/', nIndex ),
      90             :                                   rtl_UriCharClassPchar,
      91             :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
      92          45 :                                   RTL_TEXTENCODING_UTF8 ) );
      93          45 :             if ( nIndex >= 0 )
      94          15 :                 aResult.append( sal_Unicode( '/' ) );
      95             :         }
      96          45 :         while ( nIndex >= 0 );
      97             : 
      98          30 :         if ( !aParams.isEmpty() )
      99             :         {
     100           0 :             aResult.append( sal_Unicode( '?' ) );
     101           0 :             aResult.append( aParams );
     102             :         }
     103             : 
     104          30 :         if ( !aFragment.isEmpty() )
     105             :         {
     106           0 :             aResult.append( sal_Unicode( '#' ) );
     107           0 :             aResult.append( aFragment );
     108             :         }
     109             : 
     110          60 :         return aResult.makeStringAndClear();
     111             :     }
     112             : 
     113             : } } // namespace
     114             : 
     115             : #endif // INCLUDED_UCB_SOURCE_UCP_INC_URIHELPER_HXX
     116             : 
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11