ParseString.ct
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief ParseString non-inline template implementation */
16 
17 //#include "ParseString.ih"
18 
19 // Custom includes
20 #include <boost/tokenizer.hpp>
21 #include <boost/numeric/conversion/cast.hpp>
22 #include <senf/Utils/String.hh>
23 #include <senf/Socket/Protocols/AddressExceptions.hh>
24 
25 #define prefix_
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 
28 template <class ForwardIterator>
29 prefix_ void senf::detail::parseHexString(std::string const & value,
30  char const * separator, ForwardIterator f,
31  ForwardIterator l)
32 {
33  typedef boost::char_separator<char> Separator;
34  typedef boost::tokenizer<Separator> Tokenizer;
35  Separator sep (separator);
36  Tokenizer tok (value, sep);
37  Tokenizer::iterator i (tok.begin());
38  Tokenizer::iterator const i_end (tok.end());
39  try {
40  for (; i!=i_end && f!=l; ++i, ++f)
41  *f = boost::numeric_cast<typename std::iterator_traits<ForwardIterator>::value_type>(
42  senf::lexical_cast<unsigned long>()[std::hex](
43  std::string(boost::begin(*i),boost::end(*i))));
44  }
45  catch (std::bad_cast &) {
46  throw AddressSyntaxException(value);
47  }
48  if (i!=i_end || f!=l)
49  throw AddressSyntaxException(value);
50 }
51 
52 //-/////////////////////////////////////////////////////////////////////////////////////////////////
53 #undef prefix_
54 
55 
56 // Local Variables:
57 // mode: c++
58 // fill-column: 100
59 // comment-column: 40
60 // c-file-style: "senf"
61 // indent-tabs-mode: nil
62 // ispell-local-dictionary: "american"
63 // compile-command: "scons -u test"
64 // End: