LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / include / rtl / uri.hxx
blob0ab1726dab996217ab5ed236124876947dde6805
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_RTL_URI_HXX
25 #define INCLUDED_RTL_URI_HXX
27 #include "rtl/malformeduriexception.hxx"
28 #include "rtl/uri.h"
29 #include "rtl/textenc.h"
30 #include "rtl/ustring.hxx"
31 #include "sal/types.h"
33 namespace rtl {
35 /** A wrapper around the C functions from <rtl/uri.h>.
37 class Uri
39 public:
40 /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
41 an array of 128 booleans as char class.
43 static inline rtl::OUString encode(rtl::OUString const & rText,
44 sal_Bool const * pCharClass,
45 rtl_UriEncodeMechanism eMechanism,
46 rtl_TextEncoding eCharset);
48 /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
49 a predefined rtl_UriCharClass enumeration member.
51 static inline rtl::OUString encode(rtl::OUString const & rText,
52 rtl_UriCharClass eCharClass,
53 rtl_UriEncodeMechanism eMechanism,
54 rtl_TextEncoding eCharset);
56 /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there).
58 static inline rtl::OUString decode(rtl::OUString const & rText,
59 rtl_UriDecodeMechanism eMechanism,
60 rtl_TextEncoding eCharset);
62 /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there).
64 @exception MalformedUriException
65 Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a
66 malformed base URI.
68 static inline rtl::OUString convertRelToAbs(
69 rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef);
71 private:
72 Uri() SAL_DELETED_FUNCTION;
74 Uri(Uri &) SAL_DELETED_FUNCTION;
76 ~Uri() SAL_DELETED_FUNCTION;
78 void operator =(Uri) SAL_DELETED_FUNCTION;
81 inline rtl::OUString Uri::encode(rtl::OUString const & rText,
82 sal_Bool const * pCharClass,
83 rtl_UriEncodeMechanism eMechanism,
84 rtl_TextEncoding eCharset)
86 rtl::OUString aResult;
87 rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
88 pCharClass,
89 eMechanism,
90 eCharset,
91 &aResult.pData);
92 return aResult;
95 inline rtl::OUString Uri::encode(rtl::OUString const & rText,
96 rtl_UriCharClass eCharClass,
97 rtl_UriEncodeMechanism eMechanism,
98 rtl_TextEncoding eCharset)
100 rtl::OUString aResult;
101 rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
102 rtl_getUriCharClass(eCharClass),
103 eMechanism,
104 eCharset,
105 &aResult.pData);
106 return aResult;
109 inline rtl::OUString Uri::decode(rtl::OUString const & rText,
110 rtl_UriDecodeMechanism eMechanism,
111 rtl_TextEncoding eCharset)
113 rtl::OUString aResult;
114 rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData,
115 eMechanism,
116 eCharset,
117 &aResult.pData);
118 return aResult;
121 inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef,
122 rtl::OUString const & rRelUriRef)
124 rtl::OUString aResult;
125 rtl::OUString aException;
126 if (!rtl_uriConvertRelToAbs(
127 const_cast< rtl::OUString & >(rBaseUriRef).pData,
128 const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData,
129 &aException.pData))
130 throw MalformedUriException(aException);
131 return aResult;
136 #endif // INCLUDED_RTL_URI_HXX
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */