File tree 3 files changed +34
-5
lines changed
3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 19
19
20
20
-- -----------------------------------------------------------------------
21
21
22
+ with Ada.Exceptions ;
23
+ use Ada.Exceptions;
22
24
with Ada.Characters.Latin_1 ;
23
25
24
26
package body Apagerlib.Backend is
@@ -68,7 +70,10 @@ package body Apagerlib.Backend is
68
70
end loop ;
69
71
70
72
exception
71
- when No_More_Char => raise No_Line_Found;
73
+ when Exc : No_More_Char =>
74
+ Raise_Exception (No_Line_Found'Identity,
75
+ " Next_Line could not find new line because: " &
76
+ Exception_Message (Exc));
72
77
end Next_Line ;
73
78
74
79
function Next_Line_Position (Stream : in out Backend_Stream'Class;
@@ -103,13 +108,15 @@ package body Apagerlib.Backend is
103
108
raise No_Line_Found;
104
109
end if ;
105
110
106
- while Stream.Current_Position > 1 and then C /= LF and then C /= CR
107
- loop
111
+ while C /= LF and then C /= CR loop
108
112
C := Stream.Previous_Char;
109
113
end loop ;
110
114
111
115
exception
112
- when No_More_Char => return ;
116
+ when Exc : No_More_Char =>
117
+ Raise_Exception (No_Line_Found'Identity,
118
+ " Could not find previous line beacuse: "
119
+ & Exception_Message (Exc));
113
120
end Previous_Line ;
114
121
115
122
function Previous_Line_Position (Stream : in out Backend_Stream'Class;
Original file line number Diff line number Diff line change @@ -262,7 +262,8 @@ package body Apagerlib.Memories is
262
262
Memory.Current_BIP := Page_Limit;
263
263
else
264
264
-- No previous page!
265
- raise No_Byte_Found;
265
+ Raise_Exception (No_More_Char'Identity,
266
+ " Could not find previous character at first position." );
266
267
end if ;
267
268
end if ;
268
269
end Previous_Char ;
Original file line number Diff line number Diff line change 19
19
20
20
-- -----------------------------------------------------------------------
21
21
22
+ with Ada.Exceptions ;
23
+ use Ada.Exceptions;
22
24
with Ada.Text_IO ; use Ada.Text_IO;
23
25
with Ada.Command_Line ; use Ada.Command_Line;
24
26
with Apagerlib.Backend ; use Apagerlib.Backend;
@@ -61,6 +63,15 @@ procedure Apager_Backend_Test is
61
63
Memory.Next_Line;
62
64
Put (Memory.Current_Position'Image);
63
65
end loop ;
66
+
67
+ exception
68
+ when Exc : Apagerlib.Backend.No_Line_Found =>
69
+ Put (" " );
70
+ if Memory.End_Of_File then
71
+ Put_Line (" No new line character at end of file." );
72
+ else
73
+ Put_Line (Exception_Message (Exc));
74
+ end if ;
64
75
end Print_Next_Line ;
65
76
66
77
procedure Print_Next_Line_Function is
@@ -76,10 +87,20 @@ procedure Apager_Backend_Test is
76
87
begin
77
88
Memory.End_Position;
78
89
90
+ -- Beware: if the End_Position is a new line it will not be printed.
79
91
while Memory.Current_Position > 1 loop
80
92
Memory.Previous_Line;
81
93
Put (Memory.Current_Position'Image);
82
94
end loop ;
95
+
96
+ exception
97
+ when Exc : Apagerlib.Backend.No_Line_Found =>
98
+ Put (" " );
99
+ if Memory.Current_Position = 1 then
100
+ Put_Line (" No new line character at beginning of file." );
101
+ else
102
+ Put_Line (Exception_Message (Exc));
103
+ end if ;
83
104
end Print_Previous_Line ;
84
105
85
106
procedure Print_Previous_Line_Function is
You can’t perform that action at this time.
0 commit comments