Skip to content

Commit 28bcbd3

Browse files
author
Steve Hanson
committed
make std::string optional
1 parent 494447b commit 28bcbd3

File tree

6 files changed

+1015
-416
lines changed

6 files changed

+1015
-416
lines changed

include/rapidjson/internal/strfunc.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ inline SizeType StrLen(const wchar_t* s) {
4545
return SizeType(std::wcslen(s));
4646
}
4747

48+
//! Custom strcmpn() which works on different character types.
49+
/*! \tparam Ch Character type (e.g. char, wchar_t, short)
50+
\param s1 Null-terminated input string.
51+
\param s2 Null-terminated input string.
52+
\return 0 if equal
53+
*/
54+
template<typename Ch>
55+
inline int StrCmp(const Ch* s1, const Ch* s2) {
56+
RAPIDJSON_ASSERT(s1 != 0);
57+
RAPIDJSON_ASSERT(s2 != 0);
58+
while(*s1 && (*s1 == *s2)) { s1++; s2++; }
59+
return static_cast<unsigned>(*s1) < static_cast<unsigned>(*s2) ? -1 : static_cast<unsigned>(*s1) > static_cast<unsigned>(*s2);
60+
}
61+
4862
//! Returns number of code points in a encoded string.
4963
template<typename Encoding>
5064
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {

include/rapidjson/pointer.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,7 @@ class GenericPointer {
554554
// See if we have an id, and if so resolve with the current base
555555
typename ValueType::MemberIterator m = v->FindMember(kIdValue);
556556
if (m != v->MemberEnd() && (m->value).IsString()) {
557-
UriType here = UriType(m->value);
558-
here.Resolve(base);
557+
UriType here = UriType(m->value, allocator_).Resolve(base, allocator_);
559558
base = here;
560559
}
561560
m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
@@ -576,7 +575,7 @@ class GenericPointer {
576575
// Error: unresolved token
577576
if (unresolvedTokenIndex)
578577
*unresolvedTokenIndex = static_cast<size_t>(t - tokens_);
579-
return UriType();
578+
return UriType(allocator_);
580579
}
581580
return base;
582581
}

include/rapidjson/schema.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,8 @@ class Schema {
494494
// If we have an id property, resolve it with the in-scope id
495495
if (const ValueType* v = GetMember(value, GetIdString())) {
496496
if (v->IsString()) {
497-
UriType local = UriType(*v);
498-
local.Resolve(id_);
499-
id_ = local;
497+
UriType local(*v, allocator);
498+
id_ = local.Resolve(id_, allocator);
500499
}
501500
}
502501

@@ -1659,7 +1658,7 @@ class GenericSchemaDocument {
16591658

16601659
Ch noUri[1] = {0};
16611660
uri_.SetString(uri ? uri : noUri, uriLength, *allocator_);
1662-
docId_ = UriType(uri_);
1661+
docId_ = UriType(uri_, allocator_);
16631662

16641663
typeless_ = static_cast<SchemaType*>(allocator_->Malloc(sizeof(SchemaType)));
16651664
new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_, docId_);
@@ -1792,8 +1791,7 @@ class GenericSchemaDocument {
17921791
if (len > 0) {
17931792
// First resolve $ref against the in-scope id
17941793
UriType scopeId = id;
1795-
UriType ref = UriType(itr->value);
1796-
ref.Resolve(scopeId);
1794+
UriType ref = UriType(itr->value, allocator_).Resolve(scopeId, allocator_);
17971795
// See if the resolved $ref minus the fragment matches a resolved id in this document
17981796
// Search from the root. Returns the subschema in the document and its absolute JSON pointer.
17991797
PointerType basePointer = PointerType();
@@ -1851,7 +1849,7 @@ class GenericSchemaDocument {
18511849
// See if the fragment matches an id in this document.
18521850
// Search from the base we just established. Returns the subschema in the document and its absolute JSON pointer.
18531851
PointerType pointer = PointerType();
1854-
if (const ValueType *pv = FindId(*base, ref, pointer, UriType(ref.GetBase()), true, basePointer)) {
1852+
if (const ValueType *pv = FindId(*base, ref, pointer, UriType(ref.GetBaseString(), ref.GetBaseStringLength(), allocator_), true, basePointer)) {
18551853
if (!IsCyclicRef(pointer)) {
18561854
//GenericStringBuffer<EncodingType> sb;
18571855
//pointer.StringifyUriFragment(sb);
@@ -1887,8 +1885,7 @@ class GenericSchemaDocument {
18871885
// Establish the base URI of this object
18881886
typename ValueType::ConstMemberIterator m = doc.FindMember(SchemaType::GetIdString());
18891887
if (m != doc.MemberEnd() && m->value.GetType() == kStringType) {
1890-
localuri = UriType(m->value);
1891-
localuri.Resolve(baseuri);
1888+
localuri = UriType(m->value, allocator_).Resolve(baseuri, allocator_);
18921889
}
18931890
// See if it matches
18941891
if (localuri.Match(finduri, full)) {

0 commit comments

Comments
 (0)