Skip to content

Commit f783619

Browse files
committed
add jsonGetArrayLength
1 parent a9b6e47 commit f783619

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/JSON.ctx.vhdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ context json_ctx is
4747
use JSON.json.jsonGetBooleanArray;
4848
use JSON.json.jsonGetIntegerArray;
4949
use JSON.json.jsonGetRealArray;
50+
use JSON.json.jsonGetArrayLength;
5051
use JSON.json.jsonIsBoolean;
5152
use JSON.json.jsonIsNull;
5253
use JSON.json.jsonIsString;

src/JSON.pkg.vhdl

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ package JSON is
113113
function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector;
114114
function jsonGetRealArray(JSONContext : T_JSON; Path : string; Len : positive) return real_vector;
115115

116-
function jsonGetNumberArrayLength(JSONContext : T_JSON; Path : string) return natural;
116+
function jsonGetArrayLength(JSONContext : T_JSON; Path : string; IsType: character) return natural;
117117
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
118118
function jsonIsNull(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
119119
function jsonIsString(JSONContext : T_JSON; Path : STRING) return BOOLEAN;
@@ -1646,13 +1646,9 @@ package body JSON is
16461646

16471647
-- function to get a boolean_vector from the compressed content extracted from a JSON input
16481648
function jsonGetBooleanArray(JSONContext : T_JSON; Path : string) return boolean_vector is
1649-
variable len: natural:=0;
16501649
begin
1651-
while jsonIsBoolean(JSONContext, Path & "/" & to_string(len)) loop
1652-
len := len+1;
1653-
end loop;
1654-
return jsonGetBooleanArray(JSONContext, Path, len);
1655-
end function;
1650+
return jsonGetBooleanArray(JSONContext, Path, jsonGetArrayLength(JSONContext, Path, 'b'));
1651+
end;
16561652

16571653
-- function to get a boolean_vector of a fixed length from the compressed content extracted from a JSON input
16581654
function jsonGetBooleanArray(JSONContext : T_JSON; Path : string; Len : positive) return boolean_vector is
@@ -1662,14 +1658,13 @@ package body JSON is
16621658
return_value(i) := boolean'value(jsonGetString(JSONContext, Path & "/" & to_string(i)));
16631659
end loop;
16641660
return return_value;
1665-
end function;
1661+
end;
16661662

16671663
-- function to get a integer_vector from the compressed content extracted from a JSON input
16681664
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string) return integer_vector is
1669-
variable len: natural:=0;
16701665
begin
1671-
return jsonGetIntegerArray(JSONContext, Path, jsonGetNumberArrayLength(JSONContext, Path));
1672-
end function;
1666+
return jsonGetIntegerArray(JSONContext, Path, jsonGetArrayLength(JSONContext, Path, 'i'));
1667+
end;
16731668

16741669
-- function to get a integer_vector of a fixed length from the compressed content extracted from a JSON input
16751670
function jsonGetIntegerArray(JSONContext : T_JSON; Path : string; Len : positive) return integer_vector is
@@ -1679,14 +1674,13 @@ package body JSON is
16791674
return_value(i) := to_natural_dec(jsonGetString(JSONContext, Path & "/" & to_string(i)));
16801675
end loop;
16811676
return return_value;
1682-
end function;
1677+
end;
16831678

16841679
-- function to get a real_vector from the compressed content extracted from a JSON input
16851680
function jsonGetRealArray(JSONContext : T_JSON; Path : string) return real_vector is
1686-
variable len: natural:=0;
16871681
begin
1688-
return jsonGetRealArray(JSONContext, Path, jsonGetNumberArrayLength(JSONContext, Path));
1689-
end function;
1682+
return jsonGetRealArray(JSONContext, Path, jsonGetArrayLength(JSONContext, Path, 'r'));
1683+
end;
16901684

16911685
-- function to get a real_vector of a fixed length from the compressed content extracted from a JSON input
16921686
function jsonGetRealArray(JSONContext : T_JSON; Path : string; Len : positive) return real_vector is
@@ -1696,16 +1690,21 @@ package body JSON is
16961690
return_value(i) := real'value(jsonGetString(JSONContext, Path & "/" & to_string(i)));
16971691
end loop;
16981692
return return_value;
1699-
end function;
1693+
end;
17001694

1701-
function jsonGetNumberArrayLength(JSONContext : T_JSON; Path : string) return natural is
1695+
function jsonGetArrayLength(JSONContext : T_JSON; Path : string; IsType: character) return natural is
17021696
variable len: natural:=0;
1697+
variable val: boolean:=true;
17031698
begin
1704-
while jsonIsNumber(JSONContext, Path & "/" & to_string(len)) loop
1705-
len := len+1;
1699+
while(val) loop
1700+
case IsType is
1701+
when 'b' => val := jsonIsBoolean(JSONContext, Path & "/" & to_string(len));
1702+
when others => val := jsonIsNumber(JSONContext, Path & "/" & to_string(len));
1703+
end case;
1704+
len := len+1;
17061705
end loop;
1707-
return len;
1708-
end function;
1706+
return len-1;
1707+
end;
17091708

17101709
function jsonIsBoolean(JSONContext : T_JSON; Path : STRING) return BOOLEAN is
17111710
constant ElementIndex : T_UINT16 := jsonGetElementIndex(JSONContext, Path);

0 commit comments

Comments
 (0)