mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 00:08:26 -05:00
Use new helper functions ParseAsArray and ParseAsPairs of InfoStringToStructConverterBase to parse notetracksoundmap and hidetags
This commit is contained in:
@ -11,6 +11,95 @@ InfoStringToStructConverterBase::InfoStringToStructConverterBase(const InfoStrin
|
||||
{
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverterBase::ParseAsArray(const std::string& value, std::vector<std::string>& valueArray)
|
||||
{
|
||||
auto startPos = 0u;
|
||||
for (auto ci = 0u; ci < value.size(); ci++)
|
||||
{
|
||||
const auto c = value[ci];
|
||||
|
||||
if (c == '\r' && ci + 1 < value.size() && value[ci + 1] == '\n')
|
||||
{
|
||||
valueArray.emplace_back(value, startPos, ci - startPos);
|
||||
startPos = ++ci + 1;
|
||||
}
|
||||
else if(c == '\n')
|
||||
{
|
||||
valueArray.emplace_back(value, startPos, ci - startPos);
|
||||
startPos = ci + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(startPos < value.size())
|
||||
{
|
||||
valueArray.emplace_back(value, startPos, value.size() - startPos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverterBase::ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray) const
|
||||
{
|
||||
std::string key;
|
||||
auto isKey = true;
|
||||
|
||||
for (auto ci = 0u; ci < value.size(); ci++)
|
||||
{
|
||||
auto c = value[ci];
|
||||
|
||||
if (c == '\r' && ci + 1 < value.size() && value[ci + 1] == '\n')
|
||||
c = value[++ci];
|
||||
|
||||
if (c == '\n' && !isKey)
|
||||
{
|
||||
std::cout << "Expected value but got new line" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isspace(c))
|
||||
continue;
|
||||
|
||||
int separator;
|
||||
const auto startPos = ci;
|
||||
while (true)
|
||||
{
|
||||
ci++;
|
||||
if (ci >= value.size())
|
||||
{
|
||||
separator = EOF;
|
||||
break;
|
||||
}
|
||||
c = value[ci];
|
||||
if (c == '\r' && ci + 1 < value.size() && value[ci + 1] == '\n')
|
||||
c = value[++ci];
|
||||
if (isspace(c))
|
||||
{
|
||||
separator = static_cast<int>(static_cast<unsigned char>(c));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isKey)
|
||||
{
|
||||
if (separator == '\n' || separator == EOF)
|
||||
{
|
||||
std::cout << "Expected value but got new line" << std::endl;
|
||||
return false;
|
||||
}
|
||||
key = std::string(value, startPos, ci - startPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto parsedValue = std::string(value, startPos, ci - startPos);
|
||||
valueArray.emplace_back(std::make_pair(std::move(key), std::move(parsedValue)));
|
||||
key = std::string();
|
||||
}
|
||||
isKey = !isKey;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverterBase::ConvertString(const std::string& value, const size_t offset)
|
||||
{
|
||||
*reinterpret_cast<const char**>(reinterpret_cast<uintptr_t>(m_structure) + offset) = m_memory->Dup(value.c_str());
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
@ -18,6 +19,9 @@ protected:
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
MemoryManager* m_memory;
|
||||
void* m_structure;
|
||||
|
||||
static bool ParseAsArray(const std::string& value, std::vector<std::string>& valueArray);
|
||||
bool ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray) const;
|
||||
|
||||
bool ConvertString(const std::string& value, size_t offset);
|
||||
bool ConvertStringBuffer(const std::string& value, size_t offset, size_t bufferSize);
|
||||
|
Reference in New Issue
Block a user