LCOV - code coverage report
Current view: top level - ucb/source/ucp/inc - urihelper.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 37 0.0 %
Date: 2014-04-14 Functions: 0 3 0.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_URIHELPER_HXX
      21             : #define INCLUDED_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           0 :     inline OUString encodeSegment( const OUString & rSegment )
      32             :     {
      33             :         return rtl::Uri::encode( rSegment,
      34             :                                  rtl_UriCharClassPchar,
      35             :                                  rtl_UriEncodeIgnoreEscapes,
      36           0 :                                  RTL_TEXTENCODING_UTF8 );
      37             :     }
      38             : 
      39           0 :     inline OUString decodeSegment( const OUString& rSegment )
      40             :     {
      41             :         return rtl::Uri::decode( rSegment,
      42             :                                  rtl_UriDecodeWithCharset,
      43           0 :                                  RTL_TEXTENCODING_UTF8 );
      44             :     }
      45             : 
      46           0 :     inline OUString encodeURI( const OUString & rURI )
      47             :     {
      48           0 :         OUString aFragment;
      49           0 :         OUString aParams;
      50           0 :         OUString aURI;
      51             : 
      52           0 :         sal_Int32 nFragment = rURI.lastIndexOf( sal_Unicode( '#' ) );
      53           0 :         if ( nFragment != -1 )
      54           0 :             aFragment = rURI.copy( nFragment + 1 );
      55             : 
      56             :         sal_Int32 nParams = ( nFragment == -1 )
      57             :             ? rURI.lastIndexOf( sal_Unicode( '?' ) )
      58           0 :             : rURI.lastIndexOf( sal_Unicode( '?' ), nFragment );
      59           0 :         if ( nParams != -1 )
      60           0 :             aParams = ( nFragment == -1 )
      61             :                 ? rURI.copy( nParams + 1 )
      62           0 :                 : rURI.copy( nParams + 1, nFragment - nParams - 1 );
      63             : 
      64           0 :         aURI = ( nParams != -1 )
      65             :             ? rURI.copy( 0, nParams )
      66             :             : ( nFragment != -1 )
      67             :                   ? rURI.copy( 0, nFragment )
      68           0 :                   : rURI;
      69             : 
      70           0 :         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           0 :         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           0 :         OUStringBuffer aResult;
      85           0 :         sal_Int32 nIndex = 0;
      86           0 :         do
      87             :         {
      88             :             aResult.append(
      89             :                 rtl::Uri::encode( aURI.getToken( 0, '/', nIndex ),
      90             :                                   rtl_UriCharClassPchar,
      91             :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
      92           0 :                                   RTL_TEXTENCODING_UTF8 ) );
      93           0 :             if ( nIndex >= 0 )
      94           0 :                 aResult.append( sal_Unicode( '/' ) );
      95             :         }
      96           0 :         while ( nIndex >= 0 );
      97             : 
      98           0 :         if ( !aParams.isEmpty() )
      99             :         {
     100           0 :             aResult.append( sal_Unicode( '?' ) );
     101           0 :             aResult.append( aParams );
     102             :         }
     103             : 
     104           0 :         if ( !aFragment.isEmpty() )
     105             :         {
     106           0 :             aResult.append( sal_Unicode( '#' ) );
     107           0 :             aResult.append( aFragment );
     108             :         }
     109             : 
     110           0 :         return aResult.makeStringAndClear();
     111             :     }
     112             : 
     113             : } } // namespace
     114             : 
     115             : #endif /* !INCLUDED_URIHELPER_HXX */
     116             : 
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10