LCOV - code coverage report
Current view: top level - ucb/source/ucp/inc - urihelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 32 75.0 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 38 42.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef INCLUDED_URIHELPER_HXX
      30                 :            : #define INCLUDED_URIHELPER_HXX
      31                 :            : 
      32                 :            : #include "rtl/ustring.hxx"
      33                 :            : #include "rtl/ustrbuf.hxx"
      34                 :            : #include "rtl/uri.hxx"
      35                 :            : 
      36                 :            : //=========================================================================
      37                 :            : 
      38                 :            : namespace ucb_impl { namespace urihelper {
      39                 :            : 
      40                 :        196 :     inline ::rtl::OUString encodeSegment( const ::rtl::OUString & rSegment )
      41                 :            :     {
      42                 :            :         return rtl::Uri::encode( rSegment,
      43                 :            :                                  rtl_UriCharClassPchar,
      44                 :            :                                  rtl_UriEncodeIgnoreEscapes,
      45                 :        196 :                                  RTL_TEXTENCODING_UTF8 );
      46                 :            :     }
      47                 :            : 
      48                 :       2788 :     inline ::rtl::OUString decodeSegment( const rtl::OUString& rSegment )
      49                 :            :     {
      50                 :            :         return rtl::Uri::decode( rSegment,
      51                 :            :                                  rtl_UriDecodeWithCharset,
      52                 :       2788 :                                  RTL_TEXTENCODING_UTF8 );
      53                 :            :     }
      54                 :            : 
      55                 :        500 :     inline ::rtl::OUString encodeURI( const ::rtl::OUString & rURI )
      56                 :            :     {
      57                 :        500 :         rtl::OUString aFragment;
      58                 :        500 :         rtl::OUString aParams;
      59                 :        500 :         rtl::OUString aURI;
      60                 :            : 
      61                 :        500 :         sal_Int32 nFragment = rURI.lastIndexOf( sal_Unicode( '#' ) );
      62         [ -  + ]:        500 :         if ( nFragment != -1 )
      63                 :          0 :             aFragment = rURI.copy( nFragment + 1 );
      64                 :            : 
      65                 :            :         sal_Int32 nParams = ( nFragment == -1 )
      66                 :            :             ? rURI.lastIndexOf( sal_Unicode( '?' ) )
      67         [ +  - ]:        500 :             : rURI.lastIndexOf( sal_Unicode( '?' ), nFragment );
      68         [ -  + ]:        500 :         if ( nParams != -1 )
      69                 :            :             aParams = ( nFragment == -1 )
      70                 :            :                 ? rURI.copy( nParams + 1 )
      71         [ #  # ]:          0 :                 : rURI.copy( nParams + 1, nFragment - nParams - 1 );
      72                 :            : 
      73                 :            :         aURI = ( nParams != -1 )
      74                 :            :             ? rURI.copy( 0, nParams )
      75                 :            :             : ( nFragment != -1 )
      76                 :            :                   ? rURI.copy( 0, nFragment )
      77 [ -  + ][ -  + ]:        500 :                   : rURI;
      78                 :            : 
      79         [ -  + ]:        500 :         if ( aFragment.getLength() > 1 )
      80                 :            :             aFragment =
      81                 :            :                 rtl::Uri::encode( aFragment,
      82                 :            :                                   rtl_UriCharClassUric,
      83                 :            :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
      84                 :          0 :                                   RTL_TEXTENCODING_UTF8 );
      85                 :            : 
      86         [ -  + ]:        500 :         if ( aParams.getLength() > 1 )
      87                 :            :             aParams =
      88                 :            :                 rtl::Uri::encode( aParams,
      89                 :            :                                   rtl_UriCharClassUric,
      90                 :            :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
      91                 :          0 :                                   RTL_TEXTENCODING_UTF8 );
      92                 :            : 
      93                 :        500 :         rtl::OUStringBuffer aResult;
      94                 :        500 :         sal_Int32 nIndex = 0;
      95         [ +  + ]:       1074 :         do
      96                 :            :         {
      97                 :            :             aResult.append(
      98                 :            :                 rtl::Uri::encode( aURI.getToken( 0, '/', nIndex ),
      99                 :            :                                   rtl_UriCharClassPchar,
     100                 :            :                                   rtl_UriEncodeKeepEscapes, /* #i81690# */
     101         [ +  - ]:       1074 :                                   RTL_TEXTENCODING_UTF8 ) );
     102         [ +  + ]:       1074 :             if ( nIndex >= 0 )
     103         [ +  - ]:        574 :                 aResult.append( sal_Unicode( '/' ) );
     104                 :            :         }
     105                 :            :         while ( nIndex >= 0 );
     106                 :            : 
     107         [ -  + ]:        500 :         if ( !aParams.isEmpty() )
     108                 :            :         {
     109         [ #  # ]:          0 :             aResult.append( sal_Unicode( '?' ) );
     110         [ #  # ]:          0 :             aResult.append( aParams );
     111                 :            :         }
     112                 :            : 
     113         [ -  + ]:        500 :         if ( !aFragment.isEmpty() )
     114                 :            :         {
     115         [ #  # ]:          0 :             aResult.append( sal_Unicode( '#' ) );
     116         [ #  # ]:          0 :             aResult.append( aFragment );
     117                 :            :         }
     118                 :            : 
     119         [ +  - ]:        500 :         return aResult.makeStringAndClear();
     120                 :            :     }
     121                 :            : 
     122                 :            : } } // namespace
     123                 :            : 
     124                 :            : #endif /* !INCLUDED_URIHELPER_HXX */
     125                 :            : 
     126                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10