vss_24.0.0_b4d0be7c/examples/blogs/json_1/read_message.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
with Ada.Wide_Wide_Text_IO;

with VSS.JSON.Pull_Readers.Simple;
with VSS.JSON.Streams;
with VSS.Strings.Conversions;
with VSS.Text_Streams.Memory_UTF8_Input;

with Blog_Utilities;
with Messages;
with Input;

procedure Read_Message is
   use type VSS.JSON.Streams.JSON_Stream_Element_Kind;

   Text    : constant Wide_Wide_String :=
     "{""range"":{""start"":{""line"":5,""character"":23},"
     & """end"":{""line"":6,""character"":0}},""newText"":""text to insert""}";

   Stream  :
     aliased VSS.Text_Streams.Memory_UTF8_Input.Memory_UTF8_Input_Stream;
   Reader  : VSS.JSON.Pull_Readers.Simple.JSON_Simple_Pull_Reader;
   Message : Messages.LSP_Text_Edit;
   Success : Boolean := True;

begin
   Stream.Set_Data (Blog_Utilities.Encode (Text));
   Reader.Set_Stream (Stream'Unchecked_Access);

   if Reader.Read_Next /= VSS.JSON.Streams.Start_Document then
      Success := False;
   end if;

   Input.Read (Reader, Message, Success);

   if Success
     and then Reader.Read_Next /= VSS.JSON.Streams.End_Document
   then
      Success := False;
   end if;

   if Success then
      Ada.Wide_Wide_Text_IO.Put_Line
        ("Start line:     "
         & Natural'Wide_Wide_Image (Message.Text_Range.Range_Start.Line));
      Ada.Wide_Wide_Text_IO.Put_Line
        ("Start character:"
         & Natural'Wide_Wide_Image (Message.Text_Range.Range_Start.Character));
      Ada.Wide_Wide_Text_IO.Put_Line
        ("End line:       "
         & Natural'Wide_Wide_Image (Message.Text_Range.Range_End.Line));
      Ada.Wide_Wide_Text_IO.Put_Line
        ("End character:  "
         & Natural'Wide_Wide_Image (Message.Text_Range.Range_End.Character));
      Ada.Wide_Wide_Text_IO.Put_Line
        ("New text:        """
         & VSS.Strings.Conversions.To_Wide_Wide_String (Message.New_Text) & '"');
   end if;
end Read_Message;