1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_UCB_SOURCE_UCP_INC_URIHELPER_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_INC_URIHELPER_HXX
23 #include "rtl/ustring.hxx"
24 #include "rtl/ustrbuf.hxx"
25 #include "rtl/uri.hxx"
29 namespace ucb_impl
{ namespace urihelper
{
31 inline OUString
encodeSegment( const OUString
& rSegment
)
33 return rtl::Uri::encode( rSegment
,
34 rtl_UriCharClassPchar
,
35 rtl_UriEncodeIgnoreEscapes
,
36 RTL_TEXTENCODING_UTF8
);
39 inline OUString
decodeSegment( const OUString
& rSegment
)
41 return rtl::Uri::decode( rSegment
,
42 rtl_UriDecodeWithCharset
,
43 RTL_TEXTENCODING_UTF8
);
46 inline OUString
encodeURI( const OUString
& rURI
)
52 sal_Int32 nFragment
= rURI
.lastIndexOf( sal_Unicode( '#' ) );
53 if ( nFragment
!= -1 )
54 aFragment
= rURI
.copy( nFragment
+ 1 );
56 sal_Int32 nParams
= ( nFragment
== -1 )
57 ? rURI
.lastIndexOf( sal_Unicode( '?' ) )
58 : rURI
.lastIndexOf( sal_Unicode( '?' ), nFragment
);
60 aParams
= ( nFragment
== -1 )
61 ? rURI
.copy( nParams
+ 1 )
62 : rURI
.copy( nParams
+ 1, nFragment
- nParams
- 1 );
64 aURI
= ( nParams
!= -1 )
65 ? rURI
.copy( 0, nParams
)
67 ? rURI
.copy( 0, nFragment
)
70 if ( aFragment
.getLength() > 1 )
72 rtl::Uri::encode( aFragment
,
74 rtl_UriEncodeKeepEscapes
, /* #i81690# */
75 RTL_TEXTENCODING_UTF8
);
77 if ( aParams
.getLength() > 1 )
79 rtl::Uri::encode( aParams
,
81 rtl_UriEncodeKeepEscapes
, /* #i81690# */
82 RTL_TEXTENCODING_UTF8
);
84 OUStringBuffer aResult
;
89 rtl::Uri::encode( aURI
.getToken( 0, '/', nIndex
),
90 rtl_UriCharClassPchar
,
91 rtl_UriEncodeKeepEscapes
, /* #i81690# */
92 RTL_TEXTENCODING_UTF8
) );
94 aResult
.append( sal_Unicode( '/' ) );
96 while ( nIndex
>= 0 );
98 if ( !aParams
.isEmpty() )
100 aResult
.append( sal_Unicode( '?' ) );
101 aResult
.append( aParams
);
104 if ( !aFragment
.isEmpty() )
106 aResult
.append( sal_Unicode( '#' ) );
107 aResult
.append( aFragment
);
110 return aResult
.makeStringAndClear();
115 #endif // INCLUDED_UCB_SOURCE_UCP_INC_URIHELPER_HXX
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */