Mantid
Loading...
Searching...
No Matches
ICatalogInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <boost/algorithm/string.hpp>
9#include <boost/regex.hpp>
10
11namespace Mantid::Kernel {
12
13std::string ICatalogInfo::transformArchivePath(const std::string &path) const {
14 std::string ret;
15#ifdef __linux__
16 ret = replacePrefix(path, catalogPrefix(), linuxPrefix());
17 ret = replaceAllOccurences(ret, "\\", "/");
18#elif __APPLE__
19 ret = replacePrefix(path, catalogPrefix(), macPrefix());
20 ret = replaceAllOccurences(ret, "\\", "/");
21#elif _WIN32
22 // Check to see if path is a windows path.
23 if (path.find("\\") == std::string::npos) {
24 ret = replacePrefix(path, linuxPrefix(), windowsPrefix());
25 ret = replaceAllOccurences(ret, "/", "\\");
26 } else {
28 }
29#endif
30 return ret;
31}
32
40std::string ICatalogInfo::replacePrefix(const std::string &path, const std::string &regex,
41 const std::string &prefix) const {
42 boost::regex re(regex);
43 // Assign the result of the replacement back to path and return it.
44 return boost::regex_replace(path, re, prefix);
45}
46
55std::string ICatalogInfo::replaceAllOccurences(const std::string &path, const std::string &search,
56 const std::string &format) const {
57
58 return boost::replace_all_copy(path, search, format);
59}
60
61} // namespace Mantid::Kernel
virtual std::string transformArchivePath(const std::string &path) const
Transform's the archive path based on operating system used.
std::string replaceAllOccurences(const std::string &path, const std::string &search, const std::string &format) const
Replace all occurrences of the search string in the input with the format string.
virtual const std::string linuxPrefix() const =0
Obtain Linux prefix from facility file.
virtual const std::string macPrefix() const =0
Obtain Macintosh prefix from facility file.
virtual const std::string windowsPrefix() const =0
Obtain Windows prefix from the facility file.
virtual const std::string catalogPrefix() const =0
Obtain the regex prefix from the facility file.
std::string replacePrefix(const std::string &path, const std::string &regex, const std::string &prefix) const
Replace the content of a string using regex.