Skip to content

Commit b23b06e

Browse files
committed
Move file parsing library to fly::parser namespace
1 parent 0720064 commit b23b06e

12 files changed

+148
-194
lines changed

bench/json/benchmark_json.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LibflyJsonParser : public JsonParserBase
3636
}
3737

3838
private:
39-
fly::JsonParser m_parser;
39+
fly::parser::JsonParser m_parser;
4040
};
4141

4242
// Boost.JSON - https://github.com/boostorg/json

fly/config/config_manager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ ConfigManager::ConfigManager(
4949
switch (file_type)
5050
{
5151
case ConfigFileType::Ini:
52-
m_parser = std::make_unique<fly::IniParser>();
52+
m_parser = std::make_unique<fly::parser::IniParser>();
5353
break;
5454

5555
case ConfigFileType::Json:
56-
m_parser = std::make_unique<fly::JsonParser>();
56+
m_parser = std::make_unique<fly::parser::JsonParser>();
5757
break;
5858

5959
default:

fly/config/config_manager.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include <string>
1313
#include <type_traits>
1414

15-
namespace fly {
15+
namespace fly::parser {
1616
class Parser;
17-
} // namespace fly
17+
} // namespace fly::parser
1818

1919
namespace fly::path {
2020
class PathMonitor;
@@ -113,7 +113,7 @@ class ConfigManager : public std::enable_shared_from_this<ConfigManager>
113113
std::shared_ptr<fly::task::SequencedTaskRunner> m_task_runner;
114114

115115
std::shared_ptr<fly::path::PathMonitor> m_monitor;
116-
std::unique_ptr<fly::Parser> m_parser;
116+
std::unique_ptr<fly::parser::Parser> m_parser;
117117
fly::Json m_values;
118118

119119
const std::filesystem::path m_path;

fly/parser/ini_parser.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
#include <vector>
77

8-
namespace fly {
8+
namespace fly::parser {
99

1010
#define ILOG(...) \
1111
LOGW("[line {}]: " FLY_FORMAT_STRING(__VA_ARGS__), line() FLY_FORMAT_ARGS(__VA_ARGS__));
1212

1313
//==================================================================================================
14-
std::optional<Json> IniParser::parse_internal()
14+
std::optional<fly::Json> IniParser::parse_internal()
1515
{
16-
Json values = JsonTraits::object_type();
17-
Json::iterator current;
16+
fly::Json values = JsonTraits::object_type();
17+
fly::Json::iterator current;
1818

1919
std::string data;
2020

2121
while (getline(data))
2222
{
23-
String::trim(data);
23+
fly::String::trim(data);
2424

2525
if (data.empty() || data.starts_with(';'))
2626
{
@@ -84,7 +84,7 @@ std::optional<Json> IniParser::parse_internal()
8484
}
8585
}
8686

87-
return values.empty() ? std::nullopt : std::optional<Json>(std::move(values));
87+
return values.empty() ? std::nullopt : std::optional<fly::Json>(std::move(values));
8888
}
8989

9090
//==================================================================================================
@@ -106,7 +106,7 @@ bool IniParser::getline(std::string &result)
106106
//==================================================================================================
107107
std::optional<std::string> IniParser::on_section(std::string &section)
108108
{
109-
String::trim(section);
109+
fly::String::trim(section);
110110

111111
if ((trim_value(section, '\'') != TrimResult::Untrimmed) ||
112112
(trim_value(section, '\"') != TrimResult::Untrimmed))
@@ -124,14 +124,14 @@ IniParser::on_name_value_pair(const std::string &name_value)
124124
{
125125
static constexpr std::uint32_t s_size = 2;
126126

127-
std::vector<std::string> pair = String::split(name_value, '=', s_size);
127+
std::vector<std::string> pair = fly::String::split(name_value, '=', s_size);
128128

129129
if (pair.size() == s_size)
130130
{
131131
std::string name(std::move(pair[0])), value(std::move(pair[1]));
132132

133-
String::trim(name);
134-
String::trim(value);
133+
fly::String::trim(name);
134+
fly::String::trim(value);
135135

136136
if ((trim_value(name, '\'') != TrimResult::Untrimmed) ||
137137
(trim_value(name, '\"') != TrimResult::Untrimmed))
@@ -181,4 +181,4 @@ IniParser::TrimResult IniParser::trim_value(std::string &str, char start, char e
181181
return TrimResult::Untrimmed;
182182
}
183183

184-
} // namespace fly
184+
} // namespace fly::parser

fly/parser/ini_parser.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <optional>
88
#include <string>
99

10-
namespace fly {
10+
namespace fly::parser {
1111

1212
/**
1313
* Implementation of the Parser interface for the .ini format.
@@ -23,7 +23,7 @@ class IniParser : public Parser
2323
*
2424
* @return If successful, the parsed values. Otherwise, an uninitialized value.
2525
*/
26-
std::optional<Json> parse_internal() override;
26+
std::optional<fly::Json> parse_internal() override;
2727

2828
private:
2929
/**
@@ -94,4 +94,4 @@ class IniParser : public Parser
9494
TrimResult trim_value(std::string &str, char start, char end) const;
9595
};
9696

97-
} // namespace fly
97+
} // namespace fly::parser

0 commit comments

Comments
 (0)