]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/tools/quickbook/src/utils.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / utils.cpp
index 6f3b49acda6dfa096a2f326d862609d77e8570f4..a60124597892128fc2615e7f7c185ac979ecb733 100644 (file)
 
 namespace quickbook { namespace detail
 {
-    std::string encode_string(boost::string_ref str)
+    std::string encode_string(quickbook::string_view str)
     {
         std::string result;
         result.reserve(str.size());
 
-        for (boost::string_ref::const_iterator it = str.begin();
+        for (string_iterator it = str.begin();
             it != str.end(); ++it)
         {
             switch (*it)
@@ -50,60 +50,66 @@ namespace quickbook { namespace detail
         }
     }
 
-    void print_string(boost::string_ref str, std::ostream& out)
+    void print_string(quickbook::string_view str, std::ostream& out)
     {
-        for (boost::string_ref::const_iterator cur = str.begin();
+        for (string_iterator cur = str.begin();
             cur != str.end(); ++cur)
         {
             print_char(*cur, out);
         }
     }
 
-    char filter_identifier_char(char ch)
+    std::string make_identifier(quickbook::string_view text)
     {
-        if (!std::isalnum(static_cast<unsigned char>(ch)))
-            ch = '_';
-        return static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
+        std::string id(text.begin(), text.end());
+        for (std::string::iterator i = id.begin(); i != id.end(); ++i) {
+            if (!std::isalnum(static_cast<unsigned char>(*i))) {
+                *i = '_';
+            }
+            else {
+                *i = static_cast<char>(std::tolower(static_cast<unsigned char>(*i)));
+            }
+        }
+
+        return id;
     }
 
-    static std::string escape_uri_impl(std::string& uri_param, char const* mark)
+    static std::string escape_uri_impl(quickbook::string_view uri_param, char const* mark)
     {
         // Extra capital characters for validating percent escapes.
         static char const hex[] = "0123456789abcdefABCDEF";
 
         std::string uri;
-        uri.swap(uri_param);
+        uri.reserve(uri_param.size());
 
-        for (std::string::size_type n = 0; n < uri.size(); ++n)
+        for (std::string::size_type n = 0; n < uri_param.size(); ++n)
         {
-            if (static_cast<unsigned char>(uri[n]) > 127 ||
-                    (!std::isalnum(static_cast<unsigned char>(uri[n])) &&
-                     !std::strchr(mark, uri[n])) ||
-                    (uri[n] == '%' && !(n + 2 < uri.size() &&
-                                        std::strchr(hex, uri[n+1]) &&
-                                        std::strchr(hex, uri[n+2]))))
+            if (static_cast<unsigned char>(uri_param[n]) > 127 ||
+                    (!std::isalnum(static_cast<unsigned char>(uri_param[n])) &&
+                     !std::strchr(mark, uri_param[n])) ||
+                    (uri_param[n] == '%' && !(n + 2 < uri_param.size() &&
+                                        std::strchr(hex, uri_param[n+1]) &&
+                                        std::strchr(hex, uri_param[n+2]))))
             {
-                char escape[] = { hex[uri[n] / 16], hex[uri[n] % 16] };
-                uri.insert(n + 1, escape, 2);
-                uri[n] = '%';
-                n += 2;
+                char escape[] = { '%', hex[uri_param[n] / 16], hex[uri_param[n] % 16], '\0' };
+                uri += escape;
             }
-            else if (uri[n] == '%')
+            else
             {
-                n += 2;
+                uri += uri_param[n];
             }
         }
 
         return uri;
     }
 
-    std::string escape_uri(std::string uri_param)
+    std::string escape_uri(quickbook::string_view uri_param)
     {
-        // TODO: I don't understand this choice of characters.....
+        std::string uri(uri_param.begin(), uri_param.end());
         return escape_uri_impl(uri_param, "-_.!~*'()?\\/");
     }
 
-    std::string partially_escape_uri(std::string uri_param)
+    std::string partially_escape_uri(quickbook::string_view uri_param)
     {
         return escape_uri_impl(uri_param, "-_.!~*'()?\\/:&=#%+");
     }