diff --git a/include/takatori/datetime/conversion.h b/include/takatori/datetime/conversion.h index ec3d08e..12c1cd4 100644 --- a/include/takatori/datetime/conversion.h +++ b/include/takatori/datetime/conversion.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include @@ -23,7 +23,7 @@ using conversion_result = util::either; * @return the parsed date information * @return an error message if the conversion was failed */ -[[nodiscard]] conversion_result parse_date(std::string const& contents); +[[nodiscard]] conversion_result parse_date(std::string_view contents); /** * @brief parses the given contents as a time of day. @@ -32,7 +32,7 @@ using conversion_result = util::either; * @return the parsed time of day information * @return an error message if the conversion was failed */ -[[nodiscard]] conversion_result parse_time(std::string const& contents); +[[nodiscard]] conversion_result parse_time(std::string_view contents); /** * @brief parses the given contents as a datetime, with or without zone offset. @@ -41,7 +41,7 @@ using conversion_result = util::either; * @return the parsed datetime information with or without zone offset * @return an error message if the conversion was failed */ -[[nodiscard]] conversion_result parse_datetime(std::string const& contents); +[[nodiscard]] conversion_result parse_datetime(std::string_view contents); /** * @brief parses the given contents as a zone offset. @@ -50,6 +50,6 @@ using conversion_result = util::either; * @return the parsed zone offset * @return an error message if the conversion was failed */ -[[nodiscard]] conversion_result parse_zone_offset(std::string const& contents); +[[nodiscard]] conversion_result parse_zone_offset(std::string_view contents); } // namespace takatori::datetime diff --git a/src/takatori/datetime/conversion.cpp b/src/takatori/datetime/conversion.cpp index d1098f7..f18e8f6 100644 --- a/src/takatori/datetime/conversion.cpp +++ b/src/takatori/datetime/conversion.cpp @@ -72,7 +72,7 @@ std::optional require_offset(std::optional const& } // namespace -conversion_result parse_date(std::string const& contents) { +conversion_result parse_date(std::string_view contents) { parser::parser p {}; auto result = p(contents); if (!result) { @@ -91,7 +91,7 @@ conversion_result parse_date(std::string const& contents) { return *info.date; } -conversion_result parse_time(std::string const& contents) { +conversion_result parse_time(std::string_view contents) { parser::parser p {}; auto result = p(contents); if (!result) { @@ -110,7 +110,7 @@ conversion_result parse_time(std::string const& contents) { return *info.time; } -conversion_result parse_datetime(std::string const& contents) { +conversion_result parse_datetime(std::string_view contents) { parser::parser p {}; auto result = p(contents); if (!result) { @@ -136,7 +136,7 @@ conversion_result parse_datetime(std::string const& contents) { return datetime_info { *info.date, *info.time, info.offset }; } -conversion_result parse_zone_offset(std::string const& contents) { +conversion_result parse_zone_offset(std::string_view contents) { parser::parser p {}; auto result = p(contents); if (!result) { diff --git a/src/takatori/datetime/parser/parser.cpp b/src/takatori/datetime/parser/parser.cpp index 7e77fae..5b76217 100644 --- a/src/takatori/datetime/parser/parser.cpp +++ b/src/takatori/datetime/parser/parser.cpp @@ -13,9 +13,9 @@ parser &parser::set_debug(int level) noexcept { return *this; } -parser::result_type parser::operator()(std::string const& contents) const { +parser::result_type parser::operator()(std::string_view contents) const { std::istringstream input { - contents, + std::string { contents }, }; driver driver {}; scanner scanner { input }; @@ -30,7 +30,7 @@ parser::result_type parser::operator()(std::string const& contents) const { return std::move(driver.result()); } -parser::result_type parse(std::string const& contents, parser const& engine) { +parser::result_type parse(std::string_view contents, parser const& engine) { return engine(contents); } diff --git a/src/takatori/datetime/parser/parser.h b/src/takatori/datetime/parser/parser.h index 84df9a6..a68218b 100644 --- a/src/takatori/datetime/parser/parser.h +++ b/src/takatori/datetime/parser/parser.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -19,12 +19,12 @@ class parser { parser& set_debug(int level = 1) noexcept; - [[nodiscard]] result_type operator()(std::string const& contents) const; + [[nodiscard]] result_type operator()(std::string_view contents) const; private: int debug_ {}; }; -parser::result_type parse(std::string const& contents, parser const& engine = {}); +parser::result_type parse(std::string_view contents, parser const& engine = {}); } // namespace takatori::datetime::parser