17 #ifndef VCSN_MISC_ESCAPER_HXX
18 # define VCSN_MISC_ESCAPER_HXX
44 static const int idx = std::ios::xalloc ();
53 escaper<T>::escaper (
const T& w) : w_ (w)
59 escaper<T>::operator() (std::ostream& ostr)
const
63 std::string w = o.str ();
64 const std::set<char>& e =
getesc (ostr);
65 for (std::string::const_iterator i = w.begin (); i != w.end (); ++i)
66 if (e.find (*i) != e.end ())
89 setesc::setesc (
const std::set<char>& s) : s_ (s)
95 setesc::operator() (std::ostream& ostr)
const
97 typedef std::set<char> esc_set;
100 if (not ostr.pword (idx))
101 ostr.register_callback (pword_delete<esc_set>, idx);
103 delete static_cast<esc_set*
> (ostr.pword (idx));
104 ostr.pword (idx) =
new esc_set (s_);
113 std::set<char>&
getesc (std::ostream& ostr)
117 if (not ostr.pword (idx))
119 return *
static_cast<std::set<char>*
> (ostr.pword (idx));
125 #endif // ! VCSN_MISC_ESCAPER_HXX