8 #ifndef SIG_UTIL_TAGDEALER_HPP
9 #define SIG_UTIL_TAGDEALER_HPP
11 #include "../functional/high_order.hpp"
12 #include "../string/manipulate.hpp"
18 template <
class S>
struct space{};
19 template <>
struct space<std::string>{ std::string
operator()()
const{
return " "; } };
20 template <>
struct space<std::wstring>{ std::wstring
operator()()
const{
return L
" "; } };
39 TagDealer(S tag_encloser_left, S tag_encloser_right) : tel_(tag_encloser_left), ter_(tag_encloser_right){};
48 S
encode(S
const& src, S
const& tag)
const{
49 auto tag_str = tel_ + tag + ter_;
50 return tag_str + src + tag_str;
60 auto decode(S
const& src, S
const& tag) ->Maybe<S>
const{
61 auto tag_str = tel_ + tag + ter_;
64 return parse.size() < 2 ?
Nothing(S()) : Just<S>(parse[1]);
67 template <
template <
class T_,
class Allocator = std::allocator<T_>>
class Container >
68 S
encode(Container<S>
const& src, Container<S>
const& tag)
const;
70 template <
template <
class T_,
class Allocator = std::allocator<T_>>
class Container >
71 auto decode(S
const& src, Container<S>
const& tag)->Maybe<Container<S>>
const;
76 template <
template <
class T_,
class Allocator = std::allocator<T_>>
class Container >
79 auto calc =
zipWith([&](
typename Container<S>::value_type s,
typename Container<S>::value_type t){
return encode(s, t); }, src, tag);
80 return std::accumulate(calc.begin(), calc.end(), S());
84 template <
template <
class T_,
class Allocator = std::allocator<T_>>
class Container >
88 for (
auto const& e : tag){
89 auto d = decode(src, e);
92 return result.empty() ?
Nothing(result) : Just<Container<S>>(std::move(result));
TagDealer(S tag_encloser_left, S tag_encloser_right)
auto decode(S const &src, S const &tag) -> Maybe< S > const
auto split(S const &src, impl::string_t< S > const &delimiter) -> CSeq< TS >
文字列(src)をある文字列(delimiter)を目印に分割する
auto Nothing() -> typename impl::SameIf< T, void, typename boost::none_t, Maybe< T >>::type
値コンストラクタ
std::wstring operator()() const
S encode(S const &src, S const &tag) const
std::string operator()() const
bool isJust(Maybe< T > const &m)
Justであるか調べる関数.Maybe a -> Bool.
auto zipWith(F &&func, C1 &&list1, C2 &&list2)
2引数高階関数
T & fromJust(Maybe< T > &m)
Justから値を取り出す関数.Maybe a -> a.