Debian Codegraph @

gcc/ada/libgnat/s-casuti.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . C A S E _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1995-2025, AdaCore --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- Ghost code, loop invariants and assertions in this unit are meant for
33 -- analysis only, not for run-time checking, as it would be too costly
34 -- otherwise. This is enforced by setting the assertion policy to Ignore.
35
36 pragma Assertion_Policy (Ghost => Ignore,
37 Loop_Invariant => Ignore,
38 Assert => Ignore);
39
40 package body System.Case_Util
41 with SPARK_Mode
42 is
43 --------------
44 -- To_Lower --
45 --------------
46
47 function To_Lower (A : Character) return Character is
48 A_Val : constant Natural := Character'Pos (A);
49
50 begin
51 if A in 'A' .. 'Z'
52 or else A_Val in 16#C0# .. 16#D6#
53 or else A_Val in 16#D8# .. 16#DE#
54 then
55 return Character'Val (A_Val + 16#20#);
56 else
57 return A;
58 end if;
59 end To_Lower;
60
61 procedure To_Lower (A : in out String) is
62 begin
63 for J in A'Range loop
64 A (J) := To_Lower (A (J));
65
66 pragma Loop_Invariant
67 (for all K in A'First .. J => A (K) = To_Lower (A'Loop_Entry (K)));
68 end loop;
69 end To_Lower;
70
71 function To_Lower (A : String) return String is
72 Result : String := A;
73 begin
74 To_Lower (Result);
75 return Result;
76 end To_Lower;
77
78 --------------
79 -- To_Mixed --
80 --------------
81
82 procedure To_Mixed (A : in out String) is
83 Ucase : Boolean := True;
84
85 begin
86 for J in A'Range loop
87 if Ucase then
88 A (J) := To_Upper (A (J));
89 else
90 A (J) := To_Lower (A (J));
91 end if;
92
93 pragma Loop_Invariant
94 (for all K in A'First .. J =>
95 (if K = A'First
96 or else A'Loop_Entry (K - 1) = '_'
97 then
98 A (K) = To_Upper (A'Loop_Entry (K))
99 else
100 A (K) = To_Lower (A'Loop_Entry (K))));
101
102 Ucase := A (J) = '_';
103 end loop;
104 end To_Mixed;
105
106 function To_Mixed (A : String) return String is
107 Result : String := A;
108 begin
109 To_Mixed (Result);
110 return Result;
111 end To_Mixed;
112
113 --------------
114 -- To_Upper --
115 --------------
116
117 function To_Upper (A : Character) return Character is
118 A_Val : constant Natural := Character'Pos (A);
119
120 begin
121 if A in 'a' .. 'z'
122 or else A_Val in 16#E0# .. 16#F6#
123 or else A_Val in 16#F8# .. 16#FE#
124 then
125 return Character'Val (A_Val - 16#20#);
126 else
127 return A;
128 end if;
129 end To_Upper;
130
131 procedure To_Upper (A : in out String) is
132 begin
133 for J in A'Range loop
134 A (J) := To_Upper (A (J));
135
136 pragma Loop_Invariant
137 (for all K in A'First .. J => A (K) = To_Upper (A'Loop_Entry (K)));
138 end loop;
139 end To_Upper;
140
141 function To_Upper (A : String) return String is
142 Result : String := A;
143 begin
144 To_Upper (Result);
145 return Result;
146 end To_Upper;
147
148 end System.Case_Util;