• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2 Copyright (c) 2011-2013, 2017 Daniel James
3 
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 
9 namespace quickbook
10 {
11     template <typename Iterator>
read(Iterator & it,Iterator end,char const * text)12     bool read(Iterator& it, Iterator end, char const* text)
13     {
14         for (Iterator it2 = it;; ++it2, ++text) {
15             if (!*text) {
16                 it = it2;
17                 return true;
18             }
19 
20             if (it2 == end || *it2 != *text) return false;
21         }
22     }
23 
24     template <typename Iterator>
read_past(Iterator & it,Iterator end,char const * text)25     bool read_past(Iterator& it, Iterator end, char const* text)
26     {
27         while (it != end) {
28             if (read(it, end, text)) {
29                 return true;
30             }
31             ++it;
32         }
33         return false;
34     }
35 
find_char(char const * text,char c)36     inline bool find_char(char const* text, char c)
37     {
38         for (; *text; ++text)
39             if (c == *text) return true;
40         return false;
41     }
42 
43     template <typename Iterator>
read_some_of(Iterator & it,Iterator end,char const * text)44     void read_some_of(Iterator& it, Iterator end, char const* text)
45     {
46         while (it != end && find_char(text, *it))
47             ++it;
48     }
49 
50     template <typename Iterator>
read_to_one_of(Iterator & it,Iterator end,char const * text)51     void read_to_one_of(Iterator& it, Iterator end, char const* text)
52     {
53         while (it != end && !find_char(text, *it))
54             ++it;
55     }
56 
57     template <typename Iterator>
read_to(Iterator & it,Iterator end,char c)58     void read_to(Iterator& it, Iterator end, char c)
59     {
60         while (it != end && *it != c)
61             ++it;
62     }
63 }
64