Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / inc / urihelper.hxx
blobea317b90a44cce2ea2451d960630dbce7f45f0bb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #ifndef INCLUDED_URIHELPER_HXX
30 #define INCLUDED_URIHELPER_HXX
32 #include "rtl/ustring.hxx"
33 #include "rtl/ustrbuf.hxx"
34 #include "rtl/uri.hxx"
36 //=========================================================================
38 namespace ucb_impl { namespace urihelper {
40 inline ::rtl::OUString encodeSegment( const ::rtl::OUString & rSegment )
42 return rtl::Uri::encode( rSegment,
43 rtl_UriCharClassPchar,
44 rtl_UriEncodeIgnoreEscapes,
45 RTL_TEXTENCODING_UTF8 );
48 inline ::rtl::OUString decodeSegment( const rtl::OUString& rSegment )
50 return rtl::Uri::decode( rSegment,
51 rtl_UriDecodeWithCharset,
52 RTL_TEXTENCODING_UTF8 );
55 inline ::rtl::OUString encodeURI( const ::rtl::OUString & rURI )
57 rtl::OUString aFragment;
58 rtl::OUString aParams;
59 rtl::OUString aURI;
61 sal_Int32 nFragment = rURI.lastIndexOf( sal_Unicode( '#' ) );
62 if ( nFragment != -1 )
63 aFragment = rURI.copy( nFragment + 1 );
65 sal_Int32 nParams = ( nFragment == -1 )
66 ? rURI.lastIndexOf( sal_Unicode( '?' ) )
67 : rURI.lastIndexOf( sal_Unicode( '?' ), nFragment );
68 if ( nParams != -1 )
69 aParams = ( nFragment == -1 )
70 ? rURI.copy( nParams + 1 )
71 : rURI.copy( nParams + 1, nFragment - nParams - 1 );
73 aURI = ( nParams != -1 )
74 ? rURI.copy( 0, nParams )
75 : ( nFragment != -1 )
76 ? rURI.copy( 0, nFragment )
77 : rURI;
79 if ( aFragment.getLength() > 1 )
80 aFragment =
81 rtl::Uri::encode( aFragment,
82 rtl_UriCharClassUric,
83 rtl_UriEncodeKeepEscapes, /* #i81690# */
84 RTL_TEXTENCODING_UTF8 );
86 if ( aParams.getLength() > 1 )
87 aParams =
88 rtl::Uri::encode( aParams,
89 rtl_UriCharClassUric,
90 rtl_UriEncodeKeepEscapes, /* #i81690# */
91 RTL_TEXTENCODING_UTF8 );
93 rtl::OUStringBuffer aResult;
94 sal_Int32 nIndex = 0;
97 aResult.append(
98 rtl::Uri::encode( aURI.getToken( 0, '/', nIndex ),
99 rtl_UriCharClassPchar,
100 rtl_UriEncodeKeepEscapes, /* #i81690# */
101 RTL_TEXTENCODING_UTF8 ) );
102 if ( nIndex >= 0 )
103 aResult.append( sal_Unicode( '/' ) );
105 while ( nIndex >= 0 );
107 if ( !aParams.isEmpty() )
109 aResult.append( sal_Unicode( '?' ) );
110 aResult.append( aParams );
113 if ( !aFragment.isEmpty() )
115 aResult.append( sal_Unicode( '#' ) );
116 aResult.append( aFragment );
119 return aResult.makeStringAndClear();
122 } } // namespace
124 #endif /* !INCLUDED_URIHELPER_HXX */
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */