tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

URLPatternGlue.h (2826B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef URLPatternGlue_h__
      6 #define URLPatternGlue_h__
      7 
      8 #include "mozilla/net/urlpattern_glue.h"
      9 #include "nsTHashMap.h"
     10 #include "mozilla/Maybe.h"
     11 #include "mozilla/Logging.h"
     12 
     13 extern mozilla::LazyLogModule gUrlPatternLog;
     14 
     15 namespace mozilla::net {
     16 
     17 UrlpInput CreateUrlpInput(const nsACString& url);
     18 UrlpInput CreateUrlpInput(const UrlpInit& init);
     19 
     20 MaybeString CreateMaybeString(const nsACString& str, bool valid);
     21 MaybeString CreateMaybeStringNone();
     22 
     23 class UrlpComponentResult {
     24 public:
     25  UrlpComponentResult() = default;
     26  UrlpComponentResult(const UrlpComponentResult& aOther)
     27      : mInput(aOther.mInput) {
     28    for (auto iter = aOther.mGroups.ConstIter(); !iter.Done(); iter.Next()) {
     29      mGroups.InsertOrUpdate(iter.Key(), iter.Data());
     30    }
     31  }
     32  UrlpComponentResult(
     33      UrlpComponentResult&& aOther) noexcept  // move constructor
     34      : mInput(std::move(aOther.mInput)), mGroups(std::move(aOther.mGroups)) {}
     35  UrlpComponentResult& operator=(
     36      UrlpComponentResult&& aOther) noexcept {  // move assignment
     37    if (this != &aOther) {
     38      mInput = std::move(aOther.mInput);
     39      mGroups = std::move(aOther.mGroups);
     40    }
     41    return *this;
     42  }
     43 
     44  nsAutoCString mInput;
     45  nsTHashMap<nsCStringHashKey, MaybeString> mGroups;
     46 };
     47 
     48 class UrlpResult {
     49 public:
     50  UrlpResult() = default;
     51  Maybe<UrlpComponentResult> mProtocol;
     52  Maybe<UrlpComponentResult> mUsername;
     53  Maybe<UrlpComponentResult> mPassword;
     54  Maybe<UrlpComponentResult> mHostname;
     55  Maybe<UrlpComponentResult> mPort;
     56  Maybe<UrlpComponentResult> mPathname;
     57  Maybe<UrlpComponentResult> mSearch;
     58  Maybe<UrlpComponentResult> mHash;
     59  CopyableTArray<UrlpInput> mInputs;
     60 };
     61 
     62 Maybe<UrlpResult> UrlpPatternExec(UrlpPattern aPattern, const UrlpInput& aInput,
     63                                  Maybe<nsAutoCString> aMaybeBaseUrl,
     64                                  bool aIgnoreCase = false);
     65 
     66 bool UrlpPatternTest(UrlpPattern aPattern, const UrlpInput& aInput,
     67                     Maybe<nsAutoCString> aMaybeBaseUrl,
     68                     bool aIgnoreCase = false);
     69 
     70 nsAutoCString UrlpGetProtocol(const UrlpPattern aPatternWrapper);
     71 nsAutoCString UrlpGetUsername(const UrlpPattern aPatternWrapper);
     72 nsAutoCString UrlpGetPassword(const UrlpPattern aPatternWrapper);
     73 nsAutoCString UrlpGetHostname(const UrlpPattern aPatternWrapper);
     74 nsAutoCString UrlpGetPort(const UrlpPattern aPatternWrapper);
     75 nsAutoCString UrlpGetPathname(const UrlpPattern aPatternWrapper);
     76 nsAutoCString UrlpGetSearch(const UrlpPattern aPatternWrapper);
     77 nsAutoCString UrlpGetHash(const UrlpPattern aPatternWrapper);
     78 
     79 }  // namespace mozilla::net
     80 
     81 #endif  // URLPatternGlue_h__