Spicy
string.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <string_view>
7 
8 #include <hilti/rt/extension-points.h>
9 #include <hilti/rt/util.h>
10 
11 namespace hilti::rt {
12 
13 namespace string {
14 
21 size_t size(const std::string& s);
22 
28 std::string lower(const std::string& s);
29 
35 std::string upper(const std::string& s);
36 
37 } // namespace string
38 
39 namespace detail::adl {
40 inline std::string to_string(const std::string& x, adl::tag /*unused*/) {
41  return fmt("\"%s\"", escapeUTF8(x, true, true, true));
42 }
43 
44 inline std::string to_string(std::string_view x, adl::tag /*unused*/) {
45  return fmt("\"%s\"", escapeUTF8(x, true, true, true));
46 }
47 
48 template<typename CharT, size_t N>
49 inline std::string to_string(const CharT (&x)[N], adl::tag /*unused*/) {
50  return fmt("\"%s\"", escapeUTF8(x, true, true, true));
51 }
52 
53 } // namespace detail::adl
54 
55 template<>
56 inline std::string detail::to_string_for_print<std::string>(const std::string& x) {
57  return escapeUTF8(x, false, false, true);
58 }
59 
60 template<>
61 inline std::string detail::to_string_for_print<std::string_view>(const std::string_view& x) {
62  return escapeUTF8(x, false, false, true);
63 }
64 
65 
66 } // namespace hilti::rt
std::string to_string(T &&x)
Definition: extension-points.h:26
Definition: any.h:7
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13