mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 00:08:26 -05:00
Add InfoString loading
This commit is contained in:
@ -96,10 +96,90 @@ void InfoString::ToGdtProperties(const std::string& prefix, GdtEntry& gdtEntry)
|
||||
gdtEntry.m_properties["configstringFileType"] = prefix;
|
||||
}
|
||||
|
||||
void InfoString::FromString()
|
||||
class InfoStringInputStream
|
||||
{
|
||||
std::istream& m_stream;
|
||||
|
||||
public:
|
||||
explicit InfoStringInputStream(std::istream& stream)
|
||||
: m_stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
bool NextField(std::string& value) const
|
||||
{
|
||||
std::ostringstream str;
|
||||
|
||||
auto c = m_stream.get();
|
||||
if (c == EOF)
|
||||
return false;
|
||||
|
||||
while (c != EOF && c != '\\')
|
||||
{
|
||||
str << static_cast<char>(c);
|
||||
c = m_stream.get();
|
||||
}
|
||||
|
||||
value = str.str();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
bool InfoString::FromStream(std::istream& stream)
|
||||
{
|
||||
const InfoStringInputStream infoStream(stream);
|
||||
|
||||
std::string key;
|
||||
while (infoStream.NextField(key))
|
||||
{
|
||||
std::string value;
|
||||
if (!infoStream.NextField(value))
|
||||
return false;
|
||||
|
||||
const auto existingEntry = m_values.find(key);
|
||||
if (existingEntry == m_values.end())
|
||||
{
|
||||
m_keys_by_insertion.push_back(key);
|
||||
m_values.emplace(std::make_pair(key, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntry->second = value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InfoString::FromString(const std::string& prefix)
|
||||
bool InfoString::FromStream(const std::string& prefix, std::istream& stream)
|
||||
{
|
||||
const InfoStringInputStream infoStream(stream);
|
||||
|
||||
std::string readPrefix;
|
||||
if (!infoStream.NextField(readPrefix))
|
||||
return false;
|
||||
|
||||
if (prefix != readPrefix)
|
||||
return false;
|
||||
|
||||
std::string key;
|
||||
while(infoStream.NextField(key))
|
||||
{
|
||||
std::string value;
|
||||
if (!infoStream.NextField(value))
|
||||
return false;
|
||||
|
||||
const auto existingEntry = m_values.find(key);
|
||||
if(existingEntry == m_values.end())
|
||||
{
|
||||
m_keys_by_insertion.push_back(key);
|
||||
m_values.emplace(std::make_pair(key, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
existingEntry->second = value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <istream>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -23,6 +24,6 @@ public:
|
||||
_NODISCARD std::string ToString(const std::string& prefix) const;
|
||||
void ToGdtProperties(const std::string& prefix, GdtEntry& gdtEntry) const;
|
||||
|
||||
void FromString();
|
||||
void FromString(const std::string& prefix);
|
||||
bool FromStream(std::istream& stream);
|
||||
bool FromStream(const std::string& prefix, std::istream& stream);
|
||||
};
|
Reference in New Issue
Block a user