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{
20 inline std::filesystem::path to_path(const std::string& s)
21 {
22#ifdef OPENMS_WINDOWSPLATFORM
23 try
24 {
25 return std::filesystem::path(std::u8string(reinterpret_cast<const char8_t*>(s.data()), s.size()));
26 }
27 catch (const std::system_error&)
28 {
29 // Not valid UTF-8 (e.g., ANSI-encoded filename from argv); let Windows use the current code page.
30 return std::filesystem::path(s);
31 }
32#else
33 return std::filesystem::path(std::u8string(reinterpret_cast<const char8_t*>(s.data()), s.size()));
34#endif
35 }
36} // 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:20