forked from sony/nmos-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.cpp
36 lines (33 loc) · 1.21 KB
/
core.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "mdns/core.h"
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
namespace mdns
{
structured_txt_records parse_txt_records(const txt_records& records)
{
return boost::copy_range<structured_txt_records>(records
| boost::adaptors::filtered([](const std::string& record)
{
const auto eq = record.find('=');
// For now, discard "boolean attributes"...
return std::string::npos != eq && 0 != eq;
})
| boost::adaptors::transformed([](const std::string& record) -> structured_txt_record
{
const auto eq = record.find('=');
return{ record.substr(0, eq), record.substr(std::string::npos == eq ? eq : eq + 1) };
}));
}
txt_records make_txt_records(const structured_txt_records& records)
{
return boost::copy_range<txt_records>(records
| boost::adaptors::filtered([](const structured_txt_record& record)
{
return !record.first.empty();
})
| boost::adaptors::transformed([](const structured_txt_record& record)
{
return record.first + '=' + record.second;
}));
}
}