LibreOffice Module tools (master) 1
urlobj.hxx
Go to the documentation of this file.
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>
27
28#include <memory>
29#include <string_view>
30
31class SvMemoryStream;
32
33namespace com::sun::star::util {
34 class XStringWidth;
35}
36
37namespace com::sun::star::uno { template <typename > class Reference; }
38
39// Common URL prefixes for various schemes:
40inline constexpr OUStringLiteral INET_FTP_SCHEME = u"ftp://";
41inline constexpr OUStringLiteral INET_HTTP_SCHEME = u"http://";
42inline constexpr OUStringLiteral INET_HTTPS_SCHEME = u"https://";
43inline constexpr OUStringLiteral INET_FILE_SCHEME = u"file://";
44inline constexpr OUStringLiteral INET_MAILTO_SCHEME = u"mailto:";
45inline constexpr OUStringLiteral INET_HID_SCHEME = u"hid:";
46
47#define URL_PREFIX_PRIV_SOFFICE "private:"
48
49// Schemes:
50enum class INetProtocol
51{
53 Ftp,
54 Http,
55 File,
56 Mailto,
60 Https,
61 Slot,
62 Macro,
64 Data,
65 Cid,
67 Uno,
70 Ldap,
71 Db,
73 Telnet,
76 Generic,
77 Smb,
78 Hid,
79 Sftp,
80 Cmis,
81 LAST = Cmis
82};
83
86enum class FSysStyle
87{
90 Vos = 0x1,
91
94 Unix = 0x2,
95
98 Dos = 0x4,
99
173 Detect = Vos | Unix | Dos
174};
175namespace o3tl {
176 template<> struct typed_flags<FSysStyle> : is_typed_flags<FSysStyle, 0x07> {};
177}
178
180{
181public:
182 // Get- and Set-Methods:
183
195 {
199 All,
200
208 WasEncoded,
209
213 NotCanonical
214 };
215
224 {
229 NONE,
230
236 ToIUri,
237
243 WithCharset,
244
252 Unambiguous
253 };
254
255 // General Structure:
256
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,
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,
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
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,
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
391 bool isAnyKnownWebDAVScheme() const;
392
399 static OUString GetScheme(INetProtocol eTheScheme);
400
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
475 enum { LAST_SEGMENT = -1 };
476
500 sal_Int32 getSegmentCount(bool bIgnoreFinalSlash = true) const;
501
515 bool removeSegment(sal_Int32 nIndex = LAST_SEGMENT,
516 bool bIgnoreFinalSlash = true);
517
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
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
585 bool setName(std::u16string_view rTheName,
586 EncodeMechanism eMechanism = EncodeMechanism::WasEncoded,
587 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
588
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
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
640 bool hasExtension() const;
641
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
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
701 bool removeExtension(sal_Int32 nIndex = LAST_SEGMENT,
702 bool bIgnoreFinalSlash = true);
703
709 bool hasFinalSlash() const;
710
719 bool setFinalSlash();
720
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
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
825 static OUString encode( std::u16string_view rText, Part ePart,
826 EncodeMechanism eMechanism,
827 rtl_TextEncoding eCharset
828 = RTL_TEXTENCODING_UTF8);
829
830
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
879 OUString GetLastName(DecodeMechanism eMechanism = DecodeMechanism::ToIUri,
880 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
881 const;
882
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
918private:
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;
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
1124inline 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
1137inline 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
1148inline 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
1157inline 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
1165inline 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
1175inline 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
1184inline INetURLObject
1185INetURLObject::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
1200inline 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,
1209 return false;
1210 if (pTheAbsURIRef)
1211 *pTheAbsURIRef = aTheAbsURIRef;
1212 return true;
1213}
1214
1215// static
1216inline 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
1231inline bool INetURLObject::translateToExternal(std::u16string_view
1232 rTheIntURIRef,
1233 OUString & rTheExtURIRef,
1235 eDecodeMechanism,
1236 rtl_TextEncoding eCharset)
1237{
1238 return convertIntToExt(rTheIntURIRef, rTheExtURIRef,
1239 eDecodeMechanism, eCharset);
1240}
1241
1242// static
1243inline bool INetURLObject::translateToInternal(std::u16string_view
1244 rTheExtURIRef,
1245 OUString & rTheIntURIRef,
1247 eDecodeMechanism,
1248 rtl_TextEncoding eCharset)
1249{
1250 return convertExtToInt(rTheExtURIRef, rTheIntURIRef,
1251 eDecodeMechanism, eCharset);
1252}
1253
1254inline bool INetURLObject::SetPass(std::u16string_view rThePassword)
1255{
1256 return rThePassword.empty() ?
1257 clearPassword() :
1258 setPassword(rThePassword, RTL_TEXTENCODING_UTF8);
1259}
1260
1261inline 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
1270inline 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
1282inline 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
1292inline 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
1302inline 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: */
const sal_Int32 m_nLength
bool operator==(const BigInt &rVal1, const BigInt &rVal2)
Definition: bigint.cxx:806
sal_Int32 getEnd() const
Definition: urlobj.hxx:939
SubString(sal_Int32 nTheBegin=-1, sal_Int32 nTheLength=0)
Definition: urlobj.hxx:927
sal_Int32 getLength() const
Definition: urlobj.hxx:937
bool isPresent() const
Definition: urlobj.hxx:931
bool isEmpty() const
Definition: urlobj.hxx:933
sal_Int32 getBegin() const
Definition: urlobj.hxx:935
SubString m_aPath
Definition: urlobj.hxx:966
bool SetPass(std::u16string_view rThePassword)
Definition: urlobj.hxx:1254
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Decode some text.
Definition: urlobj.hxx:1302
void SetSmartProtocol(INetProtocol eTheSmartScheme)
Definition: urlobj.hxx:311
bool clearFragment()
Definition: urlobj.cxx:3403
DecodeMechanism
The way strings that represent (parts of) URIs are returned from get- methods.
Definition: urlobj.hxx:224
INetProtocol m_eSmartScheme
Definition: urlobj.hxx:970
static bool translateToInternal(std::u16string_view rTheExtURIRef, OUString &rTheIntURIRef, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Definition: urlobj.hxx:1243
SubString m_aHost
Definition: urlobj.hxx:964
bool setAbsURIRef(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bSmart, FSysStyle eStyle)
Definition: urlobj.cxx:725
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:262
INetProtocol m_eScheme
Definition: urlobj.hxx:969
bool HasURLPath() const
Definition: urlobj.hxx:454
SubString m_aScheme
Definition: urlobj.hxx:961
bool setPassword(std::u16string_view rThePassword, rtl_TextEncoding eCharset)
Definition: urlobj.cxx:2338
SubString m_aUser
Definition: urlobj.hxx:962
SubString m_aFragment
Definition: urlobj.hxx:968
static bool translateToExternal(std::u16string_view rTheIntURIRef, OUString &rTheExtURIRef, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Definition: urlobj.hxx:1231
INetURLObject smartRel2Abs(OUString const &rTheRelURIRef, bool &rWasAbsolute, bool bIgnoreFragment=false, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect) const
Definition: urlobj.hxx:1185
static bool convertIntToExt(std::u16string_view rTheIntURIRef, OUString &rTheExtURIRef, DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset)
Definition: urlobj.cxx:2079
bool HasError() const
Definition: urlobj.hxx:260
static bool convertExtToInt(std::u16string_view rTheExtURIRef, OUString &rTheIntURIRef, DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset)
Definition: urlobj.cxx:2102
bool convertRelToAbs(OUString const &rTheRelURIRef, INetURLObject &rTheAbsURIRef, bool &rWasAbsolute, EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bIgnoreFragment, bool bSmart, bool bRelativeNonURIs, FSysStyle eStyle) const
Definition: urlobj.cxx:1523
OUString GetMark(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:746
bool clearPassword()
Definition: urlobj.cxx:2320
bool setUser(std::u16string_view rTheUser, rtl_TextEncoding eCharset)
Definition: urlobj.cxx:2277
OUStringBuffer m_aAbsURIRef
Definition: urlobj.hxx:960
SubString m_aPort
Definition: urlobj.hxx:965
bool GetNewAbsURL(OUString const &rTheRelURIRef, INetURLObject *pTheAbsURIRef) const
Definition: urlobj.hxx:1200
OUString GetPass(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:420
SubString m_aQuery
Definition: urlobj.hxx:967
bool HasUserData() const
Definition: urlobj.hxx:413
bool HasParam() const
Definition: urlobj.hxx:732
bool SetSmartURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
Definition: urlobj.hxx:1175
bool HasPort() const
Definition: urlobj.hxx:435
static void encodeText(OUStringBuffer &rOutputBuffer, sal_Unicode const *pBegin, sal_Unicode const *pEnd, Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bKeepVisibleEscapes)
Definition: urlobj.cxx:3446
OUString GetUser(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:415
bool SetHost(std::u16string_view rTheHost)
Definition: urlobj.hxx:447
void clearQuery()
Definition: urlobj.cxx:3369
bool HasMark() const
Definition: urlobj.hxx:744
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:456
bool setFragment(std::u16string_view rTheMark, EncodeMechanism eMechanism, rtl_TextEncoding eCharset)
Definition: urlobj.cxx:3415
static bool IsCaseSensitive()
Definition: urlobj.hxx:914
OUString GetParam(rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:734
OUString GetHost(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
Definition: urlobj.hxx:437
bool SetURLPath(std::u16string_view rThePath, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Definition: urlobj.hxx:461
static OUString GetRelURL(std::u16string_view rTheBaseURIRef, OUString const &rTheAbsURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
Definition: urlobj.hxx:1216
bool convertAbsToRel(OUString const &rTheAbsURIRef, OUString &rTheRelURIRef, EncodeMechanism eEncodeMechanism, DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset, FSysStyle eStyle) const
Definition: urlobj.cxx:1921
INetProtocol GetProtocol() const
Definition: urlobj.hxx:380
bool SetMark(std::u16string_view rTheFragment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Definition: urlobj.hxx:1282
bool setQuery(std::u16string_view rTheQuery, EncodeMechanism eMechanism, rtl_TextEncoding eCharset)
Definition: urlobj.cxx:3381
bool SetParam(std::u16string_view rTheQuery, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Definition: urlobj.hxx:1270
SubString m_aAuth
Definition: urlobj.hxx:963
EncodeMechanism
The way input strings that represent (parts of) URIs are interpreted in set-methods.
Definition: urlobj.hxx:195
@ WasEncoded
Sequences of escape sequences, that represent characters from the specified character set and that ca...
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Definition: urlobj.hxx:1157
bool isSchemeEqualTo(INetProtocol scheme) const
Definition: urlobj.hxx:382
bool SetUser(std::u16string_view rTheUser)
Definition: urlobj.hxx:425
bool SetUserAndPass(std::u16string_view rTheUser, std::u16string_view rThePassword)
Definition: urlobj.hxx:1261
static OUString encode(std::u16string_view rText, Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Encode some text as part of a URI.
Definition: urlobj.hxx:1292
virtual OUString GetPath() const override
float u
bool operator!=(const Fraction &rVal1, const Fraction &rVal2)
Definition: fract.cxx:340
aBuf
NONE
size
void set(css::uno::UnoInterfaceReference const &value)
Reference
EscapeType
SbxDecimal::CmpResult compare(SAL_UNUSED_PARAMETER const SbxDecimal &, SAL_UNUSED_PARAMETER const SbxDecimal &)
tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
Definition: svborder.cxx:22
#define TOOLS_DLLPRIVATE
Definition: toolsdllapi.h:30
#define TOOLS_DLLPUBLIC
Definition: toolsdllapi.h:28
::std::pair< MetaAction *, int > Component
sal_uInt16 sal_Unicode
#define SAL_WARN_UNUSED
constexpr OUStringLiteral INET_MAILTO_SCHEME
Definition: urlobj.hxx:44
constexpr OUStringLiteral INET_HTTP_SCHEME
Definition: urlobj.hxx:41
INetProtocol
Definition: urlobj.hxx:51
constexpr OUStringLiteral INET_HID_SCHEME
Definition: urlobj.hxx:45
constexpr OUStringLiteral INET_FILE_SCHEME
Definition: urlobj.hxx:43
constexpr OUStringLiteral INET_HTTPS_SCHEME
Definition: urlobj.hxx:42
constexpr OUStringLiteral INET_FTP_SCHEME
Definition: urlobj.hxx:40
FSysStyle
The supported notations for file system paths.
Definition: urlobj.hxx:87
@ Detect
Detect the used notation.
@ Unix
Unix notation (e.g., "/dir/file").
@ Dos
DOS notation (e.g., "a:\dir\file" and "\\server\dir\file").
@ Vos
VOS notation (e.g., "//server/dir/file").