string-helper.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_STRING_HELPER_HPP
23 #define NDN_UTIL_STRING_HELPER_HPP
24 
25 #include "../common.hpp"
26 
27 namespace ndn {
28 
29 class Buffer;
30 
31 class StringHelperError : public std::invalid_argument
32 {
33 public:
34  explicit
35  StringHelperError(const std::string& what)
36  : std::invalid_argument(what)
37  {
38  }
39 };
40 
52 class AsHex
53 {
54 public:
55  constexpr explicit
56  AsHex(uint64_t val) noexcept
57  : m_value(val)
58  {
59  }
60 
61 private:
62  uint64_t m_value;
63 
64  friend std::ostream& operator<<(std::ostream&, const AsHex&);
65 };
66 
67 std::ostream&
68 operator<<(std::ostream& os, const AsHex& hex);
69 
79 void
80 printHex(std::ostream& os, uint64_t num, bool wantUpperCase = false);
81 
101 void
102 printHex(std::ostream& os, const uint8_t* buffer, size_t length, bool wantUpperCase = true);
103 
111 void
112 printHex(std::ostream& os, const Buffer& buffer, bool wantUpperCase = true);
113 
132 std::string
133 toHex(const uint8_t* buffer, size_t length, bool wantUpperCase = true);
134 
141 std::string
142 toHex(const Buffer& buffer, bool wantUpperCase = true);
143 
147 int
148 fromHexChar(char c);
149 
156 shared_ptr<Buffer>
157 fromHex(const std::string& hexString);
158 
172 std::string
173 unescape(const std::string& str);
174 
175 } // namespace ndn
176 
177 #endif // NDN_UTIL_STRING_HELPER_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
std::string toHex(const uint8_t *buffer, size_t length, bool wantUpperCase)
Return a string containing the hex representation of the bytes in buffer.
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:274
Helper class to convert a number to hexadecimal format, for use with stream insertion operators...
STL namespace.
StringHelperError(const std::string &what)
shared_ptr< Buffer > fromHex(const std::string &hexString)
Convert the hex string to buffer.
std::string unescape(const std::string &str)
Decode a percent-encoded string.
int fromHexChar(char c)
Convert the hex character to an integer from 0 to 15, or -1 if not a hex character.
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:40
constexpr AsHex(uint64_t val) noexcept