mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-04-21 19:08:41 +00:00
chore: use namespace for FileUtils
This commit is contained in:
@@ -2,62 +2,67 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
bool FileUtils::ParsePathsString(const std::string& pathsString, std::set<std::string>& output)
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::ostringstream currentPath;
|
||||
auto pathStart = true;
|
||||
auto quotationPos = 0; // 0 = before quotations, 1 = in quotations, 2 = after quotations
|
||||
|
||||
for (auto character : pathsString)
|
||||
bool ParsePathsString(const std::string& pathsString, std::set<std::string>& output)
|
||||
{
|
||||
switch (character)
|
||||
std::ostringstream currentPath;
|
||||
auto pathStart = true;
|
||||
auto quotationPos = 0; // 0 = before quotations, 1 = in quotations, 2 = after quotations
|
||||
|
||||
for (const auto character : pathsString)
|
||||
{
|
||||
case '"':
|
||||
if (quotationPos == 0 && pathStart)
|
||||
switch (character)
|
||||
{
|
||||
quotationPos = 1;
|
||||
}
|
||||
else if (quotationPos == 1)
|
||||
{
|
||||
quotationPos = 2;
|
||||
pathStart = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case ';':
|
||||
if (quotationPos != 1)
|
||||
{
|
||||
auto path = currentPath.str();
|
||||
if (!path.empty())
|
||||
case '"':
|
||||
if (quotationPos == 0 && pathStart)
|
||||
{
|
||||
output.insert(path);
|
||||
currentPath = std::ostringstream();
|
||||
quotationPos = 1;
|
||||
}
|
||||
else if (quotationPos == 1)
|
||||
{
|
||||
quotationPos = 2;
|
||||
pathStart = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
pathStart = true;
|
||||
quotationPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
case ';':
|
||||
if (quotationPos != 1)
|
||||
{
|
||||
auto path = currentPath.str();
|
||||
if (!path.empty())
|
||||
{
|
||||
output.insert(path);
|
||||
currentPath = std::ostringstream();
|
||||
}
|
||||
|
||||
pathStart = true;
|
||||
quotationPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPath << character;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
currentPath << character;
|
||||
pathStart = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
currentPath << character;
|
||||
pathStart = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPath.tellp() > 0)
|
||||
{
|
||||
output.insert(currentPath.str());
|
||||
}
|
||||
if (currentPath.tellp() > 0)
|
||||
{
|
||||
output.insert(currentPath.str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace utils
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
class FileUtils
|
||||
namespace utils
|
||||
{
|
||||
public:
|
||||
static constexpr uint32_t MakeMagic32(const char ch0, const char ch1, const char ch2, const char ch3)
|
||||
{
|
||||
return static_cast<uint32_t>(ch0) | static_cast<uint32_t>(ch1) << 8 | static_cast<uint32_t>(ch2) << 16 | static_cast<uint32_t>(ch3) << 24;
|
||||
@@ -18,5 +20,5 @@ public:
|
||||
* \param output A set for strings to save the output to.
|
||||
* \return \c true if the user input was valid and could be processed successfully, otherwise \c false.
|
||||
*/
|
||||
static bool ParsePathsString(const std::string& pathsString, std::set<std::string>& output);
|
||||
};
|
||||
bool ParsePathsString(const std::string& pathsString, std::set<std::string>& output);
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user