994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
procedure Test_Tokenization (Report : in out NT.Reporter'Class) is
Name : constant String := "Simple tokenization";
Space : constant Ada.Strings.Maps.Character_Set
:= Ada.Strings.Maps.To_Set (" ");
function Has_Spaces (S : String) return Boolean;
function Trim_Spaces (S : String) return String_Slices.String_Range;
function Has_Spaces (S : String) return Boolean is
begin
return Ada.Strings.Fixed.Index (S, Space) > 0;
end Has_Spaces;
function Trim_Spaces (S : String) return String_Slices.String_Range is
Result : String_Slices.String_Range;
N : Natural;
begin
N := Ada.Strings.Fixed.Index (S, Space, Ada.Strings.Outside);
if N = 0 then
return (1, 0);
end if;
Result.First := N;
N := Ada.Strings.Fixed.Index
(S, Space, Ada.Strings.Outside, Ada.Strings.Backward);
String_Slices.Set_Last (Result, N);
return Result;
end Trim_Spaces;
begin
declare
Set : Slice_Sets.Slice_Set := Slice_Sets.To_Slice_Set (Parent_String);
R : String_Slices.String_Range;
N : Natural;
begin
N := Set.Index (Space);
|
>
>
>
>
>
>
>
>
|
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
|
procedure Test_Tokenization (Report : in out NT.Reporter'Class) is
Name : constant String := "Simple tokenization";
Space : constant Ada.Strings.Maps.Character_Set
:= Ada.Strings.Maps.To_Set (" ");
function Has_Spaces (S : String) return Boolean;
function Is_Fox (S : String) return Boolean;
function Trim_Spaces (S : String) return String_Slices.String_Range;
function Has_Spaces (S : String) return Boolean is
begin
return Ada.Strings.Fixed.Index (S, Space) > 0;
end Has_Spaces;
function Is_Fox (S : String) return Boolean is
begin
return S = "fox";
end Is_Fox;
function Trim_Spaces (S : String) return String_Slices.String_Range is
Result : String_Slices.String_Range;
N : Natural;
begin
N := Ada.Strings.Fixed.Index (S, Space, Ada.Strings.Outside);
if N = 0 then
return (1, 0);
end if;
Result.First := N;
N := Ada.Strings.Fixed.Index
(S, Space, Ada.Strings.Outside, Ada.Strings.Backward);
String_Slices.Set_Last (Result, N);
return Result;
end Trim_Spaces;
use type String_Slices.String_Range;
begin
declare
Set : Slice_Sets.Slice_Set := Slice_Sets.To_Slice_Set (Parent_String);
R : String_Slices.String_Range;
N : Natural;
begin
N := Set.Index (Space);
|
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
|
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected space at" & Integer'Image (N));
Dump (Report, Set);
return;
end if;
R := Set.Find_Slice (Has_Spaces'Access);
if R.First /= 1 or R.Length /= 0 then
Report.Item (Name, NT.Fail);
Report.Info ("Unxpected slice found at "
& String_Slices.Image (R));
Dump (Report, Set);
return;
end if;
end;
Report.Item (Name, NT.Success);
exception
when Error : others => Report.Report_Exception (Name, Error);
end Test_Tokenization;
end Natools.String_Slice_Set_Tests;
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
|
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected space at" & Integer'Image (N));
Dump (Report, Set);
return;
end if;
R := Set.Find_Slice (Has_Spaces'Access);
if R /= (First => 1, Length => 0) then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected slice found at "
& String_Slices.Image (R));
Dump (Report, Set);
return;
end if;
R := Set.Find_Slice (Is_Fox'Access, Ada.Strings.Backward);
if R = (First => 1, Length => 0) then
Report.Item (Name, NT.Fail);
Report.Info ("Unable to find ""fox"" slice");
Dump (Report, Set);
return;
elsif R /= (First => 27, Length => 3) then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected ""fox"" slice found at "
& String_Slices.Image (R));
Dump (Report, Set);
return;
end if;
end;
Report.Item (Name, NT.Success);
exception
when Error : others => Report.Report_Exception (Name, Error);
end Test_Tokenization;
end Natools.String_Slice_Set_Tests;
|