mqtt_cpp
topic_filter_tokenizer.hpp
Go to the documentation of this file.
1 // Copyright wkl04 2019
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #if !defined(MQTT_BROKER_TOPIC_FILTER_TOKENIZER_HPP)
8 #define MQTT_BROKER_TOPIC_FILTER_TOKENIZER_HPP
9 
10 #include <algorithm>
11 
13 #include <mqtt/string_view.hpp>
14 
16 
17 static constexpr char topic_filter_separator = '/';
18 
19 template<typename Iterator, typename Output>
20 inline void topic_filter_tokenizer(Iterator first, Iterator last, Output write) {
21  auto pos = std::find(first, last, topic_filter_separator);
22  while (write(first, pos) && pos != last) {
23  first = std::next(pos);
24  pos = std::find(first, last, topic_filter_separator);
25  }
26 }
27 
28 
29 template<typename Output>
30 inline void topic_filter_tokenizer(string_view str, Output write) {
32  std::begin(str),
33  std::end(str),
34  [&write](string_view::const_iterator token_begin, string_view::const_iterator token_end) {
35  return write(
37  token_begin,
38  static_cast<std::size_t>(std::distance(token_begin, token_end)))
39  );
40  }
41  );
42 }
43 
45 
46 #endif // MQTT_BROKER_TOPIC_FILTER_TOKENIZER_HPP
#define MQTT_BROKER_NS_END
Definition: broker_namespace.hpp:22
#define MQTT_BROKER_NS_BEGIN
Definition: broker_namespace.hpp:21
boost::string_ref string_view
Definition: string_view.hpp:64
void topic_filter_tokenizer(Iterator first, Iterator last, Output write)
Definition: topic_filter_tokenizer.hpp:20