]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/id_xml.cpp
1 /*=============================================================================
2 Copyright (c) 2011-2013 Daniel James
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 =============================================================================*/
9 #include <boost/range/algorithm.hpp>
10 #include "document_state_impl.hpp"
17 char const* id_attributes_
[] = {"id", "linkend", "linkends",
21 xml_processor::xml_processor()
23 static std::size_t const n_id_attributes
=
24 sizeof(id_attributes_
) / sizeof(char const*);
25 for (int i
= 0; i
!= n_id_attributes
; ++i
) {
26 id_attributes
.push_back(id_attributes_
[i
]);
29 boost::sort(id_attributes
);
32 template <typename Iterator
>
33 bool read(Iterator
& it
, Iterator end
, char const* text
)
35 for (Iterator it2
= it
;; ++it2
, ++text
) {
41 if (it2
== end
|| *it2
!= *text
) return false;
45 template <typename Iterator
>
46 void read_past(Iterator
& it
, Iterator end
, char const* text
)
48 while (it
!= end
&& !read(it
, end
, text
))
52 bool find_char(char const* text
, char c
)
55 if (c
== *text
) return true;
59 template <typename Iterator
>
60 void read_some_of(Iterator
& it
, Iterator end
, char const* text
)
62 while (it
!= end
&& find_char(text
, *it
))
66 template <typename Iterator
>
67 void read_to_one_of(Iterator
& it
, Iterator end
, char const* text
)
69 while (it
!= end
&& !find_char(text
, *it
))
73 void xml_processor::parse(quickbook::string_view source
, callback
& c
)
75 typedef string_iterator iterator
;
79 iterator it
= source
.begin(), end
= source
.end();
82 read_past(it
, end
, "<");
85 if (read(it
, end
, "!--quickbook-escape-prefix-->")) {
86 read_past(it
, end
, "<!--quickbook-escape-postfix-->");
93 read_past(it
, end
, "?>");
97 if (read(it
, end
, "!--"))
98 read_past(it
, end
, "-->");
100 read_past(it
, end
, ">");
104 if ((*it
>= 'a' && *it
<= 'z') || (*it
>= 'A' && *it
<= 'Z') ||
105 *it
== '_' || *it
== ':') {
106 read_to_one_of(it
, end
, " \t\n\r>");
109 read_some_of(it
, end
, " \t\n\r");
110 iterator name_start
= it
;
111 read_to_one_of(it
, end
, "= \t\n\r>");
112 if (it
== end
|| *it
== '>') break;
113 quickbook::string_view
name(
114 name_start
, it
- name_start
);
117 read_some_of(it
, end
, "= \t\n\r");
118 if (it
== end
|| (*it
!= '"' && *it
!= '\'')) break;
123 iterator value_start
= it
;
125 it
= std::find(it
, end
, delim
);
126 if (it
== end
) break;
127 quickbook::string_view
value(
128 value_start
, it
- value_start
);
131 if (boost::find(id_attributes
, name
.to_s()) !=
132 id_attributes
.end()) {
138 read_past(it
, end
, ">");
149 quickbook::string_view source
, quickbook::string_view linkend
)
151 typedef string_iterator iterator
;
153 iterator it
= source
.begin(), end
= source
.end();
155 bool contains_link
= false;
157 for (; !contains_link
;) {
158 read_past(it
, end
, "<");
159 if (it
== end
) break;
164 read_past(it
, end
, "?>");
168 if (read(it
, end
, "!--")) {
169 read_past(it
, end
, "-->");
172 read_past(it
, end
, ">");
177 if ((*it
>= 'a' && *it
<= 'z') ||
178 (*it
>= 'A' && *it
<= 'Z') || *it
== '_' ||
180 iterator tag_name_start
= it
;
181 read_to_one_of(it
, end
, " \t\n\r>");
182 quickbook::string_view
tag_name(
183 tag_name_start
, it
- tag_name_start
);
184 if (tag_name
== "link") {
185 contains_link
= true;
189 read_to_one_of(it
, end
, "\"'\n\r>");
190 if (it
== end
|| *it
== '>') break;
191 if (*it
== '"' || *it
== '\'') {
194 it
= std::find(it
, end
, delim
);
195 if (it
== end
) break;
201 read_past(it
, end
, ">");
208 if (!contains_link
) {
209 result
+= "<link linkend=\"";
210 result
.append(linkend
.begin(), linkend
.end());
212 result
.append(source
.begin(), source
.end());
216 result
.append(source
.begin(), source
.end());