nghttpx: Add inline LogFragment ctor
This commit is contained in:
parent
0a6877d091
commit
27da08ee68
|
@ -323,13 +323,6 @@ int parse_int(T *dest, const char *opt, const char *optarg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
LogFragment make_log_fragment(LogFragmentType type,
|
|
||||||
std::unique_ptr<char[]> value = nullptr) {
|
|
||||||
return LogFragment{type, std::move(value)};
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool var_token(char c) {
|
bool var_token(char c) {
|
||||||
return util::isAlpha(c) || util::isDigit(c) || c == '_';
|
return util::isAlpha(c) || util::isDigit(c) || c == '_';
|
||||||
|
@ -418,19 +411,17 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (literal_start < var_start) {
|
if (literal_start < var_start) {
|
||||||
res.push_back(make_log_fragment(SHRPX_LOGF_LITERAL,
|
res.emplace_back(SHRPX_LOGF_LITERAL, strcopy(literal_start, var_start));
|
||||||
strcopy(literal_start, var_start)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
literal_start = p;
|
literal_start = p;
|
||||||
|
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
res.push_back(make_log_fragment(type));
|
res.emplace_back(type);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.push_back(
|
res.emplace_back(type, strcopy(value, var_name + var_namelen));
|
||||||
make_log_fragment(type, strcopy(value, var_name + var_namelen)));
|
|
||||||
auto &v = res.back().value;
|
auto &v = res.back().value;
|
||||||
for (size_t i = 0; v[i]; ++i) {
|
for (size_t i = 0; v[i]; ++i) {
|
||||||
if (v[i] == '_') {
|
if (v[i] == '_') {
|
||||||
|
@ -440,8 +431,7 @@ std::vector<LogFragment> parse_log_format(const char *optarg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (literal_start != eop) {
|
if (literal_start != eop) {
|
||||||
res.push_back(
|
res.emplace_back(SHRPX_LOGF_LITERAL, strcopy(literal_start, eop));
|
||||||
make_log_fragment(SHRPX_LOGF_LITERAL, strcopy(literal_start, eop)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -123,6 +123,8 @@ enum LogFragmentType {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LogFragment {
|
struct LogFragment {
|
||||||
|
LogFragment(LogFragmentType type, std::unique_ptr<char[]> value = nullptr)
|
||||||
|
: type(type), value(std::move(value)) {}
|
||||||
LogFragmentType type;
|
LogFragmentType type;
|
||||||
std::unique_ptr<char[]> value;
|
std::unique_ptr<char[]> value;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue