Skip to content

Commit e712c2f

Browse files
committed
core: new DocAny() factory function
1 parent e69751b commit e712c2f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/core/mormot.core.variants.pas

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,6 +3735,10 @@ function DocDictCopy(const v: variant): IDocDict; overload;
37353735
function DocDictCopy(const dv: TDocVariantData;
37363736
model: TDocVariantModel): IDocDict; overload;
37373737

3738+
/// create a self-owned IDocDict/IDocList from a JSON object/array content
3739+
// - if json is something else than an object or array, returns nil
3740+
function DocAny(const json: RawUtf8; model: TDocVariantModel): IDocAny;
3741+
37383742
var
37393743
/// default TDocVariant model for IDocList/IDocDict
37403744
DocAnyDefaultModel: TDocVariantModel = mFastFloat;
@@ -11613,6 +11617,22 @@ function DocDictFromKeys(const keys: array of RawUtf8; const value: variant;
1161311617
result := d;
1161411618
end;
1161511619

11620+
{ IDocAny factories functions }
11621+
11622+
function DocAny(const json: RawUtf8; model: TDocVariantModel): IDocAny;
11623+
begin
11624+
result := nil;
11625+
case GetFirstJsonToken(pointer(json)) of
11626+
jtObjectStart:
11627+
result := DocDict(model);
11628+
jtArrayStart:
11629+
result := DocList(model);
11630+
else
11631+
exit;
11632+
end;
11633+
result.SetJson(json);
11634+
end;
11635+
1161611636

1161711637
{ TDocAny }
1161811638

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.3.13156'
1+
'2.3.13157'

0 commit comments

Comments
 (0)