Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/tools/urlobj.hxx
Line
Count
Source
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 OUString INET_FTP_SCHEME = u"ftp://"_ustr;
41
inline constexpr OUString INET_HTTP_SCHEME = u"http://"_ustr;
42
inline constexpr OUString INET_HTTPS_SCHEME = u"https://"_ustr;
43
inline constexpr OUString INET_FILE_SCHEME = u"file://"_ustr;
44
inline constexpr OUString INET_MAILTO_SCHEME = u"mailto:"_ustr;
45
inline constexpr OUString INET_HID_SCHEME = u"hid:"_ustr;
46
47
0
#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
1.20M
        m_aAbsURIRef(256), m_eScheme(INetProtocol::NotValid), m_eSmartScheme(INetProtocol::Http) {}
259
260
543k
    bool HasError() const { return m_eScheme == INetProtocol::NotValid; }
261
262
    OUString GetMainURL(DecodeMechanism eMechanism,
263
                                rtl_TextEncoding eCharset
264
                                    = RTL_TEXTENCODING_UTF8) const
265
835k
    { 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
0
    { 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
141k
    { 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
524k
    INetProtocol GetProtocol() const { return m_eScheme; }
381
382
60.2k
    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 const 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
0
    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
58
    { return decode(m_aUser, eMechanism, eCharset); }
419
420
    OUString GetPass(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
421
                             rtl_TextEncoding eCharset
422
                                 = RTL_TEXTENCODING_UTF8) const
423
58
    { return decode(m_aAuth, eMechanism, eCharset); }
424
425
    bool SetUser(std::u16string_view rTheUser)
426
0
    { return setUser(rTheUser, RTL_TEXTENCODING_UTF8); }
427
428
    // Host and Port:
429
430
108k
    bool HasPort() const { return m_aPort.isPresent(); }
431
432
    OUString GetHost(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
433
                             rtl_TextEncoding eCharset
434
                                 = RTL_TEXTENCODING_UTF8) const
435
58
    { return decode(m_aHost, eMechanism, eCharset); }
436
437
    OUString GetHostPort(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
438
                          rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8) const;
439
440
    sal_uInt32 GetPort() const;
441
442
    bool SetPort(sal_uInt32 nThePort);
443
444
    // Path:
445
446
66.7k
    bool HasURLPath() const { return !m_aPath.isEmpty(); }
447
448
    OUString GetURLPath(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
449
                                rtl_TextEncoding eCharset
450
                                    = RTL_TEXTENCODING_UTF8) const
451
18.2k
    { return decode(m_aPath, eMechanism, eCharset); }
452
453
    bool SetURLPath(std::u16string_view rThePath,
454
                           EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
455
                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
456
0
    { return setPath(rThePath, eMechanism, eCharset); }
457
458
    // Hierarchical Path:
459
460
    /** A constant to address the last segment in various methods dealing with
461
        hierarchical paths.
462
463
        @descr  It is often more efficient to address the last segment using
464
        this constant, than to determine its ordinal value using
465
        getSegmentCount().
466
     */
467
    enum { LAST_SEGMENT = -1 };
468
469
    /** The number of segments in the hierarchical path.
470
471
        @descr  Using RFC 2396 and RFC 2234, a hierarchical path is of the
472
        form
473
474
          hierarchical-path = 1*("/" segment)
475
476
          segment = name *(";" param)
477
478
          name = [base ["." extension]]
479
480
          base = 1*pchar
481
482
          extension = *<any pchar except ".">
483
484
          param = *pchar
485
486
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
487
        hierarchical path does not denote an empty segment, but is ignored.
488
489
        @return  The number of segments in the hierarchical path.  If the path
490
        is not hierarchical, 0 is returned.
491
     */
492
    sal_Int32 getSegmentCount(bool bIgnoreFinalSlash = true) const;
493
494
    /** Remove a segment from the hierarchical path.
495
496
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
497
        if addressing the last segment.
498
499
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
500
        hierarchical path does not denote an empty segment, but is ignored.
501
502
        @return  True if the segment has successfully been removed (and the
503
        resulting URI is still valid).  If the path is not hierarchical, or
504
        the specified segment does not exist, false is returned.  If false is
505
        returned, the object is not modified.
506
     */
507
    bool removeSegment(sal_Int32 nIndex = LAST_SEGMENT,
508
                       bool bIgnoreFinalSlash = true);
509
510
    /** Insert a new segment into the hierarchical path.
511
        A final slash at the end of the
512
        hierarchical path does not denote an empty segment, but is ignored.
513
514
        @param rTheName  The name part of the new segment.  The new segment
515
        will contain no parameters.
516
517
        @param bAppendFinalSlash  If the new segment is appended at the end of
518
        the hierarchical path, this parameter specifies whether to add a final
519
        slash after it or not.
520
521
        @param nIndex  The non-negative index of the segment before which
522
        to insert the new segment.  LAST_SEGMENT or an nIndex that equals
523
        getSegmentCount() inserts the new segment at the end of the
524
        hierarchical path.
525
526
        @param eMechanism  See the general discussion for set-methods.
527
528
        @param eCharset  See the general discussion for set-methods.
529
530
        @return  True if the segment has successfully been inserted (and the
531
        resulting URI is still valid).  If the path is not hierarchical, or
532
        the specified place to insert the new segment does not exist, false is
533
        returned.  If false is returned, the object is not modified.
534
     */
535
    bool insertName(std::u16string_view rTheName,
536
                           bool bAppendFinalSlash = false,
537
                           sal_Int32 nIndex = LAST_SEGMENT,
538
                           EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
539
                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
540
541
    /** Get the name of a segment of the hierarchical path.
542
543
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
544
        if addressing the last segment.
545
546
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
547
        hierarchical path does not denote an empty segment, but is ignored.
548
549
        @param eMechanism  See the general discussion for get-methods.
550
551
        @param eCharset  See the general discussion for get-methods.
552
553
        @return  The name part of the specified segment.  If the path is not
554
        hierarchical, or the specified segment does not exits, an empty string
555
        is returned.
556
     */
557
    OUString getName(sal_Int32 nIndex = LAST_SEGMENT,
558
                      bool bIgnoreFinalSlash = true,
559
                      DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
560
                      rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
561
        const;
562
563
    /** Set the name of the last segment (preserving any parameters and any query or
564
        fragment part).
565
566
        @param rTheName  The new name.
567
568
        @param eMechanism  See the general discussion for get-methods.
569
570
        @param eCharset  See the general discussion for get-methods.
571
572
        @return  True if the name has successfully been modified (and the
573
        resulting URI is still valid).  If the path is not hierarchical, or
574
        a last segment does not exist, false is returned.  If false is
575
        returned, the object is not modified.
576
     */
577
    bool setName(std::u16string_view rTheName,
578
                 EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
579
                 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
580
581
    /** Get the base of the name of a segment.
582
583
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
584
        if addressing the last segment.
585
586
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
587
        hierarchical path does not denote an empty segment, but is ignored.
588
589
        @param eMechanism  See the general discussion for get-methods.
590
591
        @param eCharset  See the general discussion for get-methods.
592
593
        @return  The base part of the specified segment.  If the path is
594
        not hierarchical, or the specified segment does not exits, an empty
595
        string is returned.
596
     */
597
    OUString getBase(sal_Int32 nIndex = LAST_SEGMENT,
598
                      bool bIgnoreFinalSlash = true,
599
                      DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
600
                      rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
601
        const;
602
603
    /** Set the base of the name of a segment (preserving the extension).
604
        A final slash at the end of the
605
        hierarchical path does not denote an empty segment, but is ignored.
606
607
        @param rTheBase  The new base.
608
609
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
610
        if addressing the last segment.
611
612
        @param eMechanism  See the general discussion for set-methods.
613
614
        @param eCharset  See the general discussion for set-methods.
615
616
        @return  True if the base has successfully been modified (and the
617
        resulting URI is still valid).  If the path is not hierarchical, or
618
        the specified segment does not exist, false is returned.  If false is
619
        returned, the object is not modified.
620
     */
621
    bool setBase(std::u16string_view rTheBase,
622
                 sal_Int32 nIndex = LAST_SEGMENT,
623
                 EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
624
                 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
625
626
    /** Determine whether the name of the last segment has an extension.
627
628
        @return  True if the name of the specified segment has an extension.
629
        If the path is not hierarchical, or the specified segment does not
630
        exist, false is returned.
631
     */
632
    bool hasExtension() const;
633
634
    /** Get the extension of the name of a segment.
635
636
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
637
        if addressing the last segment.
638
639
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
640
        hierarchical path does not denote an empty segment, but is ignored.
641
642
        @param eMechanism  See the general discussion for get-methods.
643
644
        @param eCharset  See the general discussion for get-methods.
645
646
        @return  The extension part of the specified segment.  If the path is
647
        not hierarchical, or the specified segment does not exits, an empty
648
        string is returned.
649
     */
650
    OUString getExtension(sal_Int32 nIndex = LAST_SEGMENT,
651
                           bool bIgnoreFinalSlash = true,
652
                           DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
653
                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
654
        const;
655
656
    /** Set the extension of the name of a segment (replacing an already
657
        existing extension).
658
659
        @param rTheExtension  The new extension.
660
661
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
662
        if addressing the last segment.
663
664
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
665
        hierarchical path does not denote an empty segment, but is ignored.
666
667
        @param eCharset  See the general discussion for set-methods.
668
669
        @return  True if the extension has successfully been modified (and the
670
        resulting URI is still valid).  If the path is not hierarchical, or
671
        the specified segment does not exist, false is returned.  If false is
672
        returned, the object is not modified.
673
     */
674
    bool setExtension(std::u16string_view rTheExtension,
675
                      sal_Int32 nIndex = LAST_SEGMENT,
676
                      bool bIgnoreFinalSlash = true,
677
                      rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
678
679
    /** Remove the extension of the name of a segment.
680
681
        @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
682
        if addressing the last segment.
683
684
        @param bIgnoreFinalSlash  If true, a final slash at the end of the
685
        hierarchical path does not denote an empty segment, but is ignored.
686
687
        @return  True if the extension has successfully been removed (and the
688
        resulting URI is still valid), or if the name did not have an
689
        extension.  If the path is not hierarchical, or the specified segment
690
        does not exist, false is returned.  If false is returned, the object
691
        is not modified.
692
     */
693
    bool removeExtension(sal_Int32 nIndex = LAST_SEGMENT,
694
                         bool bIgnoreFinalSlash = true);
695
696
    /** Determine whether the hierarchical path ends in a final slash.
697
698
        @return  True if the hierarchical path ends in a final slash.  If the
699
        path is not hierarchical, false is returned.
700
     */
701
    bool hasFinalSlash() const;
702
703
    /** Make the hierarchical path end in a final slash (if it does not
704
        already do so).
705
706
        @return  True if a final slash has successfully been appended (and the
707
        resulting URI is still valid), or if the hierarchical path already
708
        ended in a final slash.  If the path is not hierarchical, false is
709
        returned.  If false is returned, the object is not modified.
710
     */
711
    bool setFinalSlash();
712
713
    /** Remove a final slash from the hierarchical path.
714
715
        @return  True if a final slash has successfully been removed (and the
716
        resulting URI is still valid), or if the hierarchical path already did
717
        not end in a final slash.  If the path is not hierarchical, false is
718
        returned.  If false is returned, the object is not modified.
719
     */
720
    bool removeFinalSlash();
721
722
    // Query:
723
724
0
    bool HasParam() const { return m_aQuery.isPresent(); }
725
726
    OUString GetParam(rtl_TextEncoding eCharset
727
                                  = RTL_TEXTENCODING_UTF8) const
728
58
    { return decode(m_aQuery, DecodeMechanism::NONE, eCharset); }
729
730
    inline bool SetParam(std::u16string_view rTheQuery,
731
                         EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
732
                         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
733
734
    // Fragment:
735
736
16.1k
    bool HasMark() const { return m_aFragment.isPresent(); }
737
738
    OUString GetMark(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
739
                             rtl_TextEncoding eCharset
740
                                 = RTL_TEXTENCODING_UTF8) const
741
3.09k
    { return decode(m_aFragment, eMechanism, eCharset); }
742
743
    inline bool SetMark(std::u16string_view rTheFragment,
744
                        EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
745
                        rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
746
747
    // File URLs:
748
749
    /** Return the file system path represented by a file URL (ignoring any
750
        fragment part).
751
752
        @param eStyle  The notation of the returned file system path.
753
754
        @param pDelimiter  Upon successful return, this parameter can return
755
        the character that is the 'main' delimiter within the returned file
756
        system path (e.g., "/" for Unix, "\" for DOS).  This is
757
        especially useful for routines that later try to shorten the returned
758
        file system path at a 'good' position, e.g. to fit it into some
759
        limited display space.
760
761
        @return  The file system path represented by this file URL.  If this
762
        file URL does not represent a file system path according to the
763
        specified notation, or if this is not a file URL at all, an empty
764
        string is returned.
765
     */
766
    OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = nullptr)
767
        const;
768
769
    // Data URLs:
770
    std::unique_ptr<SvMemoryStream> getData() const;
771
772
    // Coding:
773
774
    enum Part
775
    {
776
        PART_USER_PASSWORD          = 0x00001,
777
        PART_FPATH                  = 0x00008,
778
        PART_AUTHORITY              = 0x00010,
779
        PART_REL_SEGMENT_EXTRA      = 0x00020,
780
        PART_URIC                   = 0x00040,
781
        PART_HTTP_PATH              = 0x00080,
782
        PART_MESSAGE_ID_PATH        = 0x00100,
783
        PART_MAILTO                 = 0x00200,
784
        PART_PATH_BEFORE_QUERY      = 0x00400,
785
        PART_PCHAR                  = 0x00800,
786
        PART_VISIBLE                = 0x01000,
787
        PART_VISIBLE_NONSPECIAL     = 0x02000,
788
        PART_UNO_PARAM_VALUE        = 0x04000,
789
        PART_UNAMBIGUOUS            = 0x08000,
790
        PART_URIC_NO_SLASH          = 0x10000,
791
        PART_HTTP_QUERY             = 0x20000, //TODO! unused?
792
    };
793
794
    enum class EscapeType
795
    {
796
        NONE,
797
        Octet,
798
        Utf32
799
    };
800
801
    /** Encode some text as part of a URI.
802
803
        @param rText  Some text (for its interpretation, see the general
804
        discussion for set-methods).
805
806
        @param ePart  The part says which characters are 'forbidden' and must
807
        be encoded (replaced by escape sequences).  Characters outside the US-
808
        ASCII range are always 'forbidden.'
809
810
        @param eMechanism  See the general discussion for set-methods.
811
812
        @param eCharset  See the general discussion for set-methods.
813
814
        @return  The text, encoded according to the given mechanism and
815
        charset ('forbidden' characters replaced by escape sequences).
816
     */
817
    static OUString encode( std::u16string_view rText, Part ePart,
818
                           EncodeMechanism eMechanism,
819
                           rtl_TextEncoding eCharset
820
                               = RTL_TEXTENCODING_UTF8);
821
822
823
    /** Decode some text.
824
825
        @param rText  Some (encoded) text.
826
827
        @param eMechanism  See the general discussion for get-methods.
828
829
        @param eCharset  See the general discussion for get-methods.
830
831
        @return  The text, decoded according to the given mechanism and
832
        charset (escape sequences replaced by 'raw' characters).
833
     */
834
    static inline OUString decode(std::u16string_view rText,
835
                                   DecodeMechanism eMechanism,
836
                                   rtl_TextEncoding eCharset
837
                                       = RTL_TEXTENCODING_UTF8);
838
839
    static void appendUCS4Escape(OUStringBuffer & rTheText, sal_uInt32 nUCS4);
840
841
    static void appendUCS4(OUStringBuffer & rTheText, sal_uInt32 nUCS4,
842
                           EscapeType eEscapeType, Part ePart,
843
                           rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
844
845
    static sal_uInt32 getUTF32(sal_Unicode const *& rBegin,
846
                               sal_Unicode const * pEnd,
847
                               EncodeMechanism eMechanism,
848
                               rtl_TextEncoding eCharset,
849
                               EscapeType & rEscapeType);
850
851
    // Specialized helpers:
852
853
    static sal_uInt32 scanDomain(sal_Unicode const *& rBegin,
854
                                 sal_Unicode const * pEnd,
855
                                 bool bEager = true);
856
857
    // OBSOLETE Hierarchical Path:
858
859
    OUString GetPartBeforeLastName() const;
860
861
    /** Get the last segment in the path.
862
863
        @param eMechanism  See the general discussion for get-methods.
864
865
        @param eCharset  See the general discussion for get-methods.
866
867
        @return  For a hierarchical URL, the last segment (everything after
868
        the last unencoded '/').  Note that this last segment may be empty.  If
869
        the URL is not hierarchical, an empty string is returned.
870
     */
871
    OUString GetLastName(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
872
                          rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
873
        const;
874
875
    /** Get the 'extension' of the last segment in the path.
876
877
        @return  For a hierarchical URL, everything after the first unencoded
878
        '.' in the last segment of the path.  Note that this 'extension' may
879
        be empty.  If the URL is not hierarchical, or if the last segment does
880
        not contain an unencoded '.', an empty string is returned.
881
     */
882
    OUString GetFileExtension() const;
883
884
    bool Append(std::u16string_view rTheSegment,
885
                       EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
886
                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
887
888
    void CutLastName();
889
890
    // OBSOLETE File URLs:
891
892
    OUString PathToFileName() const;
893
894
    OUString GetFull() const;
895
896
    OUString GetPath() const;
897
898
    void SetBase(std::u16string_view rTheBase);
899
900
    OUString GetBase() const;
901
902
    void SetExtension(std::u16string_view rTheExtension);
903
904
    OUString CutExtension();
905
906
76.7k
    static bool IsCaseSensitive() { return true; }
907
908
    void changeScheme(INetProtocol eTargetScheme);
909
910
    // INetProtocol::Macro, INetProtocol::Uno, INetProtocol::Slot,
911
    // vnd.sun.star.script, etc. All the types of URLs which shouldn't
912
    // be accepted from an outside controlled source
913
    bool IsExoticProtocol() const;
914
915
private:
916
    // General Structure:
917
918
    class SAL_DLLPRIVATE SubString
919
    {
920
        sal_Int32 m_nBegin;
921
        sal_Int32 m_nLength;
922
923
    public:
924
        explicit SubString(sal_Int32 nTheBegin = -1,
925
                                  sal_Int32 nTheLength = 0):
926
23.4M
            m_nBegin(nTheBegin), m_nLength(nTheLength) {}
927
928
2.69M
        bool isPresent() const { return m_nBegin != -1; }
929
930
66.7k
        bool isEmpty() const { return m_nLength == 0; }
931
932
1.34M
        sal_Int32 getBegin() const { return m_nBegin; }
933
934
1.09M
        sal_Int32 getLength() const { return m_nLength; }
935
936
447k
        sal_Int32 getEnd() const { return m_nBegin + m_nLength; }
937
938
        sal_Int32 clear();
939
940
        sal_Int32 set(OUStringBuffer & rString,
941
                      std::u16string_view rSubString,
942
                      sal_Int32 nTheBegin);
943
944
        sal_Int32 set(OUString & rString,
945
                      std::u16string_view rSubString);
946
947
        sal_Int32 set(OUStringBuffer & rString,
948
                      std::u16string_view rSubString);
949
950
        inline void operator +=(sal_Int32 nDelta);
951
952
        int compare(SubString const & rOther,
953
            OUStringBuffer const & rThisString,
954
            OUStringBuffer const & rOtherString) const;
955
    };
956
957
    OUStringBuffer m_aAbsURIRef;
958
    SubString m_aScheme;
959
    SubString m_aUser;
960
    SubString m_aAuth;
961
    SubString m_aHost;
962
    SubString m_aPort;
963
    SubString m_aPath;
964
    SubString m_aQuery;
965
    SubString m_aFragment;
966
    INetProtocol m_eScheme;
967
    INetProtocol m_eSmartScheme;
968
969
    TOOLS_DLLPRIVATE void setInvalid();
970
971
    bool setAbsURIRef(
972
        std::u16string_view rTheAbsURIRef,
973
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bSmart,
974
        FSysStyle eStyle);
975
976
    // Relative URLs:
977
978
    bool convertRelToAbs(
979
        OUString const & rTheRelURIRef,
980
        INetURLObject & rTheAbsURIRef, bool & rWasAbsolute,
981
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
982
        bool bIgnoreFragment, bool bSmart, bool bRelativeNonURIs,
983
        FSysStyle eStyle) const;
984
985
    bool convertAbsToRel(
986
        OUString const & rTheAbsURIRef,
987
        OUString & rTheRelURIRef, EncodeMechanism eEncodeMechanism,
988
        DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset,
989
        FSysStyle eStyle) const;
990
991
    // External URLs:
992
993
    static bool convertIntToExt(
994
        std::u16string_view rTheIntURIRef,
995
        OUString & rTheExtURIRef, DecodeMechanism eDecodeMechanism,
996
        rtl_TextEncoding eCharset);
997
998
    static bool convertExtToInt(
999
        std::u16string_view rTheExtURIRef,
1000
        OUString & rTheIntURIRef, DecodeMechanism eDecodeMechanism,
1001
        rtl_TextEncoding eCharset);
1002
1003
    // Scheme:
1004
1005
    struct PrefixInfo;
1006
1007
    TOOLS_DLLPRIVATE static inline SchemeInfo const & getSchemeInfo(
1008
        INetProtocol eTheScheme);
1009
1010
    TOOLS_DLLPRIVATE inline SchemeInfo const & getSchemeInfo() const;
1011
1012
    TOOLS_DLLPRIVATE static PrefixInfo const * getPrefix(
1013
        sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1014
1015
    // Authority:
1016
1017
    TOOLS_DLLPRIVATE sal_Int32 getAuthorityBegin() const;
1018
1019
    TOOLS_DLLPRIVATE SubString getAuthority() const;
1020
1021
    // User Info:
1022
1023
    bool setUser(
1024
        std::u16string_view rTheUser,
1025
        rtl_TextEncoding eCharset);
1026
1027
    bool clearPassword();
1028
1029
    bool setPassword(
1030
        std::u16string_view rThePassword,
1031
        rtl_TextEncoding eCharset);
1032
1033
    // Host and Port:
1034
1035
    TOOLS_DLLPRIVATE static bool parseHost(
1036
        sal_Unicode const *& rBegin, sal_Unicode const * pEnd,
1037
        OUStringBuffer* pCanonic);
1038
1039
    TOOLS_DLLPRIVATE static bool parseHostOrNetBiosName(
1040
        sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1041
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1042
        bool bNetBiosName, OUStringBuffer* pCanonic);
1043
1044
    // Path:
1045
1046
    TOOLS_DLLPRIVATE static bool parsePath(
1047
        INetProtocol eScheme, sal_Unicode const ** pBegin,
1048
        sal_Unicode const * pEnd, EncodeMechanism eMechanism,
1049
        rtl_TextEncoding eCharset, bool bSkippedInitialSlash,
1050
        sal_uInt32 nSegmentDelimiter, sal_uInt32 nAltSegmentDelimiter,
1051
        sal_uInt32 nQueryDelimiter, sal_uInt32 nFragmentDelimiter,
1052
        OUStringBuffer &rSynPath);
1053
1054
    bool setPath(
1055
        std::u16string_view rThePath,
1056
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1057
1058
    // Hierarchical Path:
1059
1060
    TOOLS_DLLPRIVATE bool checkHierarchical() const;
1061
1062
    TOOLS_DLLPRIVATE SubString getSegment(
1063
        sal_Int32 nIndex, bool bIgnoreFinalSlash) const;
1064
1065
    // Query:
1066
1067
    void clearQuery();
1068
1069
    bool setQuery(
1070
        std::u16string_view rTheQuery,
1071
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1072
1073
    // Fragment:
1074
1075
    bool clearFragment();
1076
1077
    bool setFragment(
1078
        std::u16string_view rTheMark,
1079
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1080
1081
    // FILE URLs:
1082
1083
    TOOLS_DLLPRIVATE bool hasDosVolume(FSysStyle eStyle) const;
1084
1085
    // Coding:
1086
1087
    TOOLS_DLLPRIVATE static inline void appendEscape(
1088
        OUStringBuffer & rTheText, sal_uInt32 nOctet);
1089
1090
    static void encodeText(
1091
        OUStringBuffer& rOutputBuffer,
1092
        sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1093
        Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1094
        bool bKeepVisibleEscapes);
1095
1096
    static inline void encodeText(
1097
        OUStringBuffer& rOutputBuffer,
1098
        std::u16string_view rTheText, Part ePart,
1099
        EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1100
        bool bKeepVisibleEscapes);
1101
1102
    static OUString decode(
1103
        sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1104
        DecodeMechanism, rtl_TextEncoding eCharset);
1105
1106
    inline OUString decode(
1107
        SubString const & rSubString,
1108
        DecodeMechanism eMechanism, rtl_TextEncoding eCharset) const;
1109
1110
    // Specialized helpers:
1111
1112
    TOOLS_DLLPRIVATE static bool scanIPv6reference(
1113
        sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1114
};
1115
1116
// static
1117
inline void INetURLObject::encodeText( OUStringBuffer& rOutputBuffer,
1118
                                           std::u16string_view rTheText,
1119
                                           Part ePart,
1120
                                           EncodeMechanism eMechanism,
1121
                                           rtl_TextEncoding eCharset,
1122
                                           bool bKeepVisibleEscapes)
1123
19.0k
{
1124
19.0k
    encodeText(rOutputBuffer,
1125
19.0k
                rTheText.data(),
1126
19.0k
                rTheText.data() + rTheText.size(), ePart,
1127
19.0k
                eMechanism, eCharset, bKeepVisibleEscapes);
1128
19.0k
}
1129
1130
inline OUString INetURLObject::decode(SubString const & rSubString,
1131
                                       DecodeMechanism eMechanism,
1132
                                       rtl_TextEncoding eCharset) const
1133
21.5k
{
1134
21.5k
    return rSubString.isPresent() ?
1135
21.2k
               decode(m_aAbsURIRef.getStr() + rSubString.getBegin(),
1136
21.2k
                      m_aAbsURIRef.getStr() + rSubString.getEnd(),
1137
21.2k
                      eMechanism, eCharset) :
1138
21.5k
               OUString();
1139
21.5k
}
1140
1141
inline INetURLObject::INetURLObject(std::u16string_view rTheAbsURIRef,
1142
                                    EncodeMechanism eMechanism,
1143
                                    rtl_TextEncoding eCharset):
1144
1.19M
    m_aAbsURIRef(rTheAbsURIRef.size() * 2), m_eScheme(INetProtocol::NotValid), m_eSmartScheme(INetProtocol::Http)
1145
1.19M
{
1146
1.19M
    setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, false,
1147
1.19M
                 FSysStyle(0));
1148
1.19M
}
1149
1150
inline bool INetURLObject::SetURL(std::u16string_view rTheAbsURIRef,
1151
                                  EncodeMechanism eMechanism,
1152
                                  rtl_TextEncoding eCharset)
1153
114k
{
1154
114k
    return setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, false,
1155
114k
                        FSysStyle(0));
1156
114k
}
1157
1158
inline INetURLObject::INetURLObject(std::u16string_view rTheAbsURIRef,
1159
                                    INetProtocol eTheSmartScheme,
1160
                                    EncodeMechanism eMechanism,
1161
                                    rtl_TextEncoding eCharset,
1162
                                    FSysStyle eStyle):
1163
330
    m_eScheme(INetProtocol::NotValid), m_eSmartScheme(eTheSmartScheme)
1164
330
{
1165
330
    setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, true, eStyle);
1166
330
}
1167
1168
inline bool INetURLObject::SetSmartURL(std::u16string_view rTheAbsURIRef,
1169
                                       EncodeMechanism eMechanism,
1170
                                       rtl_TextEncoding eCharset,
1171
                                       FSysStyle eStyle)
1172
536k
{
1173
536k
    return setAbsURIRef(rTheAbsURIRef, eMechanism, eCharset, true,
1174
536k
                        eStyle);
1175
536k
}
1176
1177
inline INetURLObject
1178
INetURLObject::smartRel2Abs(OUString const & rTheRelURIRef,
1179
                            bool & rWasAbsolute,
1180
                            bool bIgnoreFragment,
1181
                            EncodeMechanism eMechanism,
1182
                            rtl_TextEncoding eCharset,
1183
                            bool bRelativeNonURIs,
1184
                            FSysStyle eStyle) const
1185
333k
{
1186
333k
    INetURLObject aTheAbsURIRef;
1187
333k
    convertRelToAbs(rTheRelURIRef, aTheAbsURIRef, rWasAbsolute,
1188
333k
                    eMechanism, eCharset, bIgnoreFragment, true,
1189
333k
                    bRelativeNonURIs, eStyle);
1190
333k
    return aTheAbsURIRef;
1191
333k
}
1192
1193
inline bool INetURLObject::GetNewAbsURL(OUString const & rTheRelURIRef,
1194
                                        INetURLObject * pTheAbsURIRef)
1195
    const
1196
63.6k
{
1197
63.6k
    INetURLObject aTheAbsURIRef;
1198
63.6k
    bool bWasAbsolute;
1199
63.6k
    if (!convertRelToAbs(rTheRelURIRef, aTheAbsURIRef, bWasAbsolute,
1200
63.6k
                         EncodeMechanism::WasEncoded, RTL_TEXTENCODING_UTF8, false/*bIgnoreFragment*/, false, false,
1201
63.6k
                         FSysStyle::Detect))
1202
58.8k
        return false;
1203
4.71k
    if (pTheAbsURIRef)
1204
4.71k
        *pTheAbsURIRef = std::move(aTheAbsURIRef);
1205
4.71k
    return true;
1206
63.6k
}
1207
1208
// static
1209
inline OUString INetURLObject::GetRelURL(std::u16string_view rTheBaseURIRef,
1210
                                          OUString const & rTheAbsURIRef,
1211
                                          EncodeMechanism eEncodeMechanism,
1212
                                          DecodeMechanism eDecodeMechanism,
1213
                                          rtl_TextEncoding eCharset,
1214
                                          FSysStyle eStyle)
1215
0
{
1216
0
    OUString aTheRelURIRef;
1217
0
    INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
1218
0
        convertAbsToRel(rTheAbsURIRef, aTheRelURIRef, eEncodeMechanism,
1219
0
                        eDecodeMechanism, eCharset, eStyle);
1220
0
    return aTheRelURIRef;
1221
0
}
1222
1223
// static
1224
inline bool INetURLObject::translateToExternal(std::u16string_view
1225
                                                   rTheIntURIRef,
1226
                                               OUString & rTheExtURIRef,
1227
                                               DecodeMechanism
1228
                                                   eDecodeMechanism,
1229
                                               rtl_TextEncoding eCharset)
1230
0
{
1231
0
    return convertIntToExt(rTheIntURIRef, rTheExtURIRef,
1232
0
                           eDecodeMechanism, eCharset);
1233
0
}
1234
1235
// static
1236
inline bool INetURLObject::translateToInternal(std::u16string_view
1237
                                                   rTheExtURIRef,
1238
                                               OUString & rTheIntURIRef,
1239
                                               DecodeMechanism
1240
                                                   eDecodeMechanism,
1241
                                               rtl_TextEncoding eCharset)
1242
0
{
1243
0
    return convertExtToInt(rTheExtURIRef, rTheIntURIRef,
1244
0
                           eDecodeMechanism, eCharset);
1245
0
}
1246
1247
inline bool INetURLObject::SetParam(std::u16string_view rTheQuery,
1248
                                    EncodeMechanism eMechanism,
1249
                                    rtl_TextEncoding eCharset)
1250
58
{
1251
58
    if (rTheQuery.empty())
1252
58
    {
1253
58
        clearQuery();
1254
58
        return false;
1255
58
    }
1256
0
    return setQuery(rTheQuery, eMechanism, eCharset);
1257
58
}
1258
1259
inline bool INetURLObject::SetMark(std::u16string_view rTheFragment,
1260
                                   EncodeMechanism eMechanism,
1261
                                   rtl_TextEncoding eCharset)
1262
40.8k
{
1263
40.8k
    return rTheFragment.empty() ?
1264
35.4k
               clearFragment() :
1265
40.8k
               setFragment(rTheFragment, eMechanism, eCharset);
1266
40.8k
}
1267
1268
// static
1269
inline OUString INetURLObject::encode(std::u16string_view rText, Part ePart,
1270
                                   EncodeMechanism eMechanism,
1271
                                   rtl_TextEncoding eCharset)
1272
59
{
1273
59
    OUStringBuffer aBuf;
1274
59
    encodeText(aBuf, rText, ePart, eMechanism, eCharset, false);
1275
59
    return aBuf.makeStringAndClear();
1276
59
}
1277
1278
// static
1279
inline OUString INetURLObject::decode(std::u16string_view rText,
1280
                                       DecodeMechanism eMechanism,
1281
                                       rtl_TextEncoding eCharset)
1282
891k
{
1283
891k
    return decode(rText.data(), rText.data() + rText.size(),
1284
891k
                  eMechanism, eCharset);
1285
891k
}
1286
1287
#endif
1288
1289
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */