]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/utils.cpp
f2f155768ba29a614ff528409430b476775242ce
1 /*=============================================================================
2 Copyright (c) 2002 2004 2006 Joel de Guzman
3 Copyright (c) 2004 Eric Niebler
4 http://spirit.sourceforge.net/
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
20 std::string
encode_string(quickbook::string_view str
)
23 result
.reserve(str
.size());
25 for (string_iterator it
= str
.begin(); it
!= str
.end(); ++it
) {
48 void print_char(char ch
, std::ostream
& out
)
66 // note ' is not included. see the curse of apos:
67 // http://fishbowl.pastiche.org/2003/07/01/the_curse_of_apos
71 void print_string(quickbook::string_view str
, std::ostream
& out
)
73 for (string_iterator cur
= str
.begin(); cur
!= str
.end(); ++cur
) {
74 print_char(*cur
, out
);
78 std::string
make_identifier(quickbook::string_view text
)
80 std::string
id(text
.begin(), text
.end());
81 for (std::string::iterator i
= id
.begin(); i
!= id
.end(); ++i
) {
82 if (!std::isalnum(static_cast<unsigned char>(*i
))) {
86 *i
= static_cast<char>(
87 std::tolower(static_cast<unsigned char>(*i
)));
94 static std::string
escape_uri_impl(
95 quickbook::string_view uri_param
, char const* mark
)
97 // Extra capital characters for validating percent escapes.
98 static char const hex
[] = "0123456789abcdefABCDEF";
101 uri
.reserve(uri_param
.size());
103 for (std::string::size_type n
= 0; n
< uri_param
.size(); ++n
) {
104 if (static_cast<unsigned char>(uri_param
[n
]) > 127 ||
105 (!std::isalnum(static_cast<unsigned char>(uri_param
[n
])) &&
106 !std::strchr(mark
, uri_param
[n
])) ||
107 (uri_param
[n
] == '%' &&
108 !(n
+ 2 < uri_param
.size() &&
109 std::strchr(hex
, uri_param
[n
+ 1]) &&
110 std::strchr(hex
, uri_param
[n
+ 2])))) {
111 char escape
[] = {'%', hex
[uri_param
[n
] / 16],
112 hex
[uri_param
[n
] % 16], '\0'};
123 std::string
escape_uri(quickbook::string_view uri_param
)
125 std::string
uri(uri_param
.begin(), uri_param
.end());
126 return escape_uri_impl(uri_param
, "-_.!~*'()?\\/");
129 std::string
partially_escape_uri(quickbook::string_view uri_param
)
131 return escape_uri_impl(uri_param
, "-_.!~*'()?\\/:&=#%+");