3#include <c++utilities/conversion/stringconversion.h>
27 m_file.exceptions(ios_base::failbit | ios_base::badbit);
36 : m_path(std::move(path))
40 m_file.exceptions(ios_base::failbit | ios_base::badbit);
53 m_file.exceptions(ios_base::failbit | ios_base::badbit);
88 pathForOpen(
path()).data(), (m_readOnly = readOnly) ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary);
89 m_file.seekg(0, ios_base::end);
90 m_size =
static_cast<std::uint64_t
>(m_file.tellg());
91 m_file.seekg(0, ios_base::beg);
122 if (
path != m_path) {
137 if (
path != m_path) {
151 const auto lastSlash =
path.rfind(
'/');
152 const auto lastBackSlash =
path.rfind(
'\\');
153 const auto lastPoint = cutExtension ?
path.rfind(
'.') : string::npos;
154 auto lastSeparator =
decltype(lastSlash)();
155 if (lastSlash == string::npos && lastBackSlash == string::npos) {
156 return std::string(lastPoint == string::npos ?
path :
path.substr(0, lastPoint));
157 }
else if (lastSlash == string::npos) {
158 lastSeparator = lastBackSlash;
159 }
else if (lastBackSlash == string::npos) {
160 lastSeparator = lastSlash;
162 lastSeparator = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
164 return std::string(lastPoint != string::npos ?
path.substr(lastSeparator + 1, lastPoint - lastSeparator - 1) :
path.substr(lastSeparator + 1));
174 return fileName(m_path, cutExtension);
184 const auto lastPoint =
path.rfind(
'.');
185 if (lastPoint == std::string::npos) {
186 return std::string();
188 return std::string(
path.data() + lastPoint,
path.size() - lastPoint);
205 const auto lastPoint = fullPath.rfind(
'.');
206 return std::string(lastPoint != std::string::npos ? fullPath.substr(0, lastPoint) : fullPath);
222 const auto lastSlash =
path.rfind(
'/');
223 const auto lastBackSlash =
path.rfind(
'\\');
224 auto lastSeparator =
decltype(lastSlash)();
225 if (lastSlash == string::npos && lastBackSlash == std::string::npos) {
226 return std::string();
227 }
else if (lastSlash == string::npos) {
228 lastSeparator = lastBackSlash;
229 }
else if (lastBackSlash == string::npos) {
230 lastSeparator = lastSlash;
232 lastSeparator = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
234 if (lastSeparator > 0) {
235 return std::string(
path.substr(0, lastSeparator));
237 return std::string();
BasicFileInfo()
Constructs a new BasicFileInfo for the specified file.
std::string containingDirectory() const
Returns the path of the directory containing the current file.
static std::string fileName(std::string_view path, bool cutExtension=false)
Returns the file name of the given file.
void invalidate()
Invalidates the file info manually.
const std::string & path() const
Returns the path of the current file.
void reopen(bool readOnly=false)
Opens a std::fstream for the current file.
virtual void invalidated()
This function is called when the BasicFileInfo gets invalidated.
std::string pathWithoutExtension() const
Returns the path of the current file without the extension/suffix.
void open(bool readOnly=false)
Opens a std::fstream for the current file.
void close()
A possibly opened std::fstream will be closed.
static std::string_view pathForOpen(std::string_view url)
Returns removes the "file:/" prefix from url to be able to pass it to functions like open(),...
virtual ~BasicFileInfo()
Destroys the BasicFileInfo.
std::string extension() const
Returns the extension of the current file.
bool isOpen() const
Indicates whether a std::fstream is open for the current file.
void setPath(std::string_view path)
Sets the current file.
Contains all classes and functions of the TagInfo library.