summaryrefslogtreecommitdiff
path: root/test.adb
blob: cc93b774c36362aaff96094009b591331365aca4 (plain) (blame)
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
with Ada.Text_IO;
with Text_IO; use Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings; use Ada.Strings;
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Test is
    File_Name: constant String := "colors.txt";
    F: File_Type;

    function Chop_By(Src: in out Unbounded_String; Pattern: String) return Unbounded_String is
        Space_Index: Integer := Index(Src, Pattern);
        Result: Unbounded_String;
    begin
        if Space_Index = 0 then
            Result := Src;
            Src := Null_Unbounded_String;
        else
            Result := Unbounded_Slice(Src, 1, Space_Index - 1);
            Src := Unbounded_Slice(Src, Space_Index + 1, Length(Src));
        end if;

        return Result;
    end;
begin
    Open(F, In_File, File_Name);
    while not End_Of_File(F) loop
        declare
            Line: Unbounded_String := To_Unbounded_String(Get_Line(F));
        begin
            Line := Trim(Line, Ada.Strings.Left);
            Put_Line('"' & To_String(Chop_By(Line, " ")) & '"');

            for Times in 1..4 loop
                Line := Trim(Line, Ada.Strings.Left);
                declare
                    Token: Unbounded_String := Chop_By(Line, " ");
                begin
                    --  Put_Line(Float'Value(To_String(Token))'Image);
                    Put_Line(To_String(Token));
                end;
            end loop;
        end;
        Put_Line("------------------------------");
    end loop;
    Close(F);
end;