Skip to content

Commit

Permalink
JSON: make unescape_string visible
Browse files Browse the repository at this point in the history
When using the low-level JSON parser, the caller need a way to
unescape strings.

no-issue-check
  • Loading branch information
lambourg committed Oct 16, 2024
1 parent 842ce5e commit 84aecdb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/src/gnatcoll-json.adb
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,26 @@ package body GNATCOLL.JSON is

end Parse_Next;

----------------------
-- Decode_As_String --
----------------------

function Decode_As_String
(Event : JSON_Parser_Event;
Data : GNATCOLL.Buffer.Reader) return String
is
Str : String renames
Data.Token (Event.First, Event.Last);
begin
if Event.Kind /= STRING_VALUE then
raise Invalid_JSON_Stream with
"expected a STRING_VALUE, event is " & Event.Kind'Image;
end if;

return Strings.To_String
(Utility.Un_Escape_String (Str, Str'First, Str'Last));
end Decode_As_String;

----------
-- Read --
----------
Expand Down
5 changes: 5 additions & 0 deletions core/src/gnatcoll-json.ads
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ package GNATCOLL.JSON is
return JSON_Parser_Event;
-- Fetch the next JSON parser event.

function Decode_As_String
(Event : JSON_Parser_Event;
Data : GNATCOLL.Buffer.Reader) return String;
-- Decode a STRING_VALUE as a string.

type JSON_Value_Type is
(JSON_Null_Type,
-- Null value: all such JSON values are equivalent
Expand Down

0 comments on commit 84aecdb

Please sign in to comment.