OpenMS
Loading...
Searching...
No Matches
PathUtils.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <filesystem>
12#include <string>
13
14namespace OpenMS
15{
24 inline std::filesystem::path to_path(const std::string& s)
25 {
26#ifdef _WIN32
27 try
28 {
29 return std::filesystem::path(std::u8string(reinterpret_cast<const char8_t*>(s.data()), s.size()));
30 }
31 catch (const std::system_error&)
32 {
33 // Not valid UTF-8 (e.g., ANSI-encoded filename from argv); let Windows use the current code page.
34 return std::filesystem::path(s);
35 }
36#else
37 return std::filesystem::path(std::u8string(reinterpret_cast<const char8_t*>(s.data()), s.size()));
38#endif
39 }
40} // namespace OpenMS
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::filesystem::path to_path(const std::string &s)
Definition PathUtils.h:24