15 #ifndef RAPIDJSON_URI_H_
16 #define RAPIDJSON_URI_H_
20 #if defined(__clang__)
22 RAPIDJSON_DIAG_OFF(c++ 98 - compat)
23 #elif defined(_MSC_VER)
24 RAPIDJSON_DIAG_OFF(4512)
32 template <
typename ValueType,
typename Allocator = CrtAllocator>
36 typedef typename ValueType::Ch
Ch;
37 #if RAPIDJSON_HAS_STDSTRING
38 typedef std::basic_string<Ch> String;
50 allocator_(allocator),
63 allocator_(allocator),
77 allocator_(allocator),
80 Parse(uri, internal::StrLen<Ch>(uri));
93 allocator_(allocator),
96 const Ch* u = uri.template Get<const Ch*>();
97 Parse(u, internal::StrLen<Ch>(u));
100 #if RAPIDJSON_HAS_STDSTRING
109 allocator_(allocator),
112 Parse(uri.c_str(), internal::StrLen<Ch>(uri.c_str()));
140 allocator_(allocator),
174 template <
typename T>
177 uri.template Set<const Ch*>(this->
GetString(), allocator);
187 return scheme_ == 0 ? 0 : internal::StrLen<Ch>(scheme_);
198 #if RAPIDJSON_HAS_STDSTRING
207 static String GetScheme(
const GenericUri& uri)
250 if(s1 == 0 || s2 == 0)
252 return internal::StrCmp<Ch>(s1, s2) == 0;
262 resuri.allocator_ = allocator;
273 resuri.RemoveDotSegments();
286 resuri.RemoveDotSegments();
315 resuri.RemoveDotSegments();
325 resuri.path_[pos] =
'/';
329 while(lastslashpos > 0)
331 if(baseuri.path_[lastslashpos - 1] ==
'/')
335 std::memcpy(&resuri.path_[pos], baseuri.path_, lastslashpos *
sizeof(
Ch));
338 resuri.RemoveDotSegments();
361 std::size_t Allocate(std::size_t len)
370 size_t total = (3 * len + 7) *
sizeof(
Ch);
371 scheme_ =
static_cast<Ch*
>(allocator_->Malloc(total));
407 void Parse(
const Ch* uri, std::size_t len)
409 std::size_t start = 0, pos1 = 0, pos2 = 0;
436 std::memcpy(scheme_, &uri[start], pos1 *
sizeof(
Ch));
437 scheme_[pos1] =
'\0';
447 if(start < len - 1 && uri[start] ==
'/' && uri[start + 1] ==
'/')
460 std::memcpy(auth_, &uri[start], (pos2 - start) *
sizeof(
Ch));
461 auth_[pos2 - start] =
'\0';
482 std::memcpy(path_, &uri[start], (pos2 - start) *
sizeof(
Ch));
483 path_[pos2 - start] =
'\0';
494 if(start < len && uri[start] ==
'?')
505 std::memcpy(query_, &uri[start], (pos2 - start) *
sizeof(
Ch));
506 query_[pos2 - start] =
'\0';
515 if(start < len && uri[start] ==
'#')
517 std::memcpy(frag_, &uri[start], (len - start) *
sizeof(
Ch));
518 frag_[len - start] =
'\0';
556 Ch* CopyPart(
Ch* to,
Ch* from, std::size_t len)
560 std::memcpy(to, from, len *
sizeof(
Ch));
562 Ch* next = to + len + 1;
569 void RemoveDotSegments()
572 std::size_t pathpos = 0;
573 std::size_t newpos = 0;
576 while(pathpos < pathlen)
580 while((pathpos + slashpos) < pathlen)
582 if(path_[pathpos + slashpos] ==
'/')
587 if(slashpos == 2 && path_[pathpos] ==
'.' && path_[pathpos + 1] ==
'.')
592 size_t lastslashpos = newpos;
598 while(lastslashpos > 0)
600 if(path_[lastslashpos - 1] ==
'/')
605 newpos = lastslashpos;
608 else if(slashpos == 1 && path_[pathpos] ==
'.')
616 std::memmove(&path_[newpos], &path_[pathpos], slashpos *
sizeof(
Ch));
619 if((pathpos + slashpos) < pathlen)
626 pathpos += slashpos + 1;
628 path_[newpos] =
'\0';
649 #if defined(__clang__)
void Free(A &a, T *p, size_t n=1)
Definition: allocators.h:485
const Ch * GetFragString() const
Definition: uri.h:195
GenericUri & operator=(const GenericUri &rhs)
Assignment operator.
Definition: uri.h:154
const Ch * GetString() const
Definition: uri.h:180
GenericUri(const Ch *uri, SizeType len, Allocator *allocator=0)
Definition: uri.h:55
bool Match(const GenericUri &uri, bool full=true) const
Definition: uri.h:234
GenericUri(const Ch *uri, Allocator *allocator=0)
Definition: uri.h:69
ValueType::Ch Ch
Definition: uri.h:36
GenericUri(const GenericUri &rhs, Allocator *allocator)
Copy constructor.
Definition: uri.h:132
const Ch * GetQueryString() const
Definition: uri.h:193
~GenericUri()
Destructor.
Definition: uri.h:147
SizeType GetAuthStringLength() const
Definition: uri.h:190
SizeType GetQueryStringLength() const
Definition: uri.h:194
GenericUri(const GenericUri &rhs)
Copy constructor.
Definition: uri.h:117
SizeType GetPathStringLength() const
Definition: uri.h:192
GenericUri Resolve(const GenericUri &baseuri, Allocator *allocator=0)
Resolve this URI against another (base) URI in accordance with URI resolution rules.
Definition: uri.h:259
Allocator & GetAllocator()
Get the allocator of this GenericUri.
Definition: uri.h:356
SizeType GetFragStringLength() const
Definition: uri.h:196
SizeType GetBaseStringLength() const
Definition: uri.h:183
bool operator==(const GenericUri &rhs) const
Equality operators.
Definition: uri.h:230
const Ch * GetSchemeString() const
Definition: uri.h:184
const Ch * GetBaseString() const
Definition: uri.h:182
SizeType GetSchemeStringLength() const
Definition: uri.h:185
const Ch * GetPathString() const
Definition: uri.h:191
SizeType GetStringLength() const
Definition: uri.h:181
GenericUri(const T &uri, Allocator *allocator=0)
Definition: uri.h:85
void Get(T &uri, Allocator &allocator)
Getters.
Definition: uri.h:175
GenericUri(Allocator *allocator=0)
Constructors.
Definition: uri.h:42
bool operator!=(const GenericUri &rhs) const
Definition: uri.h:232
const Ch * GetAuthString() const
Definition: uri.h:189
Concept for allocating, resizing and freeing memory block.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:451
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:746
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:429
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:742
GenericUri< Value > Uri
GenericUri for Value (UTF-8, default allocator).
Definition: uri.h:645