url_mapper.h 836 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include <library/cpp/regex/pcre/regexp.h>
  3. #include <util/generic/vector.h>
  4. namespace NYql {
  5. class TUrlMapper {
  6. public:
  7. void AddMapping(const TString& pattern, const TString& targetUrl);
  8. bool MapUrl(const TString& url, TString& mappedUrl) const;
  9. private:
  10. struct TCustomScheme {
  11. TCustomScheme(const TString& pattern, const TString& url)
  12. : Pattern(pattern)
  13. , TargetUrlHolder(url)
  14. , TargetUrlSubst(pattern.data()) {
  15. if (0 == TargetUrlSubst.ParseReplacement(TargetUrlHolder.data())) {
  16. ythrow yexception() << "Bad url replacement: " << TargetUrlHolder;
  17. }
  18. }
  19. TRegExMatch Pattern;
  20. TString TargetUrlHolder;
  21. TRegExSubst TargetUrlSubst;
  22. };
  23. private:
  24. TVector<TCustomScheme> CustomSchemes;
  25. };
  26. }