12 #pragma clang diagnostic push
13 #pragma clang diagnostic ignored "-Wreorder"
15 #pragma GCC diagnostic ignored "-Wreorder"
18 #include "name-component.h"
21 #include "detail/uri.h"
27 Component::Component ()
31 Component::Component (
const std::string &uri)
33 copy (uri.begin (), uri.end (), std::back_inserter (*
this));
36 Component::Component (std::string::const_iterator begin, std::string::const_iterator end)
38 copy (begin, end, std::back_inserter (*
this));
41 Component::Component (
const void *buf,
size_t length)
43 copy (static_cast<const char*> (buf),
44 static_cast<const char*> (buf)+length,
45 std::back_inserter (*
this));
49 Component::fromUri (
const std::string &uri)
53 Uri::fromEscaped (uri.begin (), uri.end (), std::back_inserter (*
this));
67 Component::fromUri (std::string::const_iterator begin, std::string::const_iterator end)
71 Uri::fromEscaped (begin, end, std::back_inserter (*
this));
86 if (size () < other.size ())
89 if (size () > other.size ())
94 std::pair<const_iterator, const_iterator> diff = mismatch (begin (), end (), other.begin ());
95 if (diff.first == end ())
98 return (std::lexicographical_compare (diff.first, end (), diff.second, other.end ())) ? -1 : +1;
102 Component::fromNumber (uint64_t number)
106 this->push_back (static_cast<unsigned char> (number & 0xFF));
109 std::reverse (this->begin (), this->end ());
114 Component::fromNumberWithMarker (uint64_t number,
unsigned char marker)
116 this->push_back (marker);
120 this->push_back (static_cast<unsigned char> (number & 0xFF));
124 std::reverse (this->begin () + 1, this->end ());
129 Component::toBlob ()
const
131 return std::string (begin (), end ());
135 Component::toBlob (std::ostream &os)
const
137 os.write (buf (), size ());
141 Component::toUri ()
const
143 std::ostringstream os;
149 Component::toUri (std::ostream &os)
const
151 const uint8_t* valuePtr =
reinterpret_cast<const uint8_t*
>(buf());
152 size_t valueSize = size();
154 bool gotNonDot =
false;
155 for (
unsigned i = 0; i < valueSize; ++i) {
156 if (valuePtr[i] != 0x2e) {
164 for (
size_t i = 0; i < valueSize; ++i)
169 std::ios::fmtflags saveFlags = os.flags(std::ios::hex | std::ios::uppercase);
171 for (
size_t i = 0; i < valueSize; ++i) {
172 uint8_t x = valuePtr[i];
174 if ((x >= 0x30 && x <= 0x39) || (x >= 0x41 && x <= 0x5a) ||
175 (x >= 0x61 && x <= 0x7a) || x == 0x2b || x == 0x2d ||
176 x == 0x2e || x == 0x5f)
182 os << static_cast<unsigned int>(x);
192 Component::toNumber ()
const
195 for (const_iterator i = begin (); i != end (); i++)
198 ret |=
static_cast<unsigned char> (*i);
204 Component::toNumberWithMarker (
unsigned char marker)
const
207 static_cast<unsigned char> (*(begin ())) != marker)
210 <<
error::msg (
"Name component does not have required marker [" + toUri () +
"]"));
214 for (const_iterator i = begin () + 1; i != end (); i++)
217 ret |=
static_cast<unsigned char> (*i);
int get_pos(boost::exception &e)
Helper method to get position of the error from the exception.
An error with name::Component.
boost::error_info< struct tag_msg, std::string > msg
Free-formatted text message explaining the error.
This file defines basic elements for the library reporting.
boost::error_info< struct tag_pos, int > pos
Report of the position of the error (error-specific meaning)
An error with URI processing.
Class to representing binary blob of NDN name component.