1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: uri.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include "rtl/malformeduriexception.hxx"
36 #include "rtl/textenc.h"
37 #include "rtl/ustring.hxx"
38 #include "sal/types.h"
42 /** A wrapper around the C functions from <rtl/uri.h>.
47 /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
48 an array of 128 booleans as char class.
50 static inline rtl::OUString
encode(rtl::OUString
const & rText
,
51 sal_Bool
const * pCharClass
,
52 rtl_UriEncodeMechanism eMechanism
,
53 rtl_TextEncoding eCharset
)
56 /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
57 a predefined rtl_UriCharClass enumeration member.
59 static inline rtl::OUString
encode(rtl::OUString
const & rText
,
60 rtl_UriCharClass eCharClass
,
61 rtl_UriEncodeMechanism eMechanism
,
62 rtl_TextEncoding eCharset
)
65 /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there).
67 static inline rtl::OUString
decode(rtl::OUString
const & rText
,
68 rtl_UriDecodeMechanism eMechanism
,
69 rtl_TextEncoding eCharset
)
72 /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there).
74 @exception MalformedUriException
75 Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a
78 static inline rtl::OUString
convertRelToAbs(
79 rtl::OUString
const & rBaseUriRef
, rtl::OUString
const & rRelUriRef
);
99 inline rtl::OUString
Uri::encode(rtl::OUString
const & rText
,
100 sal_Bool
const * pCharClass
,
101 rtl_UriEncodeMechanism eMechanism
,
102 rtl_TextEncoding eCharset
)
105 rtl::OUString aResult
;
106 rtl_uriEncode(const_cast< rtl::OUString
& >(rText
).pData
,
114 inline rtl::OUString
Uri::encode(rtl::OUString
const & rText
,
115 rtl_UriCharClass eCharClass
,
116 rtl_UriEncodeMechanism eMechanism
,
117 rtl_TextEncoding eCharset
)
120 rtl::OUString aResult
;
121 rtl_uriEncode(const_cast< rtl::OUString
& >(rText
).pData
,
122 rtl_getUriCharClass(eCharClass
),
129 inline rtl::OUString
Uri::decode(rtl::OUString
const & rText
,
130 rtl_UriDecodeMechanism eMechanism
,
131 rtl_TextEncoding eCharset
)
134 rtl::OUString aResult
;
135 rtl_uriDecode(const_cast< rtl::OUString
& >(rText
).pData
,
142 inline rtl::OUString
Uri::convertRelToAbs(rtl::OUString
const & rBaseUriRef
,
143 rtl::OUString
const & rRelUriRef
)
145 rtl::OUString aResult
;
146 rtl::OUString aException
;
147 if (!rtl_uriConvertRelToAbs(
148 const_cast< rtl::OUString
& >(rBaseUriRef
).pData
,
149 const_cast< rtl::OUString
& >(rRelUriRef
).pData
, &aResult
.pData
,
151 throw MalformedUriException(aException
);
157 #endif // _RTL_URI_HXX_