From 19eb367ebd0df86f0d06dc2362c3e3859e56e767 Mon Sep 17 00:00:00 2001 From: manga_osyo Date: Fri, 4 May 2012 23:57:10 +0900 Subject: [PATCH 1/2] add __TIME__ parse example --- libs/weed/example/__TIME__.cpp | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 libs/weed/example/__TIME__.cpp diff --git a/libs/weed/example/__TIME__.cpp b/libs/weed/example/__TIME__.cpp new file mode 100644 index 00000000..e6283cb8 --- /dev/null +++ b/libs/weed/example/__TIME__.cpp @@ -0,0 +1,68 @@ +// +// Sprout C++ Library +// +// Copyright (c) 2012 +// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/ +// osyo-manga : http://d.hatena.ne.jp/osyo-manga/ +// +// Readme: +// https://github.com/osyo-manga/cpp-half/blob/master/README +// +// License: +// Boost Software License - Version 1.0 +// +// +#include +#include +#include +#include + +// +// __TIME__ Parser +// +int +main(){ + namespace w = sprout::weed; + + // + // __TIME__ to Sprout.String + // + static constexpr auto time = sprout::to_string(__TIME__); +// static constexpr auto time = sprout::to_string("23:22:45"); + + + // + // parse __TIME__ + // + constexpr auto parser = w::int_ >> ':' >> w::int_ >> ':' >> w::int_; + static constexpr auto result = w::parse(time.begin(), time.end(), parser); + static_assert(result.success(), "failed parse"); + + + // + // get result + // + static constexpr sprout::array result_attr = result.attr(); + static constexpr auto hour = result_attr[0]; + static constexpr auto minute = result_attr[1]; + static constexpr auto second = result_attr[2]; + +// static_assert(hour == 23, ""); +// static_assert(minute == 22, ""); +// static_assert(second == 45, ""); + + std::cout << hour << std::endl; + std::cout << minute << std::endl; + std::cout << second << std::endl; + + + // + // compile time output + // + namespace m = boost::mpl; + typedef m::print>::type hour_; + typedef m::print>::type minute_; + typedef m::print>::type second_; + + return 0; +} From 83eb1531ad3d3716aff63f62f1463080c47ad3b2 Mon Sep 17 00:00:00 2001 From: manga_osyo Date: Sat, 5 May 2012 00:23:48 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=90=8D=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/weed/example/__TIME__.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/weed/example/__TIME__.cpp b/libs/weed/example/__TIME__.cpp index e6283cb8..2074e511 100644 --- a/libs/weed/example/__TIME__.cpp +++ b/libs/weed/example/__TIME__.cpp @@ -34,7 +34,7 @@ main(){ // // parse __TIME__ // - constexpr auto parser = w::int_ >> ':' >> w::int_ >> ':' >> w::int_; + constexpr auto expr = w::int_ >> ':' >> w::int_ >> ':' >> w::int_; static constexpr auto result = w::parse(time.begin(), time.end(), parser); static_assert(result.success(), "failed parse");