Line data Source code
1 : /*! 2 : * \file esys/repo/git/url_git.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2022 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/git/url.h" 20 : 21 : #include <Poco/URI.h> 22 : 23 : namespace esys::repo::git 24 : { 25 : 26 0 : URL::URL() = default; 27 : 28 6 : URL::URL(const std::string &url) 29 6 : : m_url(url) 30 : { 31 6 : } 32 : 33 6 : URL::~URL() = default; 34 : 35 0 : void URL::set(const std::string &url) 36 : { 37 0 : m_url = url; 38 0 : } 39 : 40 6 : const std::string &URL::get() const 41 : { 42 6 : return m_url; 43 : } 44 : 45 12 : void URL::remove_dot_git(std::string &text) 46 : { 47 12 : auto idx = text.rfind(".git"); 48 12 : if (idx == text.npos) return; 49 : 50 7 : text = text.substr(0, idx); 51 : } 52 : 53 0 : bool URL::operator==(const URL &url) const 54 : { 55 0 : return operator==(url.get()); 56 : } 57 : 58 6 : bool URL::operator==(const std::string &url) const 59 : { 60 6 : std::string url_ = url; 61 6 : std::string this_url = get(); 62 : 63 6 : remove_dot_git(url_); 64 6 : remove_dot_git(this_url); 65 : 66 6 : Poco::URI uri(url_); 67 6 : Poco::URI this_uri(this_url); 68 : 69 12 : if ((this_uri.getAuthority() == uri.getAuthority()) && (this_uri.getPath() == uri.getPath())) return true; 70 4 : if ((this_uri.getHost() == uri.getHost()) && (this_uri.getPath() == uri.getPath())) return true; 71 : 72 : return false; 73 6 : } 74 : 75 0 : bool URL::operator!=(const URL &url) const 76 : { 77 0 : return !operator==(url); 78 : } 79 : 80 1 : bool URL::operator!=(const std::string &url) const 81 : { 82 1 : return !operator==(url); 83 : } 84 : 85 : } // namespace esys::repo::git