ParseString.ct
Go to the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026
00027
00028
00029 #include <boost/tokenizer.hpp>
00030 #include <boost/range.hpp>
00031 #include <boost/numeric/conversion/cast.hpp>
00032 #include <senf/Utils/String.hh>
00033 #include <senf/Socket/Protocols/AddressExceptions.hh>
00034
00035 #define prefix_
00036
00037
00038 template <class ForwardIterator>
00039 prefix_ void senf::detail::parseHexString(std::string const & value,
00040 char const * separator, ForwardIterator f,
00041 ForwardIterator l)
00042 {
00043 typedef boost::char_separator<char> Separator;
00044 typedef boost::tokenizer<Separator> Tokenizer;
00045 Separator sep (separator);
00046 Tokenizer tok (value, sep);
00047 Tokenizer::iterator i (tok.begin());
00048 Tokenizer::iterator const i_end (tok.end());
00049 try {
00050 for (; i!=i_end && f!=l; ++i, ++f)
00051 *f = boost::numeric_cast<typename std::iterator_traits<ForwardIterator>::value_type>(
00052 senf::lexical_cast<unsigned long>()[std::hex](
00053 std::string(boost::begin(*i),boost::end(*i))));
00054 }
00055 catch (std::bad_cast &) {
00056 throw AddressSyntaxException(value);
00057 }
00058 if (i!=i_end || f!=l)
00059 throw AddressSyntaxException(value);
00060 }
00061
00062
00063 #undef prefix_
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074