xref: /core/include/tools/urlobj.hxx (revision 485300f9)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_TOOLS_URLOBJ_HXX
20 #define INCLUDED_TOOLS_URLOBJ_HXX
21 
22 #include <tools/toolsdllapi.h>
23 #include <rtl/ustrbuf.hxx>
24 #include <rtl/textenc.h>
25 #include <sal/types.h>
26 #include <o3tl/typed_flags_set.hxx>
27 
28 #include <memory>
29 #include <string_view>
30 
31 class SvMemoryStream;
32 
33 namespace com::sun::star::util {
34     class XStringWidth;
35 }
36 
37 namespace com::sun::star::uno { template <typename > class Reference; }
38 
39 // Common URL prefixes for various schemes:
40 inline constexpr OUStringLiteral INET_FTP_SCHEME = u"ftp://";
41 inline constexpr OUStringLiteral INET_HTTP_SCHEME = u"http://";
42 inline constexpr OUStringLiteral INET_HTTPS_SCHEME = u"https://";
43 inline constexpr OUStringLiteral INET_FILE_SCHEME = u"file://";
44 inline constexpr OUStringLiteral INET_MAILTO_SCHEME = u"mailto:";
45 inline constexpr OUStringLiteral INET_HID_SCHEME = u"hid:";
46 
47 #define URL_PREFIX_PRIV_SOFFICE "private:"
48 
49 // Schemes:
50 enum class INetProtocol
51 {
52     NotValid,
53     Ftp,
54     Http,
55     File,
56     Mailto,
57     VndSunStarWebdav,
58     PrivSoffice,
59     VndSunStarHelp,
60     Https,
61     Slot,
62     Macro,
63     Javascript,
64     Data,
65     Cid,
66     VndSunStarHier,
67     Uno,
68     Component,
69     VndSunStarPkg,
70     Ldap,
71     Db,
72     VndSunStarCmd,
73     Telnet,
74     VndSunStarExpand,
75     VndSunStarTdoc,
76     Generic,
77     Smb,
78     Hid,
79     Sftp,
80     Cmis,
81     LAST = Cmis
82 };
83 
84 /** The supported notations for file system paths.
85  */
86 enum class FSysStyle
87 {
88     /** VOS notation (e.g., "//server/dir/file").
89      */
90     Vos = 0x1,
91 
92     /** Unix notation (e.g., "/dir/file").
93      */
94     Unix = 0x2,
95 
96     /** DOS notation (e.g., "a:\dir\file" and "\\server\dir\file").
97      */
98     Dos = 0x4,
99 
100     /** Detect the used notation.
101 
102         @descr  For the following descriptions, please note that
103         whereas FSYS_DEFAULT includes all style bits, combinations of only
104         a few style bits are also possible, and are also described.
105 
106         @descr  When used to translate a file system path to a file URL,
107         the subset of the following productions for which the appropriate
108         style bit is set are checked in order (using the conventions of
109         RFC 2234, RFC 2396, and RFC 2732; UCS4 stands for any UCS4
110         character):
111 
112          Production T1 (VOS local; FSysStyle::Vos only):
113             "//." ["/" *UCS4]
114           becomes
115             "file:///" *UCS4
116 
117          Production T2 (VOS host; FSysStyle::Vos only):
118             "//" [host] ["/" *UCS4]
119           becomes
120             "file://" host "/" *UCS4
121 
122          Production T3 (UNC; FSysStyle::Dos only):
123             "\\" [host] ["\" *UCS4]
124           becomes
125             "file://" host "/" *UCS4
126           replacing "\" by "/" within <*UCS4>
127 
128          Production T4 (Unix-like DOS; FSysStyle::Dos only):
129             ALPHA ":" ["/" *UCS4]
130           becomes
131             "file:///" ALPHA ":/" *UCS4
132           replacing "\" by "/" within <*UCS4>
133 
134          Production T5 (DOS; FSysStyle::Dos only):
135             ALPHA ":" ["\" *UCS4]
136           becomes
137             "file:///" ALPHA ":/" *UCS4
138           replacing "\" by "/" within <*UCS4>
139 
140          Production T6 (any):
141             *UCS4
142           becomes
143             "file:///" *UCS4
144           replacing the delimiter by "/" within <*UCS4>.  The delimiter is
145           that character from the set { "/", "\" } which appears most
146           often in <*UCS4> (if FSysStyle::Unix is not among the style bits, "/"
147           is removed from the set; if FSysStyle::Dos is not among the style
148           bits, "\" is removed from the set).  If two or more
149           characters appear the same number of times, the character
150           mentioned first in that set is chosen.  If the first character
151           of <*UCS4> is the delimiter, that character is not copied.
152 
153         @descr  When used to translate a file URL to a file system path,
154         the following productions are checked in order (using the
155         conventions of RFC 2234, RFC 2396, and RFC 2732):
156 
157          Production F1 (VOS; FSysStyle::Vos):
158             "file://" host "/" fpath ["#" fragment]
159           becomes
160             "//" host "/" fpath
161 
162          Production F2 (DOS; FSysStyle::Dos):
163             "file:///" ALPHA ":" ["/" fpath] ["#" fragment]
164           becomes
165             ALPHA ":" ["\" fpath]
166           replacing "/" by "\" in <fpath>
167 
168          Production F3 (Unix; FSysStyle::Unix):
169             "file:///" fpath ["#" fragment]
170           becomes
171             "/" fpath
172      */
173     Detect = Vos | Unix | Dos
174 };
175 namespace o3tl {
176     template<> struct typed_flags<FSysStyle> : is_typed_flags<FSysStyle, 0x07> {};
177 }
178 
179 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC INetURLObject
180 {
181 public:
182     // Get- and Set-Methods:
183 
184     /** The way input strings that represent (parts of) URIs are interpreted
185         in set-methods.
186 
187         @descr  UTF-32 characters in the range 0x80--0x10FFFF are replaced by
188         sequences of escape sequences, representing the UTF-8 coded characters.
189 
190         @descr  Along with an EncodeMechanism parameter, the set-methods all
191         take an rtl_TextEncoding parameter, which is ignored unless the
192         EncodeMechanism is EncodeMechanism::WasEncoded.
193      */
194     enum class EncodeMechanism
195     {
196         /** All escape sequences that are already present are ignored, and are
197             interpreted as literal sequences of three characters.
198          */
199         All,
200 
201         /** Sequences of escape sequences, that represent characters from the
202             specified character set and that can be converted to UTF-32
203             characters, are first decoded.  If they have to be encoded, they
204             are converted to UTF-8 characters and are than translated into
205             (sequences of) escape sequences. Other escape sequences are
206             copied verbatim (but using upper case hex digits).
207          */
208         WasEncoded,
209 
210         /** All escape sequences that are already present are copied verbatim
211             (but using upper case hex digits).
212          */
213         NotCanonical
214     };
215 
216     /** The way strings that represent (parts of) URIs are returned from get-
217         methods.
218 
219         @descr  Along with a DecodeMechanism parameter, the get-methods all
220         take an rtl_TextEncoding parameter, which is ignored unless the
221         DecodeMechanism is DecodeMechanism::WithCharset or DecodeMechanism::Unambiguous.
222      */
223     enum class DecodeMechanism
224     {
225         /** The (part of the) URI is returned unchanged.  Since URIs are
226             written using a subset of US-ASCII, the returned string is
227             guaranteed to contain only US-ASCII characters.
228          */
229         NONE,
230 
231         /** All sequences of escape sequences that represent UTF-8 coded
232             UTF-32 characters with a numerical value greater than 0x7F, are
233             replaced by the respective UTF-16 characters.  All other escape
234             sequences are not decoded.
235          */
236         ToIUri,
237 
238         /** All (sequences of) escape sequences that represent characters from
239             the specified character set, and that can be converted to UTF-32,
240             are replaced by the respective UTF-16 characters.  All other
241             escape sequences are not decoded.
242          */
243         WithCharset,
244 
245         /** All (sequences of) escape sequences that represent characters from
246             the specified character set, that can be converted to UTF-32, and
247             that (in the case of ASCII characters) can safely be decoded
248             without altering the meaning of the (part of the) URI, are
249             replaced by the respective UTF-16 characters.  All other escape
250             sequences are not decoded.
251          */
252         Unambiguous
253     };
254 
255     // General Structure:
256 
257     INetURLObject():
258         m_aAbsURIRef(256), m_eScheme(INetProtocol::NotValid), m_eSmartScheme(INetProtocol::Http) {}
259 
260     bool HasError() const { return m_eScheme == INetProtocol::NotValid; }
261 
262     OUString GetMainURL(DecodeMechanism eMechanism,
263                                 rtl_TextEncoding eCharset
264                                     = RTL_TEXTENCODING_UTF8) const
265     { return decode(m_aAbsURIRef, eMechanism, eCharset); }
266 
267     OUString GetURLNoPass(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
268                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
269         const;
270 
271     OUString GetURLNoMark(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
272                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
273         const;
274 
275     OUString
276     getAbbreviated(css::uno::Reference< css::util::XStringWidth > const & rStringWidth,
277                    sal_Int32 nWidth,
278                    DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
279                    rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
280         const;
281 
282     bool operator ==(INetURLObject const & rObject) const;
283 
284     bool operator !=(INetURLObject const & rObject) const
285     { return !(*this == rObject); }
286 
287     // Strict Parsing:
288 
289     inline explicit INetURLObject(
290         std::u16string_view rTheAbsURIRef,
291         EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
292         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
293 
294     inline bool SetURL(std::u16string_view rTheAbsURIRef,
295                        EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
296                        rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
297 
298     bool ConcatData(INetProtocol eTheScheme, std::u16string_view rTheUser,
299                     std::u16string_view rThePassword,
300                     std::u16string_view rTheHost, sal_uInt32 nThePort,
301                     std::u16string_view rThePath);
302 
303     // Smart Parsing:
304 
305     inline INetURLObject(std::u16string_view rTheAbsURIRef,
306                          INetProtocol eTheSmartScheme,
307                          EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
308                          rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
309                          FSysStyle eStyle = FSysStyle::Detect);
310 
311     void SetSmartProtocol(INetProtocol eTheSmartScheme)
312     { m_eSmartScheme = eTheSmartScheme; }
313 
314     inline bool
315     SetSmartURL(std::u16string_view rTheAbsURIRef,
316                 EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
317                 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
318                 FSysStyle eStyle = FSysStyle::Detect);
319 
320     inline INetURLObject
321     smartRel2Abs(OUString const & rTheRelURIRef,
322                  bool & rWasAbsolute,
323                  bool bIgnoreFragment = false,
324                  EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
325                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
326                  bool bRelativeNonURIs = false,
327                  FSysStyle eStyle = FSysStyle::Detect) const;
328 
329     // Relative URLs:
330 
331     inline bool
332     GetNewAbsURL(OUString const & rTheRelURIRef,
333                  INetURLObject * pTheAbsURIRef)
334         const;
335 
336     /** @descr  If rTheRelURIRef cannot be converted to an absolute URL
337         (because of syntactic reasons), either rTheRelURIRef or an empty
338         string is returned:  If all of the parameters eEncodeMechanism,
339         eDecodeMechanism and eCharset have their respective default values,
340         then rTheRelURIRef is returned unmodified; otherwise, an empty string
341         is returned.
342      */
343     static OUString
344     GetAbsURL(std::u16string_view rTheBaseURIRef,
345               OUString const & rTheRelURIRef,
346               EncodeMechanism eEncodeMechanism = EncodeMechanism::WasEncoded,
347               DecodeMechanism eDecodeMechanism = DecodeMechanism::ToIUri,
348               rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
349 
350     static inline OUString
351     GetRelURL(std::u16string_view rTheBaseURIRef,
352               OUString const & rTheAbsURIRef,
353               EncodeMechanism eEncodeMechanism = EncodeMechanism::WasEncoded,
354               DecodeMechanism eDecodeMechanism = DecodeMechanism::ToIUri,
355               rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
356               FSysStyle eStyle = FSysStyle::Detect);
357 
358     // External URLs:
359 
360     OUString getExternalURL() const;
361 
362     static inline bool translateToExternal(std::u16string_view rTheIntURIRef,
363                                            OUString & rTheExtURIRef,
364                                            DecodeMechanism eDecodeMechanism
365                                                = DecodeMechanism::ToIUri,
366                                            rtl_TextEncoding eCharset
367                                                = RTL_TEXTENCODING_UTF8);
368 
369     static inline bool translateToInternal(std::u16string_view rTheExtURIRef,
370                                            OUString & rTheIntURIRef,
371                                            DecodeMechanism eDecodeMechanism
372                                                = DecodeMechanism::ToIUri,
373                                            rtl_TextEncoding eCharset
374                                                = RTL_TEXTENCODING_UTF8);
375 
376     // Scheme:
377 
378     struct SchemeInfo;
379 
380     INetProtocol GetProtocol() const { return m_eScheme; }
381 
382     bool isSchemeEqualTo(INetProtocol scheme) const { return scheme == m_eScheme; }
383 
384     bool isSchemeEqualTo(std::u16string_view scheme) const;
385 
386     /** Check if the scheme is one of the WebDAV scheme
387      *  we know about.
388      *
389      *  @return true is one other scheme either public scheme or private scheme.
390      */
391     bool isAnyKnownWebDAVScheme() const;
392 
393     /** Return the URL 'prefix' for a given scheme.
394 
395         @param eTheScheme  One of the supported URL schemes.
396 
397         @return  The 'prefix' of URLs of the given scheme.
398      */
399     static OUString GetScheme(INetProtocol eTheScheme);
400 
401     /** Return the human-readable name for a given scheme.
402 
403         @param eTheScheme  One of the supported URL schemes.
404 
405         @return  The protocol name of URLs of the given scheme.
406      */
407     static const OUString & GetSchemeName(INetProtocol eTheScheme);
408 
409     static INetProtocol CompareProtocolScheme(std::u16string_view aTheAbsURIRef);
410 
411     // User Info:
412 
413     bool HasUserData() const { return m_aUser.isPresent(); }
414 
415     OUString GetUser(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
416                              rtl_TextEncoding eCharset
417                                  = RTL_TEXTENCODING_UTF8) const
418     { return decode(m_aUser, eMechanism, eCharset); }
419 
420     OUString GetPass(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
421                              rtl_TextEncoding eCharset
422                                  = RTL_TEXTENCODING_UTF8) const
423     { return decode(m_aAuth, eMechanism, eCharset); }
424 
425     bool SetUser(std::u16string_view rTheUser)
426     { return setUser(rTheUser, RTL_TEXTENCODING_UTF8); }
427 
428     inline bool SetPass(std::u16string_view rThePassword);
429 
430     inline bool SetUserAndPass(std::u16string_view rTheUser,
431                                std::u16string_view rThePassword);
432 
433     // Host and Port:
434 
435     bool HasPort() const { return m_aPort.isPresent(); }
436 
437     OUString GetHost(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
438                              rtl_TextEncoding eCharset
439                                  = RTL_TEXTENCODING_UTF8) const
440     { return decode(m_aHost, eMechanism, eCharset); }
441 
442     OUString GetHostPort(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
443                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8) const;
444 
445     sal_uInt32 GetPort() const;
446 
447     bool SetHost(std::u16string_view rTheHost)
448     { return setHost(rTheHost, RTL_TEXTENCODING_UTF8); }
449 
450     bool SetPort(sal_uInt32 nThePort);
451 
452     // Path:
453 
454     bool HasURLPath() const { return !m_aPath.isEmpty(); }
455 
456     OUString GetURLPath(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
457                                 rtl_TextEncoding eCharset
458                                     = RTL_TEXTENCODING_UTF8) const
459     { return decode(m_aPath, eMechanism, eCharset); }
460 
461     bool SetURLPath(std::u16string_view rThePath,
462                            EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
463                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
464     { return setPath(rThePath, eMechanism, eCharset); }
465 
466     // Hierarchical Path:
467 
468     /** A constant to address the last segment in various methods dealing with
469         hierarchical paths.
470 
471         @descr  It is often more efficient to address the last segment using
472         this constant, than to determine its ordinal value using
473         getSegmentCount().
474      */
475     enum { LAST_SEGMENT = -1 };
476 
477     /** The number of segments in the hierarchical path.
478 
479         @descr  Using RFC 2396 and RFC 2234, a hierarchical path is of the
480         form
481 
482           hierarchical-path = 1*("/" segment)
483 
484           segment = name *(";" param)
485 
486           name = [base ["." extension]]
487 
488           base = 1*pchar
489 
490           extension = *<any pchar except ".">
491 
492           param = *pchar
493 
494         @param bIgnoreFinalSlash  If true, a final slash at the end of the
495         hierarchical path does not denote an empty segment, but is ignored.
496 
497         @return  The number of segments in the hierarchical path.  If the path
498         is not hierarchical, 0 is returned.
499      */
500     sal_Int32 getSegmentCount(bool bIgnoreFinalSlash = true) const;
501 
502     /** Remove a segment from the hierarchical path.
503 
504         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
505         if addressing the last segment.
506 
507         @param bIgnoreFinalSlash  If true, a final slash at the end of the
508         hierarchical path does not denote an empty segment, but is ignored.
509 
510         @return  True if the segment has successfully been removed (and the
511         resulting URI is still valid).  If the path is not hierarchical, or
512         the specified segment does not exist, false is returned.  If false is
513         returned, the object is not modified.
514      */
515     bool removeSegment(sal_Int32 nIndex = LAST_SEGMENT,
516                        bool bIgnoreFinalSlash = true);
517 
518     /** Insert a new segment into the hierarchical path.
519         A final slash at the end of the
520         hierarchical path does not denote an empty segment, but is ignored.
521 
522         @param rTheName  The name part of the new segment.  The new segment
523         will contain no parameters.
524 
525         @param bAppendFinalSlash  If the new segment is appended at the end of
526         the hierarchical path, this parameter specifies whether to add a final
527         slash after it or not.
528 
529         @param nIndex  The non-negative index of the segment before which
530         to insert the new segment.  LAST_SEGMENT or an nIndex that equals
531         getSegmentCount() inserts the new segment at the end of the
532         hierarchical path.
533 
534         @param eMechanism  See the general discussion for set-methods.
535 
536         @param eCharset  See the general discussion for set-methods.
537 
538         @return  True if the segment has successfully been inserted (and the
539         resulting URI is still valid).  If the path is not hierarchical, or
540         the specified place to insert the new segment does not exist, false is
541         returned.  If false is returned, the object is not modified.
542      */
543     bool insertName(std::u16string_view rTheName,
544                            bool bAppendFinalSlash = false,
545                            sal_Int32 nIndex = LAST_SEGMENT,
546                            EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
547                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
548 
549     /** Get the name of a segment of the hierarchical path.
550 
551         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
552         if addressing the last segment.
553 
554         @param bIgnoreFinalSlash  If true, a final slash at the end of the
555         hierarchical path does not denote an empty segment, but is ignored.
556 
557         @param eMechanism  See the general discussion for get-methods.
558 
559         @param eCharset  See the general discussion for get-methods.
560 
561         @return  The name part of the specified segment.  If the path is not
562         hierarchical, or the specified segment does not exits, an empty string
563         is returned.
564      */
565     OUString getName(sal_Int32 nIndex = LAST_SEGMENT,
566                       bool bIgnoreFinalSlash = true,
567                       DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
568                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
569         const;
570 
571     /** Set the name of the last segment (preserving any parameters and any query or
572         fragment part).
573 
574         @param rTheName  The new name.
575 
576         @param eMechanism  See the general discussion for get-methods.
577 
578         @param eCharset  See the general discussion for get-methods.
579 
580         @return  True if the name has successfully been modified (and the
581         resulting URI is still valid).  If the path is not hierarchical, or
582         a last segment does not exist, false is returned.  If false is
583         returned, the object is not modified.
584      */
585     bool setName(std::u16string_view rTheName,
586                  EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
587                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
588 
589     /** Get the base of the name of a segment.
590 
591         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
592         if addressing the last segment.
593 
594         @param bIgnoreFinalSlash  If true, a final slash at the end of the
595         hierarchical path does not denote an empty segment, but is ignored.
596 
597         @param eMechanism  See the general discussion for get-methods.
598 
599         @param eCharset  See the general discussion for get-methods.
600 
601         @return  The base part of the specified segment.  If the path is
602         not hierarchical, or the specified segment does not exits, an empty
603         string is returned.
604      */
605     OUString getBase(sal_Int32 nIndex = LAST_SEGMENT,
606                       bool bIgnoreFinalSlash = true,
607                       DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
608                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
609         const;
610 
611     /** Set the base of the name of a segment (preserving the extension).
612         A final slash at the end of the
613         hierarchical path does not denote an empty segment, but is ignored.
614 
615         @param rTheBase  The new base.
616 
617         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
618         if addressing the last segment.
619 
620         @param eMechanism  See the general discussion for set-methods.
621 
622         @param eCharset  See the general discussion for set-methods.
623 
624         @return  True if the base has successfully been modified (and the
625         resulting URI is still valid).  If the path is not hierarchical, or
626         the specified segment does not exist, false is returned.  If false is
627         returned, the object is not modified.
628      */
629     bool setBase(std::u16string_view rTheBase,
630                  sal_Int32 nIndex = LAST_SEGMENT,
631                  EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
632                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
633 
634     /** Determine whether the name of the last segment has an extension.
635 
636         @return  True if the name of the specified segment has an extension.
637         If the path is not hierarchical, or the specified segment does not
638         exist, false is returned.
639      */
640     bool hasExtension() const;
641 
642     /** Get the extension of the name of a segment.
643 
644         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
645         if addressing the last segment.
646 
647         @param bIgnoreFinalSlash  If true, a final slash at the end of the
648         hierarchical path does not denote an empty segment, but is ignored.
649 
650         @param eMechanism  See the general discussion for get-methods.
651 
652         @param eCharset  See the general discussion for get-methods.
653 
654         @return  The extension part of the specified segment.  If the path is
655         not hierarchical, or the specified segment does not exits, an empty
656         string is returned.
657      */
658     OUString getExtension(sal_Int32 nIndex = LAST_SEGMENT,
659                            bool bIgnoreFinalSlash = true,
660                            DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
661                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
662         const;
663 
664     /** Set the extension of the name of a segment (replacing an already
665         existing extension).
666 
667         @param rTheExtension  The new extension.
668 
669         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
670         if addressing the last segment.
671 
672         @param bIgnoreFinalSlash  If true, a final slash at the end of the
673         hierarchical path does not denote an empty segment, but is ignored.
674 
675         @param eCharset  See the general discussion for set-methods.
676 
677         @return  True if the extension has successfully been modified (and the
678         resulting URI is still valid).  If the path is not hierarchical, or
679         the specified segment does not exist, false is returned.  If false is
680         returned, the object is not modified.
681      */
682     bool setExtension(std::u16string_view rTheExtension,
683                       sal_Int32 nIndex = LAST_SEGMENT,
684                       bool bIgnoreFinalSlash = true,
685                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
686 
687     /** Remove the extension of the name of a segment.
688 
689         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
690         if addressing the last segment.
691 
692         @param bIgnoreFinalSlash  If true, a final slash at the end of the
693         hierarchical path does not denote an empty segment, but is ignored.
694 
695         @return  True if the extension has successfully been removed (and the
696         resulting URI is still valid), or if the name did not have an
697         extension.  If the path is not hierarchical, or the specified segment
698         does not exist, false is returned.  If false is returned, the object
699         is not modified.
700      */
701     bool removeExtension(sal_Int32 nIndex = LAST_SEGMENT,
702                          bool bIgnoreFinalSlash = true);
703 
704     /** Determine whether the hierarchical path ends in a final slash.
705 
706         @return  True if the hierarchical path ends in a final slash.  If the
707         path is not hierarchical, false is returned.
708      */
709     bool hasFinalSlash() const;
710 
711     /** Make the hierarchical path end in a final slash (if it does not
712         already do so).
713 
714         @return  True if a final slash has successfully been appended (and the
715         resulting URI is still valid), or if the hierarchical path already
716         ended in a final slash.  If the path is not hierarchical, false is
717         returned.  If false is returned, the object is not modified.
718      */
719     bool setFinalSlash();
720 
721     /** Remove a final slash from the hierarchical path.
722 
723         @return  True if a final slash has successfully been removed (and the
724         resulting URI is still valid), or if the hierarchical path already did
725         not end in a final slash.  If the path is not hierarchical, false is
726         returned.  If false is returned, the object is not modified.
727      */
728     bool removeFinalSlash();
729 
730     // Query:
731 
732     bool HasParam() const { return m_aQuery.isPresent(); }
733 
734     OUString GetParam(rtl_TextEncoding eCharset
735                                   = RTL_TEXTENCODING_UTF8) const
736     { return decode(m_aQuery, DecodeMechanism::NONE, eCharset); }
737 
738     inline bool SetParam(std::u16string_view rTheQuery,
739                          EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
740                          rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
741 
742     // Fragment:
743 
744     bool HasMark() const { return m_aFragment.isPresent(); }
745 
746     OUString GetMark(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
747                              rtl_TextEncoding eCharset
748                                  = RTL_TEXTENCODING_UTF8) const
749     { return decode(m_aFragment, eMechanism, eCharset); }
750 
751     inline bool SetMark(std::u16string_view rTheFragment,
752                         EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
753                         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
754 
755     // File URLs:
756 
757     /** Return the file system path represented by a file URL (ignoring any
758         fragment part).
759 
760         @param eStyle  The notation of the returned file system path.
761 
762         @param pDelimiter  Upon successful return, this parameter can return
763         the character that is the 'main' delimiter within the returned file
764         system path (e.g., "/" for Unix, "\" for DOS).  This is
765         especially useful for routines that later try to shorten the returned
766         file system path at a 'good' position, e.g. to fit it into some
767         limited display space.
768 
769         @return  The file system path represented by this file URL.  If this
770         file URL does not represent a file system path according to the
771         specified notation, or if this is not a file URL at all, an empty
772         string is returned.
773      */
774     OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = nullptr)
775         const;
776 
777     // Data URLs:
778     std::unique_ptr<SvMemoryStream> getData() const;
779 
780     // Coding:
781 
782     enum Part
783     {
784         PART_USER_PASSWORD          = 0x00001,
785         PART_FPATH                  = 0x00008,
786         PART_AUTHORITY              = 0x00010,
787         PART_REL_SEGMENT_EXTRA      = 0x00020,
788         PART_URIC                   = 0x00040,
789         PART_HTTP_PATH              = 0x00080,
790         PART_MESSAGE_ID_PATH        = 0x00100,
791         PART_MAILTO                 = 0x00200,
792         PART_PATH_BEFORE_QUERY      = 0x00400,
793         PART_PCHAR                  = 0x00800,
794         PART_VISIBLE                = 0x01000,
795         PART_VISIBLE_NONSPECIAL     = 0x02000,
796         PART_UNO_PARAM_VALUE        = 0x04000,
797         PART_UNAMBIGUOUS            = 0x08000,
798         PART_URIC_NO_SLASH          = 0x10000,
799         PART_HTTP_QUERY             = 0x20000, //TODO! unused?
800     };
801 
802     enum class EscapeType
803     {
804         NONE,
805         Octet,
806         Utf32
807     };
808 
809     /** Encode some text as part of a URI.
810 
811         @param rText  Some text (for its interpretation, see the general
812         discussion for set-methods).
813 
814         @param ePart  The part says which characters are 'forbidden' and must
815         be encoded (replaced by escape sequences).  Characters outside the US-
816         ASCII range are always 'forbidden.'
817 
818         @param eMechanism  See the general discussion for set-methods.
819 
820         @param eCharset  See the general discussion for set-methods.
821 
822         @return  The text, encoded according to the given mechanism and
823         charset ('forbidden' characters replaced by escape sequences).
824      */
825     static OUString encode( std::u16string_view rText, Part ePart,
826                            EncodeMechanism eMechanism,
827                            rtl_TextEncoding eCharset
828                                = RTL_TEXTENCODING_UTF8);
829 
830 
831     /** Decode some text.
832 
833         @param rText  Some (encoded) text.
834 
835         @param eMechanism  See the general discussion for get-methods.
836 
837         @param eCharset  See the general discussion for get-methods.
838 
839         @return  The text, decoded according to the given mechanism and
840         charset (escape sequences replaced by 'raw' characters).
841      */
842     static inline OUString decode(std::u16string_view rText,
843                                    DecodeMechanism eMechanism,
844                                    rtl_TextEncoding eCharset
845                                        = RTL_TEXTENCODING_UTF8);
846 
847     static void appendUCS4Escape(OUStringBuffer & rTheText, sal_uInt32 nUCS4);
848 
849     static void appendUCS4(OUStringBuffer & rTheText, sal_uInt32 nUCS4,
850                            EscapeType eEscapeType, Part ePart,
851                            rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
852 
853     static sal_uInt32 getUTF32(sal_Unicode const *& rBegin,
854                                sal_Unicode const * pEnd,
855                                EncodeMechanism eMechanism,
856                                rtl_TextEncoding eCharset,
857                                EscapeType & rEscapeType);
858 
859     // Specialized helpers:
860 
861     static sal_uInt32 scanDomain(sal_Unicode const *& rBegin,
862                                  sal_Unicode const * pEnd,
863                                  bool bEager = true);
864 
865     // OBSOLETE Hierarchical Path:
866 
867     OUString GetPartBeforeLastName() const;
868 
869     /** Get the last segment in the path.
870 
871         @param eMechanism  See the general discussion for get-methods.
872 
873         @param eCharset  See the general discussion for get-methods.
874 
875         @return  For a hierarchical URL, the last segment (everything after
876         the last unencoded '/').  Note that this last segment may be empty.  If
877         the URL is not hierarchical, an empty string is returned.
878      */
879     OUString GetLastName(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
880                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
881         const;
882 
883     /** Get the 'extension' of the last segment in the path.
884 
885         @return  For a hierarchical URL, everything after the first unencoded
886         '.' in the last segment of the path.  Note that this 'extension' may
887         be empty.  If the URL is not hierarchical, or if the last segment does
888         not contain an unencoded '.', an empty string is returned.
889      */
890     OUString GetFileExtension() const;
891 
892     bool Append(std::u16string_view rTheSegment,
893                        EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
894                        rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
895 
896     void CutLastName();
897 
898     // OBSOLETE File URLs:
899 
900     OUString PathToFileName() const;
901 
902     OUString GetFull() const;
903 
904     OUString GetPath() const;
905 
906     void SetBase(std::u16string_view rTheBase);
907 
908     OUString GetBase() const;
909 
910     void SetExtension(std::u16string_view rTheExtension);
911 
912     OUString CutExtension();
913 
914     static bool IsCaseSensitive() { return true; }
915 
916     void changeScheme(INetProtocol eTargetScheme);
917 
918 private:
919     // General Structure:
920 
921     class SAL_DLLPRIVATE SubString
922     {
923         sal_Int32 m_nBegin;
924         sal_Int32 m_nLength;
925 
926     public:
927         explicit SubString(sal_Int32 nTheBegin = -1,
928                                   sal_Int32 nTheLength = 0):
929             m_nBegin(nTheBegin), m_nLength(nTheLength) {}
930 
931         bool isPresent() const { return m_nBegin != -1; }
932 
933         bool isEmpty() const { return m_nLength == 0; }
934 
935         sal_Int32 getBegin() const { return m_nBegin; }
936 
937         sal_Int32 getLength() const { return m_nLength; }
938 
939         sal_Int32 getEnd() const { return m_nBegin + m_nLength; }
940 
941         sal_Int32 clear();
942 
943         sal_Int32 set(OUStringBuffer & rString,
944                       std::u16string_view rSubString,
945                       sal_Int32 nTheBegin);
946 
947         sal_Int32 set(OUString & rString,
948                       std::u16string_view rSubString);
949 
950         sal_Int32 set(OUStringBuffer & rString,
951                       std::u16string_view rSubString);
952 
953         inline void operator +=(sal_Int32 nDelta);
954 
955         int compare(SubString const & rOther,
956             OUStringBuffer const & rThisString,
957             OUStringBuffer const & rOtherString) const;
958     };
959 
960     OUStringBuffer m_aAbsURIRef;
961     SubString m_aScheme;
962     SubString m_aUser;
963     SubString m_aAuth;
964     SubString m_aHost;
965     SubString m_aPort;
966     SubString m_aPath;
967     SubString m_aQuery;
968     SubString m_aFragment;
969     INetProtocol m_eScheme;
970     INetProtocol m_eSmartScheme;
971 
972     TOOLS_DLLPRIVATE void setInvalid();
973 
974     bool setAbsURIRef(
975         std::u16string_view rTheAbsURIRef,
976         EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bSmart,
977         FSysStyle eStyle);
978 
979     // Relative URLs:
980 
981     bool convertRelToAbs(
982         OUString const & rTheRelURIRef,
983         INetURLObject & rTheAbsURIRef, bool & rWasAbsolute,
984         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
985         bool bIgnoreFragment, bool bSmart, bool bRelativeNonURIs,
986         FSysStyle eStyle) const;
987 
988     bool convertAbsToRel(
989         OUString const & rTheAbsURIRef,
990         OUString & rTheRelURIRef, EncodeMechanism eEncodeMechanism,
991         DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset,
992         FSysStyle eStyle) const;
993 
994     // External URLs:
995 
996     static bool convertIntToExt(
997         std::u16string_view rTheIntURIRef,
998         OUString & rTheExtURIRef, DecodeMechanism eDecodeMechanism,
999         rtl_TextEncoding eCharset);
1000 
1001     static bool convertExtToInt(
1002         std::u16string_view rTheExtURIRef,
1003         OUString & rTheIntURIRef, DecodeMechanism eDecodeMechanism,
1004         rtl_TextEncoding eCharset);
1005 
1006     // Scheme:
1007 
1008     struct PrefixInfo;
1009 
1010     TOOLS_DLLPRIVATE static inline SchemeInfo const & getSchemeInfo(
1011         INetProtocol eTheScheme);
1012 
1013     TOOLS_DLLPRIVATE inline SchemeInfo const & getSchemeInfo() const;
1014 
1015     TOOLS_DLLPRIVATE static PrefixInfo const * getPrefix(
1016         sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1017 
1018     // Authority:
1019 
1020     TOOLS_DLLPRIVATE sal_Int32 getAuthorityBegin() const;
1021 
1022     TOOLS_DLLPRIVATE SubString getAuthority() const;
1023 
1024     // User Info:
1025 
1026     bool setUser(
1027         std::u16string_view rTheUser,
1028         rtl_TextEncoding eCharset);
1029 
1030     bool clearPassword();
1031 
1032     bool setPassword(
1033         std::u16string_view rThePassword,
1034         rtl_TextEncoding eCharset);
1035 
1036     // Host and Port:
1037 
1038     TOOLS_DLLPRIVATE static bool parseHost(
1039         sal_Unicode const *& rBegin, sal_Unicode const * pEnd,
1040         OUStringBuffer* pCanonic);
1041 
1042     TOOLS_DLLPRIVATE static bool parseHostOrNetBiosName(
1043         sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1044         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1045         bool bNetBiosName, OUStringBuffer* pCanonic);
1046 
1047     bool setHost(
1048         std::u16string_view rTheHost,
1049         rtl_TextEncoding eCharset);
1050 
1051     // Path:
1052 
1053     TOOLS_DLLPRIVATE static bool parsePath(
1054         INetProtocol eScheme, sal_Unicode const ** pBegin,
1055         sal_Unicode const * pEnd, EncodeMechanism eMechanism,
1056         rtl_TextEncoding eCharset, bool bSkippedInitialSlash,
1057         sal_uInt32 nSegmentDelimiter, sal_uInt32 nAltSegmentDelimiter,
1058         sal_uInt32 nQueryDelimiter, sal_uInt32 nFragmentDelimiter,
1059         OUStringBuffer &rSynPath);
1060 
1061     bool setPath(
1062         std::u16string_view rThePath,
1063         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1064 
1065     // Hierarchical Path:
1066 
1067     TOOLS_DLLPRIVATE bool checkHierarchical() const;
1068 
1069     TOOLS_DLLPRIVATE SubString getSegment(
1070         sal_Int32 nIndex, bool bIgnoreFinalSlash) const;
1071 
1072     // Query:
1073 
1074     void clearQuery();
1075 
1076     bool setQuery(
1077         std::u16string_view rTheQuery,
1078         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1079 
1080     // Fragment:
1081 
1082     bool clearFragment();
1083 
1084     bool setFragment(
1085         std::u16string_view rTheMark,
1086         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1087 
1088     // FILE URLs:
1089 
1090     TOOLS_DLLPRIVATE bool hasDosVolume(FSysStyle eStyle) const;
1091 
1092     // Coding:
1093 
1094     TOOLS_DLLPRIVATE static inline void appendEscape(
1095         OUStringBuffer & rTheText, sal_uInt32 nOctet);
1096 
1097     static void encodeText(
1098         OUStringBuffer& rOutputBuffer,
1099         sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1100         Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1101         bool bKeepVisibleEscapes);
1102 
1103     static inline void encodeText(
1104         OUStringBuffer& rOutputBuffer,
1105         std::u16string_view rTheText, Part ePart,
1106         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1107         bool bKeepVisibleEscapes);
1108 
1109     static OUString decode(
1110         sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1111         DecodeMechanism, rtl_TextEncoding eCharset);
1112 
1113     inline OUString decode(
1114         SubString const & rSubString,
1115         DecodeMechanism eMechanism, rtl_TextEncoding eCharset) const;
1116 
1117     // Specialized helpers:
1118 
1119     TOOLS_DLLPRIVATE static bool scanIPv6reference(
1120         sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1121 };
1122 
1123 // static
1124 inline void INetURLObject::encodeText( OUStringBuffer& rOutputBuffer,
1125                                            std::u16string_view rTheText,
1126                                            Part ePart,
1127                                            EncodeMechanism eMechanism,
1128                                            rtl_TextEncoding eCharset,
1129                                            bool bKeepVisibleEscapes)
1130 {
1131     encodeText(rOutputBuffer,
1132                 rTheText.data(),
1133                 rTheText.data() + rTheText.size(), ePart,
1134                 eMechanism, eCharset, bKeepVisibleEscapes);
1135 }
1136 
1137 inline OUString INetURLObject::decode(SubString const & rSubString,
1138                                        DecodeMechanism eMechanism,
1139                                        rtl_TextEncoding eCharset) const
1140 {
1141     return rSubString.isPresent() ?
1142                decode(m_aAbsURIRef.getStr() + rSubString.getBegin(),
1143                       m_aAbsURIRef.getStr() + rSubString.getEnd(),
1144                       eMechanism, eCharset) :
1145                OUString();
1146 }
1147 
1148 inline INetURLObject::INetURLObject(std::u16string_view rTheAbsURIRef,
1149                                     EncodeMechanism eMechanism,
1150                                     rtl_TextEncoding eCharset):
1151     m_aAbsURIRef(rTheAbsURIRef.size() * 2), m_eScheme(INetProtocol::NotValid), m_eSmartScheme(INetProtocol::Http)
1152 {
1153     setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, false,
1154                  FSysStyle(0));
1155 }
1156 
1157 inline bool INetURLObject::SetURL(std::u16string_view rTheAbsURIRef,
1158                                   EncodeMechanism eMechanism,
1159                                   rtl_TextEncoding eCharset)
1160 {
1161     return setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, false,
1162                         FSysStyle(0));
1163 }
1164 
1165 inline INetURLObject::INetURLObject(std::u16string_view rTheAbsURIRef,
1166                                     INetProtocol eTheSmartScheme,
1167                                     EncodeMechanism eMechanism,
1168                                     rtl_TextEncoding eCharset,
1169                                     FSysStyle eStyle):
1170     m_eScheme(INetProtocol::NotValid), m_eSmartScheme(eTheSmartScheme)
1171 {
1172     setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, true, eStyle);
1173 }
1174 
1175 inline bool INetURLObject::SetSmartURL(std::u16string_view rTheAbsURIRef,
1176                                        EncodeMechanism eMechanism,
1177                                        rtl_TextEncoding eCharset,
1178                                        FSysStyle eStyle)
1179 {
1180     return setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, true,
1181                         eStyle);
1182 }
1183 
1184 inline INetURLObject
1185 INetURLObject::smartRel2Abs(OUString const & rTheRelURIRef,
1186                             bool & rWasAbsolute,
1187                             bool bIgnoreFragment,
1188                             EncodeMechanism eMechanism,
1189                             rtl_TextEncoding eCharset,
1190                             bool bRelativeNonURIs,
1191                             FSysStyle eStyle) const
1192 {
1193     INetURLObject aTheAbsURIRef;
1194     convertRelToAbs(rTheRelURIRef, aTheAbsURIRef, rWasAbsolute,
1195                     eMechanism, eCharset, bIgnoreFragment, true,
1196                     bRelativeNonURIs, eStyle);
1197     return aTheAbsURIRef;
1198 }
1199 
1200 inline bool INetURLObject::GetNewAbsURL(OUString const & rTheRelURIRef,
1201                                         INetURLObject * pTheAbsURIRef)
1202     const
1203 {
1204     INetURLObject aTheAbsURIRef;
1205     bool bWasAbsolute;
1206     if (!convertRelToAbs(rTheRelURIRef, aTheAbsURIRef, bWasAbsolute,
1207                          EncodeMechanism::WasEncoded, RTL_TEXTENCODING_UTF8, false/*bIgnoreFragment*/, false, false,
1208                          FSysStyle::Detect))
1209         return false;
1210     if (pTheAbsURIRef)
1211         *pTheAbsURIRef = aTheAbsURIRef;
1212     return true;
1213 }
1214 
1215 // static
1216 inline OUString INetURLObject::GetRelURL(std::u16string_view rTheBaseURIRef,
1217                                           OUString const & rTheAbsURIRef,
1218                                           EncodeMechanism eEncodeMechanism,
1219                                           DecodeMechanism eDecodeMechanism,
1220                                           rtl_TextEncoding eCharset,
1221                                           FSysStyle eStyle)
1222 {
1223     OUString aTheRelURIRef;
1224     INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
1225         convertAbsToRel(rTheAbsURIRef, aTheRelURIRef, eEncodeMechanism,
1226                         eDecodeMechanism, eCharset, eStyle);
1227     return aTheRelURIRef;
1228 }
1229 
1230 // static
1231 inline bool INetURLObject::translateToExternal(std::u16string_view
1232                                                    rTheIntURIRef,
1233                                                OUString & rTheExtURIRef,
1234                                                DecodeMechanism
1235                                                    eDecodeMechanism,
1236                                                rtl_TextEncoding eCharset)
1237 {
1238     return convertIntToExt(rTheIntURIRef, rTheExtURIRef,
1239                            eDecodeMechanism, eCharset);
1240 }
1241 
1242 // static
1243 inline bool INetURLObject::translateToInternal(std::u16string_view
1244                                                    rTheExtURIRef,
1245                                                OUString & rTheIntURIRef,
1246                                                DecodeMechanism
1247                                                    eDecodeMechanism,
1248                                                rtl_TextEncoding eCharset)
1249 {
1250     return convertExtToInt(rTheExtURIRef, rTheIntURIRef,
1251                            eDecodeMechanism, eCharset);
1252 }
1253 
1254 inline bool INetURLObject::SetPass(std::u16string_view rThePassword)
1255 {
1256     return rThePassword.empty() ?
1257                clearPassword() :
1258                setPassword(rThePassword, RTL_TEXTENCODING_UTF8);
1259 }
1260 
1261 inline bool INetURLObject::SetUserAndPass(std::u16string_view rTheUser,
1262                                           std::u16string_view rThePassword)
1263 {
1264     return setUser(rTheUser, RTL_TEXTENCODING_UTF8)
1265            && (rThePassword.empty() ?
1266                    clearPassword() :
1267                    setPassword(rThePassword, RTL_TEXTENCODING_UTF8));
1268 }
1269 
1270 inline bool INetURLObject::SetParam(std::u16string_view rTheQuery,
1271                                     EncodeMechanism eMechanism,
1272                                     rtl_TextEncoding eCharset)
1273 {
1274     if (rTheQuery.empty())
1275     {
1276         clearQuery();
1277         return false;
1278     }
1279     return setQuery(rTheQuery, eMechanism, eCharset);
1280 }
1281 
1282 inline bool INetURLObject::SetMark(std::u16string_view rTheFragment,
1283                                    EncodeMechanism eMechanism,
1284                                    rtl_TextEncoding eCharset)
1285 {
1286     return rTheFragment.empty() ?
1287                clearFragment() :
1288                setFragment(rTheFragment, eMechanism, eCharset);
1289 }
1290 
1291 // static
1292 inline OUString INetURLObject::encode(std::u16string_view rText, Part ePart,
1293                                    EncodeMechanism eMechanism,
1294                                    rtl_TextEncoding eCharset)
1295 {
1296     OUStringBuffer aBuf;
1297     encodeText(aBuf, rText, ePart, eMechanism, eCharset, false);
1298     return aBuf.makeStringAndClear();
1299 }
1300 
1301 // static
1302 inline OUString INetURLObject::decode(std::u16string_view rText,
1303                                        DecodeMechanism eMechanism,
1304                                        rtl_TextEncoding eCharset)
1305 {
1306     return decode(rText.data(), rText.data() + rText.size(),
1307                   eMechanism, eCharset);
1308 }
1309 
1310 #endif
1311 
1312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1313