annotate gcc/ada/libgnat/g-spchge.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . S P E L L I N G _ C H E C K E R _ G E N E R I C --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1998-2018, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 pragma Compiler_Unit_Warning;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 package body GNAT.Spelling_Checker_Generic is
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 ------------------------
kono
parents:
diff changeset
37 -- Is_Bad_Spelling_Of --
kono
parents:
diff changeset
38 ------------------------
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 function Is_Bad_Spelling_Of
kono
parents:
diff changeset
41 (Found : String_Type;
kono
parents:
diff changeset
42 Expect : String_Type) return Boolean
kono
parents:
diff changeset
43 is
kono
parents:
diff changeset
44 FN : constant Natural := Found'Length;
kono
parents:
diff changeset
45 FF : constant Natural := Found'First;
kono
parents:
diff changeset
46 FL : constant Natural := Found'Last;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 EN : constant Natural := Expect'Length;
kono
parents:
diff changeset
49 EF : constant Natural := Expect'First;
kono
parents:
diff changeset
50 EL : constant Natural := Expect'Last;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Letter_o : constant Char_Type := Char_Type'Val (Character'Pos ('o'));
kono
parents:
diff changeset
53 Digit_0 : constant Char_Type := Char_Type'Val (Character'Pos ('0'));
kono
parents:
diff changeset
54 Digit_9 : constant Char_Type := Char_Type'Val (Character'Pos ('9'));
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 begin
kono
parents:
diff changeset
57 -- If both strings null, then we consider this a match, but if one
kono
parents:
diff changeset
58 -- is null and the other is not, then we definitely do not match
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 if FN = 0 then
kono
parents:
diff changeset
61 return (EN = 0);
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 elsif EN = 0 then
kono
parents:
diff changeset
64 return False;
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 -- If first character does not match, then we consider that this is
kono
parents:
diff changeset
67 -- definitely not a misspelling. An exception is when we expect a
kono
parents:
diff changeset
68 -- letter O and found a zero.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 elsif Found (FF) /= Expect (EF)
kono
parents:
diff changeset
71 and then (Found (FF) /= Digit_0 or else Expect (EF) /= Letter_o)
kono
parents:
diff changeset
72 then
kono
parents:
diff changeset
73 return False;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 -- Not a bad spelling if both strings are 1-2 characters long
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 elsif FN < 3 and then EN < 3 then
kono
parents:
diff changeset
78 return False;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 -- Lengths match. Execute loop to check for a single error, single
kono
parents:
diff changeset
81 -- transposition or exact match (we only fall through this loop if
kono
parents:
diff changeset
82 -- one of these three conditions is found).
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 elsif FN = EN then
kono
parents:
diff changeset
85 for J in 1 .. FN - 2 loop
kono
parents:
diff changeset
86 if Expect (EF + J) /= Found (FF + J) then
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- If both mismatched characters are digits, then we do
kono
parents:
diff changeset
89 -- not consider it a misspelling (e.g. B345 is not a
kono
parents:
diff changeset
90 -- misspelling of B346, it is something quite different)
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 if Expect (EF + J) in Digit_0 .. Digit_9
kono
parents:
diff changeset
93 and then Found (FF + J) in Digit_0 .. Digit_9
kono
parents:
diff changeset
94 then
kono
parents:
diff changeset
95 return False;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 elsif Expect (EF + J + 1) = Found (FF + J + 1)
kono
parents:
diff changeset
98 and then Expect (EF + J + 2 .. EL) = Found (FF + J + 2 .. FL)
kono
parents:
diff changeset
99 then
kono
parents:
diff changeset
100 return True;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 elsif Expect (EF + J) = Found (FF + J + 1)
kono
parents:
diff changeset
103 and then Expect (EF + J + 1) = Found (FF + J)
kono
parents:
diff changeset
104 and then Expect (EF + J + 2 .. EL) = Found (FF + J + 2 .. FL)
kono
parents:
diff changeset
105 then
kono
parents:
diff changeset
106 return True;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 else
kono
parents:
diff changeset
109 return False;
kono
parents:
diff changeset
110 end if;
kono
parents:
diff changeset
111 end if;
kono
parents:
diff changeset
112 end loop;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 -- At last character. Test digit case as above, otherwise we
kono
parents:
diff changeset
115 -- have a match since at most this last character fails to match.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 if Expect (EL) in Digit_0 .. Digit_9
kono
parents:
diff changeset
118 and then Found (FL) in Digit_0 .. Digit_9
kono
parents:
diff changeset
119 and then Expect (EL) /= Found (FL)
kono
parents:
diff changeset
120 then
kono
parents:
diff changeset
121 return False;
kono
parents:
diff changeset
122 else
kono
parents:
diff changeset
123 return True;
kono
parents:
diff changeset
124 end if;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 -- Length is 1 too short. Execute loop to check for single deletion
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 elsif FN = EN - 1 then
kono
parents:
diff changeset
129 for J in 1 .. FN - 1 loop
kono
parents:
diff changeset
130 if Found (FF + J) /= Expect (EF + J) then
kono
parents:
diff changeset
131 return Found (FF + J .. FL) = Expect (EF + J + 1 .. EL);
kono
parents:
diff changeset
132 end if;
kono
parents:
diff changeset
133 end loop;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 -- If we fall through then the last character was missing, which
kono
parents:
diff changeset
136 -- we consider to be a match (e.g. found xyz, expected xyza).
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 return True;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 -- Length is 1 too long. Execute loop to check for single insertion
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 elsif FN = EN + 1 then
kono
parents:
diff changeset
143 for J in 1 .. EN - 1 loop
kono
parents:
diff changeset
144 if Found (FF + J) /= Expect (EF + J) then
kono
parents:
diff changeset
145 return Found (FF + J + 1 .. FL) = Expect (EF + J .. EL);
kono
parents:
diff changeset
146 end if;
kono
parents:
diff changeset
147 end loop;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 -- If we fall through then the last character was an additional
kono
parents:
diff changeset
150 -- character, which is a match (e.g. found xyza, expected xyz).
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 return True;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 -- Length is completely wrong
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 else
kono
parents:
diff changeset
157 return False;
kono
parents:
diff changeset
158 end if;
kono
parents:
diff changeset
159 end Is_Bad_Spelling_Of;
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 end GNAT.Spelling_Checker_Generic;