mirror of https://github.com/Componolit/jwx
Store string offset into elements
This commit is contained in:
parent
18e557096f
commit
0ac32e393a
|
@ -14,6 +14,7 @@ is
|
||||||
|
|
||||||
type Context_Element_Type (Kind : Kind_Type := Kind_Invalid) is
|
type Context_Element_Type (Kind : Kind_Type := Kind_Invalid) is
|
||||||
record
|
record
|
||||||
|
Offset : Natural := 0;
|
||||||
Next_Member : Index_Type := Null_Index;
|
Next_Member : Index_Type := Null_Index;
|
||||||
Next_Value : Index_Type := Null_Index;
|
Next_Value : Index_Type := Null_Index;
|
||||||
case Kind is
|
case Kind is
|
||||||
|
@ -45,9 +46,10 @@ is
|
||||||
-- Invalid_Element --
|
-- Invalid_Element --
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
Invalid_Element : constant Context_Element_Type :=
|
function Invalid_Element (Off : Natural := 0) return Context_Element_Type is
|
||||||
-- Construct invalid element
|
-- Construct invalid element
|
||||||
(Kind => Kind_Invalid,
|
(Kind => Kind_Invalid,
|
||||||
|
Offset => Off,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
|
||||||
|
@ -59,9 +61,10 @@ is
|
||||||
-- Null_Element --
|
-- Null_Element --
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
Null_Element : constant Context_Element_Type :=
|
function Null_Element (Off : Natural) return Context_Element_Type is
|
||||||
-- Construct null element
|
-- Construct null element
|
||||||
(Kind => Kind_Null,
|
(Kind => Kind_Null,
|
||||||
|
Offset => Off,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
|
||||||
|
@ -69,9 +72,10 @@ is
|
||||||
-- Boolean_Element --
|
-- Boolean_Element --
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
function Boolean_Element (Value : Boolean) return Context_Element_Type is
|
function Boolean_Element (Value : Boolean; Off : Natural) return Context_Element_Type is
|
||||||
-- Construct boolean element
|
-- Construct boolean element
|
||||||
(Kind => Kind_Boolean,
|
(Kind => Kind_Boolean,
|
||||||
|
Offset => Off,
|
||||||
Boolean_Value => Value,
|
Boolean_Value => Value,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
@ -80,9 +84,10 @@ is
|
||||||
-- Real_Element --
|
-- Real_Element --
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
function Real_Element (Value : Real_Type) return Context_Element_Type is
|
function Real_Element (Value : Real_Type; Off : Natural) return Context_Element_Type is
|
||||||
-- Construct real element
|
-- Construct real element
|
||||||
(Kind => Kind_Real,
|
(Kind => Kind_Real,
|
||||||
|
Offset => Off,
|
||||||
Real_Value => Value,
|
Real_Value => Value,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
@ -91,9 +96,10 @@ is
|
||||||
-- Integer_Element --
|
-- Integer_Element --
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
function Integer_Element (Value : Integer_Type) return Context_Element_Type is
|
function Integer_Element (Value : Integer_Type; Off : Natural) return Context_Element_Type is
|
||||||
-- Construct integer element
|
-- Construct integer element
|
||||||
(Kind => Kind_Integer,
|
(Kind => Kind_Integer,
|
||||||
|
Offset => Off,
|
||||||
Integer_Value => Value,
|
Integer_Value => Value,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
@ -102,9 +108,12 @@ is
|
||||||
-- String_Element --
|
-- String_Element --
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
function String_Element (String_Start, String_End : Integer) return Context_Element_Type is
|
function String_Element (String_Start : Integer;
|
||||||
|
String_End : Integer;
|
||||||
|
Off : Natural) return Context_Element_Type is
|
||||||
-- Construct string element
|
-- Construct string element
|
||||||
(Kind => Kind_String,
|
(Kind => Kind_String,
|
||||||
|
Offset => Off,
|
||||||
String_Start => String_Start,
|
String_Start => String_Start,
|
||||||
String_End => String_End,
|
String_End => String_End,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
|
@ -114,9 +123,10 @@ is
|
||||||
-- Object_Element --
|
-- Object_Element --
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
Object_Element : constant Context_Element_Type :=
|
function Object_Element (Off : Natural) return Context_Element_Type is
|
||||||
-- Construct object element
|
-- Construct object element
|
||||||
(Kind => Kind_Object,
|
(Kind => Kind_Object,
|
||||||
|
Offset => Off,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
|
||||||
|
@ -124,9 +134,10 @@ is
|
||||||
-- Array_Element --
|
-- Array_Element --
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
Array_Element : constant Context_Element_Type :=
|
function Array_Element (Off : Natural) return Context_Element_Type is
|
||||||
-- Construct array element
|
-- Construct array element
|
||||||
(Kind => Kind_Array,
|
(Kind => Kind_Array,
|
||||||
|
Offset => Off,
|
||||||
Next_Member => Null_Index,
|
Next_Member => Null_Index,
|
||||||
Next_Value => Null_Index);
|
Next_Value => Null_Index);
|
||||||
|
|
||||||
|
@ -350,7 +361,7 @@ is
|
||||||
Base := Data'First + Offset;
|
Base := Data'First + Offset;
|
||||||
if Data (Base .. Base + 3) = "null"
|
if Data (Base .. Base + 3) = "null"
|
||||||
then
|
then
|
||||||
Set (Null_Element);
|
Set (Null_Element (Offset));
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
Offset := Offset + 4;
|
Offset := Offset + 4;
|
||||||
Match := Match_OK;
|
Match := Match_OK;
|
||||||
|
@ -386,7 +397,7 @@ is
|
||||||
Base := Data'First + Offset;
|
Base := Data'First + Offset;
|
||||||
if Data (Base .. Base + 3) = "true"
|
if Data (Base .. Base + 3) = "true"
|
||||||
then
|
then
|
||||||
Set (Boolean_Element (True));
|
Set (Boolean_Element (True, Offset));
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
Offset := Offset + 4;
|
Offset := Offset + 4;
|
||||||
Match := Match_OK;
|
Match := Match_OK;
|
||||||
|
@ -401,7 +412,7 @@ is
|
||||||
|
|
||||||
if Data (Base .. Base + 4) = "false"
|
if Data (Base .. Base + 4) = "false"
|
||||||
then
|
then
|
||||||
Set (Boolean_Element (False));
|
Set (Boolean_Element (False, Offset));
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
Offset := Offset + 5;
|
Offset := Offset + 5;
|
||||||
Match := Match_OK;
|
Match := Match_OK;
|
||||||
|
@ -828,7 +839,7 @@ is
|
||||||
end if;
|
end if;
|
||||||
Tmp := -Tmp;
|
Tmp := -Tmp;
|
||||||
end if;
|
end if;
|
||||||
Set (Real_Element (Tmp));
|
Set (Real_Element (Tmp, Offset));
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
if Match_Exponent = Match_OK
|
if Match_Exponent = Match_OK
|
||||||
|
@ -850,7 +861,7 @@ is
|
||||||
if Negative then
|
if Negative then
|
||||||
Integer_Component := -Integer_Component;
|
Integer_Component := -Integer_Component;
|
||||||
end if;
|
end if;
|
||||||
Set (Integer_Element (Integer_Component));
|
Set (Integer_Element (Integer_Component, Offset));
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
|
@ -939,7 +950,7 @@ is
|
||||||
|
|
||||||
String_End := Data'First + (Offset - 2);
|
String_End := Data'First + (Offset - 2);
|
||||||
|
|
||||||
Set (String_Element (String_Start, String_End));
|
Set (String_Element (String_Start, String_End, Old_Offset));
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
Match := Match_OK;
|
Match := Match_OK;
|
||||||
|
|
||||||
|
@ -979,7 +990,7 @@ is
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
Object_Index := Context_Index;
|
Object_Index := Context_Index;
|
||||||
Set (Object_Element);
|
Set (Object_Element (Old_Offset));
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
Previous_Member := Object_Index;
|
Previous_Member := Object_Index;
|
||||||
|
|
||||||
|
@ -1091,7 +1102,7 @@ is
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
AI := Context_Index;
|
AI := Context_Index;
|
||||||
Set (Array_Element);
|
Set (Array_Element (Old_Offset));
|
||||||
Context_Index := Context_Index + 1;
|
Context_Index := Context_Index + 1;
|
||||||
Previous_Element := AI;
|
Previous_Element := AI;
|
||||||
|
|
||||||
|
@ -1320,4 +1331,10 @@ is
|
||||||
return Last_Index;
|
return Last_Index;
|
||||||
end Pos;
|
end Pos;
|
||||||
|
|
||||||
|
----------------
|
||||||
|
-- Get_Offset --
|
||||||
|
----------------
|
||||||
|
|
||||||
|
function Get_Offset (Index : Index_Type := Null_Index) return Natural is (Get (Index).Offset);
|
||||||
|
|
||||||
end JWX.JSON;
|
end JWX.JSON;
|
||||||
|
|
|
@ -181,4 +181,9 @@ is
|
||||||
-- @param Index Index of array element, current element by default
|
-- @param Index Index of array element, current element by default
|
||||||
-- @return Index to object at Position, End_Index if out of bounds
|
-- @return Index to object at Position, End_Index if out of bounds
|
||||||
|
|
||||||
|
function Get_Offset (Index : Index_Type := Null_Index) return Natural;
|
||||||
|
-- Return offset of an element
|
||||||
|
--
|
||||||
|
-- @return Offset into input string
|
||||||
|
|
||||||
end JWX.JSON;
|
end JWX.JSON;
|
||||||
|
|
Loading…
Reference in New Issue