Commit 53db2bb5 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Add mpeg ts reader helper function to find entries by name.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent c918bbc6
......@@ -330,37 +330,45 @@ TSReader::entries()
return m_entries;
}
const TSReader::Entry *
TSReader::find (const string& name) const
{
for (const auto& entry : m_entries)
if (entry.filename == name)
return &entry;
return nullptr;
}
map<string, string>
TSReader::parse_vars (const string& name)
{
map<string, string> vars;
for (auto entry : m_entries)
auto entry = find (name);
if (!entry)
return vars;
enum { KEY, VALUE } mode = KEY;
string s;
string key;
for (auto c : entry->data)
{
if (entry.filename == name)
if (c == '=' && mode == KEY)
{
enum { KEY, VALUE } mode = KEY;
string s;
string key;
for (auto c : entry.data)
{
if (c == '=' && mode == KEY)
{
key = s;
s.clear();
mode = VALUE;
}
else if (c == '\0' && mode == VALUE)
{
vars[key] = s;
s.clear();
mode = KEY;
}
else
{
s += c;
}
}
key = s;
s.clear();
mode = VALUE;
}
else if (c == '\0' && mode == VALUE)
{
vars[key] = s;
s.clear();
mode = KEY;
}
else
{
s += c;
}
}
return vars;
......
......@@ -37,6 +37,7 @@ private:
public:
Error load (const std::string& inname);
const std::vector<Entry>& entries();
const Entry *find (const std::string& filename) const;
std::map<std::string, std::string> parse_vars (const std::string& name);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment