annotate gcc/ada/libgnat/a-stzfix.adb @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
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 -- A D A . S T R I N G S . W I D E _ F I X E D --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
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 with Ada.Strings.Wide_Wide_Maps; use Ada.Strings.Wide_Wide_Maps;
kono
parents:
diff changeset
33 with Ada.Strings.Wide_Wide_Search;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 package body Ada.Strings.Wide_Wide_Fixed is
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 ------------------------
kono
parents:
diff changeset
38 -- Search Subprograms --
kono
parents:
diff changeset
39 ------------------------
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 function Index
kono
parents:
diff changeset
42 (Source : Wide_Wide_String;
kono
parents:
diff changeset
43 Pattern : Wide_Wide_String;
kono
parents:
diff changeset
44 Going : Direction := Forward;
kono
parents:
diff changeset
45 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
kono
parents:
diff changeset
46 Wide_Wide_Maps.Identity)
kono
parents:
diff changeset
47 return Natural
kono
parents:
diff changeset
48 renames Ada.Strings.Wide_Wide_Search.Index;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 function Index
kono
parents:
diff changeset
51 (Source : Wide_Wide_String;
kono
parents:
diff changeset
52 Pattern : Wide_Wide_String;
kono
parents:
diff changeset
53 Going : Direction := Forward;
kono
parents:
diff changeset
54 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
kono
parents:
diff changeset
55 return Natural
kono
parents:
diff changeset
56 renames Ada.Strings.Wide_Wide_Search.Index;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 function Index
kono
parents:
diff changeset
59 (Source : Wide_Wide_String;
kono
parents:
diff changeset
60 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
61 Test : Membership := Inside;
kono
parents:
diff changeset
62 Going : Direction := Forward) return Natural
kono
parents:
diff changeset
63 renames Ada.Strings.Wide_Wide_Search.Index;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 function Index
kono
parents:
diff changeset
66 (Source : Wide_Wide_String;
kono
parents:
diff changeset
67 Pattern : Wide_Wide_String;
kono
parents:
diff changeset
68 From : Positive;
kono
parents:
diff changeset
69 Going : Direction := Forward;
kono
parents:
diff changeset
70 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
kono
parents:
diff changeset
71 Wide_Wide_Maps.Identity)
kono
parents:
diff changeset
72 return Natural
kono
parents:
diff changeset
73 renames Ada.Strings.Wide_Wide_Search.Index;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 function Index
kono
parents:
diff changeset
76 (Source : Wide_Wide_String;
kono
parents:
diff changeset
77 Pattern : Wide_Wide_String;
kono
parents:
diff changeset
78 From : Positive;
kono
parents:
diff changeset
79 Going : Direction := Forward;
kono
parents:
diff changeset
80 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
kono
parents:
diff changeset
81 return Natural
kono
parents:
diff changeset
82 renames Ada.Strings.Wide_Wide_Search.Index;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 function Index
kono
parents:
diff changeset
85 (Source : Wide_Wide_String;
kono
parents:
diff changeset
86 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
87 From : Positive;
kono
parents:
diff changeset
88 Test : Membership := Inside;
kono
parents:
diff changeset
89 Going : Direction := Forward) return Natural
kono
parents:
diff changeset
90 renames Ada.Strings.Wide_Wide_Search.Index;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 function Index_Non_Blank
kono
parents:
diff changeset
93 (Source : Wide_Wide_String;
kono
parents:
diff changeset
94 Going : Direction := Forward) return Natural
kono
parents:
diff changeset
95 renames Ada.Strings.Wide_Wide_Search.Index_Non_Blank;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 function Index_Non_Blank
kono
parents:
diff changeset
98 (Source : Wide_Wide_String;
kono
parents:
diff changeset
99 From : Positive;
kono
parents:
diff changeset
100 Going : Direction := Forward) return Natural
kono
parents:
diff changeset
101 renames Ada.Strings.Wide_Wide_Search.Index_Non_Blank;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 function Count
kono
parents:
diff changeset
104 (Source : Wide_Wide_String;
kono
parents:
diff changeset
105 Pattern : Wide_Wide_String;
kono
parents:
diff changeset
106 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping :=
kono
parents:
diff changeset
107 Wide_Wide_Maps.Identity)
kono
parents:
diff changeset
108 return Natural
kono
parents:
diff changeset
109 renames Ada.Strings.Wide_Wide_Search.Count;
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 function Count
kono
parents:
diff changeset
112 (Source : Wide_Wide_String;
kono
parents:
diff changeset
113 Pattern : Wide_Wide_String;
kono
parents:
diff changeset
114 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
kono
parents:
diff changeset
115 return Natural
kono
parents:
diff changeset
116 renames Ada.Strings.Wide_Wide_Search.Count;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 function Count
kono
parents:
diff changeset
119 (Source : Wide_Wide_String;
kono
parents:
diff changeset
120 Set : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural
kono
parents:
diff changeset
121 renames Ada.Strings.Wide_Wide_Search.Count;
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 procedure Find_Token
kono
parents:
diff changeset
124 (Source : Wide_Wide_String;
kono
parents:
diff changeset
125 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
126 From : Positive;
kono
parents:
diff changeset
127 Test : Membership;
kono
parents:
diff changeset
128 First : out Positive;
kono
parents:
diff changeset
129 Last : out Natural)
kono
parents:
diff changeset
130 renames Ada.Strings.Wide_Wide_Search.Find_Token;
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 procedure Find_Token
kono
parents:
diff changeset
133 (Source : Wide_Wide_String;
kono
parents:
diff changeset
134 Set : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
135 Test : Membership;
kono
parents:
diff changeset
136 First : out Positive;
kono
parents:
diff changeset
137 Last : out Natural)
kono
parents:
diff changeset
138 renames Ada.Strings.Wide_Wide_Search.Find_Token;
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 ---------
kono
parents:
diff changeset
141 -- "*" --
kono
parents:
diff changeset
142 ---------
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 function "*"
kono
parents:
diff changeset
145 (Left : Natural;
kono
parents:
diff changeset
146 Right : Wide_Wide_Character) return Wide_Wide_String
kono
parents:
diff changeset
147 is
kono
parents:
diff changeset
148 Result : Wide_Wide_String (1 .. Left);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 begin
kono
parents:
diff changeset
151 for J in Result'Range loop
kono
parents:
diff changeset
152 Result (J) := Right;
kono
parents:
diff changeset
153 end loop;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 return Result;
kono
parents:
diff changeset
156 end "*";
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 function "*"
kono
parents:
diff changeset
159 (Left : Natural;
kono
parents:
diff changeset
160 Right : Wide_Wide_String) return Wide_Wide_String
kono
parents:
diff changeset
161 is
kono
parents:
diff changeset
162 Result : Wide_Wide_String (1 .. Left * Right'Length);
kono
parents:
diff changeset
163 Ptr : Integer := 1;
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 begin
kono
parents:
diff changeset
166 for J in 1 .. Left loop
kono
parents:
diff changeset
167 Result (Ptr .. Ptr + Right'Length - 1) := Right;
kono
parents:
diff changeset
168 Ptr := Ptr + Right'Length;
kono
parents:
diff changeset
169 end loop;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 return Result;
kono
parents:
diff changeset
172 end "*";
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 ------------
kono
parents:
diff changeset
175 -- Delete --
kono
parents:
diff changeset
176 ------------
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 function Delete
kono
parents:
diff changeset
179 (Source : Wide_Wide_String;
kono
parents:
diff changeset
180 From : Positive;
kono
parents:
diff changeset
181 Through : Natural) return Wide_Wide_String
kono
parents:
diff changeset
182 is
kono
parents:
diff changeset
183 begin
kono
parents:
diff changeset
184 if From not in Source'Range
kono
parents:
diff changeset
185 or else Through > Source'Last
kono
parents:
diff changeset
186 then
kono
parents:
diff changeset
187 raise Index_Error;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 elsif From > Through then
kono
parents:
diff changeset
190 return Source;
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 else
kono
parents:
diff changeset
193 declare
kono
parents:
diff changeset
194 Len : constant Integer := Source'Length - (Through - From + 1);
kono
parents:
diff changeset
195 Result : constant Wide_Wide_String
kono
parents:
diff changeset
196 (Source'First .. Source'First + Len - 1) :=
kono
parents:
diff changeset
197 Source (Source'First .. From - 1) &
kono
parents:
diff changeset
198 Source (Through + 1 .. Source'Last);
kono
parents:
diff changeset
199 begin
kono
parents:
diff changeset
200 return Result;
kono
parents:
diff changeset
201 end;
kono
parents:
diff changeset
202 end if;
kono
parents:
diff changeset
203 end Delete;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 procedure Delete
kono
parents:
diff changeset
206 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
207 From : Positive;
kono
parents:
diff changeset
208 Through : Natural;
kono
parents:
diff changeset
209 Justify : Alignment := Left;
kono
parents:
diff changeset
210 Pad : Wide_Wide_Character := Wide_Wide_Space)
kono
parents:
diff changeset
211 is
kono
parents:
diff changeset
212 begin
kono
parents:
diff changeset
213 Move (Source => Delete (Source, From, Through),
kono
parents:
diff changeset
214 Target => Source,
kono
parents:
diff changeset
215 Justify => Justify,
kono
parents:
diff changeset
216 Pad => Pad);
kono
parents:
diff changeset
217 end Delete;
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 ----------
kono
parents:
diff changeset
220 -- Head --
kono
parents:
diff changeset
221 ----------
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 function Head
kono
parents:
diff changeset
224 (Source : Wide_Wide_String;
kono
parents:
diff changeset
225 Count : Natural;
kono
parents:
diff changeset
226 Pad : Wide_Wide_Character := Wide_Wide_Space) return Wide_Wide_String
kono
parents:
diff changeset
227 is
kono
parents:
diff changeset
228 Result : Wide_Wide_String (1 .. Count);
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 begin
kono
parents:
diff changeset
231 if Count <= Source'Length then
kono
parents:
diff changeset
232 Result := Source (Source'First .. Source'First + Count - 1);
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 else
kono
parents:
diff changeset
235 Result (1 .. Source'Length) := Source;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 for J in Source'Length + 1 .. Count loop
kono
parents:
diff changeset
238 Result (J) := Pad;
kono
parents:
diff changeset
239 end loop;
kono
parents:
diff changeset
240 end if;
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 return Result;
kono
parents:
diff changeset
243 end Head;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 procedure Head
kono
parents:
diff changeset
246 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
247 Count : Natural;
kono
parents:
diff changeset
248 Justify : Alignment := Left;
kono
parents:
diff changeset
249 Pad : Wide_Wide_Character := Ada.Strings.Wide_Wide_Space)
kono
parents:
diff changeset
250 is
kono
parents:
diff changeset
251 begin
kono
parents:
diff changeset
252 Move (Source => Head (Source, Count, Pad),
kono
parents:
diff changeset
253 Target => Source,
kono
parents:
diff changeset
254 Drop => Error,
kono
parents:
diff changeset
255 Justify => Justify,
kono
parents:
diff changeset
256 Pad => Pad);
kono
parents:
diff changeset
257 end Head;
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 ------------
kono
parents:
diff changeset
260 -- Insert --
kono
parents:
diff changeset
261 ------------
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 function Insert
kono
parents:
diff changeset
264 (Source : Wide_Wide_String;
kono
parents:
diff changeset
265 Before : Positive;
kono
parents:
diff changeset
266 New_Item : Wide_Wide_String) return Wide_Wide_String
kono
parents:
diff changeset
267 is
kono
parents:
diff changeset
268 Result : Wide_Wide_String (1 .. Source'Length + New_Item'Length);
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 begin
kono
parents:
diff changeset
271 if Before < Source'First or else Before > Source'Last + 1 then
kono
parents:
diff changeset
272 raise Index_Error;
kono
parents:
diff changeset
273 end if;
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 Result := Source (Source'First .. Before - 1) & New_Item &
kono
parents:
diff changeset
276 Source (Before .. Source'Last);
kono
parents:
diff changeset
277 return Result;
kono
parents:
diff changeset
278 end Insert;
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 procedure Insert
kono
parents:
diff changeset
281 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
282 Before : Positive;
kono
parents:
diff changeset
283 New_Item : Wide_Wide_String;
kono
parents:
diff changeset
284 Drop : Truncation := Error)
kono
parents:
diff changeset
285 is
kono
parents:
diff changeset
286 begin
kono
parents:
diff changeset
287 Move (Source => Insert (Source, Before, New_Item),
kono
parents:
diff changeset
288 Target => Source,
kono
parents:
diff changeset
289 Drop => Drop);
kono
parents:
diff changeset
290 end Insert;
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 ----------
kono
parents:
diff changeset
293 -- Move --
kono
parents:
diff changeset
294 ----------
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 procedure Move
kono
parents:
diff changeset
297 (Source : Wide_Wide_String;
kono
parents:
diff changeset
298 Target : out Wide_Wide_String;
kono
parents:
diff changeset
299 Drop : Truncation := Error;
kono
parents:
diff changeset
300 Justify : Alignment := Left;
kono
parents:
diff changeset
301 Pad : Wide_Wide_Character := Wide_Wide_Space)
kono
parents:
diff changeset
302 is
kono
parents:
diff changeset
303 Sfirst : constant Integer := Source'First;
kono
parents:
diff changeset
304 Slast : constant Integer := Source'Last;
kono
parents:
diff changeset
305 Slength : constant Integer := Source'Length;
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 Tfirst : constant Integer := Target'First;
kono
parents:
diff changeset
308 Tlast : constant Integer := Target'Last;
kono
parents:
diff changeset
309 Tlength : constant Integer := Target'Length;
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 function Is_Padding (Item : Wide_Wide_String) return Boolean;
kono
parents:
diff changeset
312 -- Determinbe if all characters in Item are pad characters
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 function Is_Padding (Item : Wide_Wide_String) return Boolean is
kono
parents:
diff changeset
315 begin
kono
parents:
diff changeset
316 for J in Item'Range loop
kono
parents:
diff changeset
317 if Item (J) /= Pad then
kono
parents:
diff changeset
318 return False;
kono
parents:
diff changeset
319 end if;
kono
parents:
diff changeset
320 end loop;
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 return True;
kono
parents:
diff changeset
323 end Is_Padding;
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 -- Start of processing for Move
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 begin
kono
parents:
diff changeset
328 if Slength = Tlength then
kono
parents:
diff changeset
329 Target := Source;
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 elsif Slength > Tlength then
kono
parents:
diff changeset
332 case Drop is
kono
parents:
diff changeset
333 when Left =>
kono
parents:
diff changeset
334 Target := Source (Slast - Tlength + 1 .. Slast);
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 when Right =>
kono
parents:
diff changeset
337 Target := Source (Sfirst .. Sfirst + Tlength - 1);
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 when Error =>
kono
parents:
diff changeset
340 case Justify is
kono
parents:
diff changeset
341 when Left =>
kono
parents:
diff changeset
342 if Is_Padding (Source (Sfirst + Tlength .. Slast)) then
kono
parents:
diff changeset
343 Target :=
kono
parents:
diff changeset
344 Source (Sfirst .. Sfirst + Target'Length - 1);
kono
parents:
diff changeset
345 else
kono
parents:
diff changeset
346 raise Length_Error;
kono
parents:
diff changeset
347 end if;
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 when Right =>
kono
parents:
diff changeset
350 if Is_Padding (Source (Sfirst .. Slast - Tlength)) then
kono
parents:
diff changeset
351 Target := Source (Slast - Tlength + 1 .. Slast);
kono
parents:
diff changeset
352 else
kono
parents:
diff changeset
353 raise Length_Error;
kono
parents:
diff changeset
354 end if;
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 when Center =>
kono
parents:
diff changeset
357 raise Length_Error;
kono
parents:
diff changeset
358 end case;
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 end case;
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 -- Source'Length < Target'Length
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 else
kono
parents:
diff changeset
365 case Justify is
kono
parents:
diff changeset
366 when Left =>
kono
parents:
diff changeset
367 Target (Tfirst .. Tfirst + Slength - 1) := Source;
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 for J in Tfirst + Slength .. Tlast loop
kono
parents:
diff changeset
370 Target (J) := Pad;
kono
parents:
diff changeset
371 end loop;
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 when Right =>
kono
parents:
diff changeset
374 for J in Tfirst .. Tlast - Slength loop
kono
parents:
diff changeset
375 Target (J) := Pad;
kono
parents:
diff changeset
376 end loop;
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 Target (Tlast - Slength + 1 .. Tlast) := Source;
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 when Center =>
kono
parents:
diff changeset
381 declare
kono
parents:
diff changeset
382 Front_Pad : constant Integer := (Tlength - Slength) / 2;
kono
parents:
diff changeset
383 Tfirst_Fpad : constant Integer := Tfirst + Front_Pad;
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 begin
kono
parents:
diff changeset
386 for J in Tfirst .. Tfirst_Fpad - 1 loop
kono
parents:
diff changeset
387 Target (J) := Pad;
kono
parents:
diff changeset
388 end loop;
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 Target (Tfirst_Fpad .. Tfirst_Fpad + Slength - 1) := Source;
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 for J in Tfirst_Fpad + Slength .. Tlast loop
kono
parents:
diff changeset
393 Target (J) := Pad;
kono
parents:
diff changeset
394 end loop;
kono
parents:
diff changeset
395 end;
kono
parents:
diff changeset
396 end case;
kono
parents:
diff changeset
397 end if;
kono
parents:
diff changeset
398 end Move;
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 ---------------
kono
parents:
diff changeset
401 -- Overwrite --
kono
parents:
diff changeset
402 ---------------
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 function Overwrite
kono
parents:
diff changeset
405 (Source : Wide_Wide_String;
kono
parents:
diff changeset
406 Position : Positive;
kono
parents:
diff changeset
407 New_Item : Wide_Wide_String) return Wide_Wide_String
kono
parents:
diff changeset
408 is
kono
parents:
diff changeset
409 begin
kono
parents:
diff changeset
410 if Position not in Source'First .. Source'Last + 1 then
kono
parents:
diff changeset
411 raise Index_Error;
kono
parents:
diff changeset
412 else
kono
parents:
diff changeset
413 declare
kono
parents:
diff changeset
414 Result_Length : constant Natural :=
kono
parents:
diff changeset
415 Natural'Max
kono
parents:
diff changeset
416 (Source'Length,
kono
parents:
diff changeset
417 Position - Source'First + New_Item'Length);
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 Result : Wide_Wide_String (1 .. Result_Length);
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 begin
kono
parents:
diff changeset
422 Result := Source (Source'First .. Position - 1) & New_Item &
kono
parents:
diff changeset
423 Source (Position + New_Item'Length .. Source'Last);
kono
parents:
diff changeset
424 return Result;
kono
parents:
diff changeset
425 end;
kono
parents:
diff changeset
426 end if;
kono
parents:
diff changeset
427 end Overwrite;
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 procedure Overwrite
kono
parents:
diff changeset
430 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
431 Position : Positive;
kono
parents:
diff changeset
432 New_Item : Wide_Wide_String;
kono
parents:
diff changeset
433 Drop : Truncation := Right)
kono
parents:
diff changeset
434 is
kono
parents:
diff changeset
435 begin
kono
parents:
diff changeset
436 Move (Source => Overwrite (Source, Position, New_Item),
kono
parents:
diff changeset
437 Target => Source,
kono
parents:
diff changeset
438 Drop => Drop);
kono
parents:
diff changeset
439 end Overwrite;
kono
parents:
diff changeset
440
kono
parents:
diff changeset
441 -------------------
kono
parents:
diff changeset
442 -- Replace_Slice --
kono
parents:
diff changeset
443 -------------------
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 function Replace_Slice
kono
parents:
diff changeset
446 (Source : Wide_Wide_String;
kono
parents:
diff changeset
447 Low : Positive;
kono
parents:
diff changeset
448 High : Natural;
kono
parents:
diff changeset
449 By : Wide_Wide_String) return Wide_Wide_String
kono
parents:
diff changeset
450 is
kono
parents:
diff changeset
451 begin
kono
parents:
diff changeset
452 if Low > Source'Last + 1 or else High < Source'First - 1 then
kono
parents:
diff changeset
453 raise Index_Error;
kono
parents:
diff changeset
454 end if;
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 if High >= Low then
kono
parents:
diff changeset
457 declare
kono
parents:
diff changeset
458 Front_Len : constant Integer :=
kono
parents:
diff changeset
459 Integer'Max (0, Low - Source'First);
kono
parents:
diff changeset
460 -- Length of prefix of Source copied to result
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 Back_Len : constant Integer :=
kono
parents:
diff changeset
463 Integer'Max (0, Source'Last - High);
kono
parents:
diff changeset
464 -- Length of suffix of Source copied to result
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 Result_Length : constant Integer :=
kono
parents:
diff changeset
467 Front_Len + By'Length + Back_Len;
kono
parents:
diff changeset
468 -- Length of result
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 Result : Wide_Wide_String (1 .. Result_Length);
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 begin
kono
parents:
diff changeset
473 Result (1 .. Front_Len) := Source (Source'First .. Low - 1);
kono
parents:
diff changeset
474 Result (Front_Len + 1 .. Front_Len + By'Length) := By;
kono
parents:
diff changeset
475 Result (Front_Len + By'Length + 1 .. Result'Length) :=
kono
parents:
diff changeset
476 Source (High + 1 .. Source'Last);
kono
parents:
diff changeset
477 return Result;
kono
parents:
diff changeset
478 end;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 else
kono
parents:
diff changeset
481 return Insert (Source, Before => Low, New_Item => By);
kono
parents:
diff changeset
482 end if;
kono
parents:
diff changeset
483 end Replace_Slice;
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 procedure Replace_Slice
kono
parents:
diff changeset
486 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
487 Low : Positive;
kono
parents:
diff changeset
488 High : Natural;
kono
parents:
diff changeset
489 By : Wide_Wide_String;
kono
parents:
diff changeset
490 Drop : Truncation := Error;
kono
parents:
diff changeset
491 Justify : Alignment := Left;
kono
parents:
diff changeset
492 Pad : Wide_Wide_Character := Wide_Wide_Space)
kono
parents:
diff changeset
493 is
kono
parents:
diff changeset
494 begin
kono
parents:
diff changeset
495 Move (Replace_Slice (Source, Low, High, By), Source, Drop, Justify, Pad);
kono
parents:
diff changeset
496 end Replace_Slice;
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 ----------
kono
parents:
diff changeset
499 -- Tail --
kono
parents:
diff changeset
500 ----------
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 function Tail
kono
parents:
diff changeset
503 (Source : Wide_Wide_String;
kono
parents:
diff changeset
504 Count : Natural;
kono
parents:
diff changeset
505 Pad : Wide_Wide_Character := Wide_Wide_Space) return Wide_Wide_String
kono
parents:
diff changeset
506 is
kono
parents:
diff changeset
507 Result : Wide_Wide_String (1 .. Count);
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 begin
kono
parents:
diff changeset
510 if Count < Source'Length then
kono
parents:
diff changeset
511 Result := Source (Source'Last - Count + 1 .. Source'Last);
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 -- Pad on left
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 else
kono
parents:
diff changeset
516 for J in 1 .. Count - Source'Length loop
kono
parents:
diff changeset
517 Result (J) := Pad;
kono
parents:
diff changeset
518 end loop;
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 Result (Count - Source'Length + 1 .. Count) := Source;
kono
parents:
diff changeset
521 end if;
kono
parents:
diff changeset
522
kono
parents:
diff changeset
523 return Result;
kono
parents:
diff changeset
524 end Tail;
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 procedure Tail
kono
parents:
diff changeset
527 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
528 Count : Natural;
kono
parents:
diff changeset
529 Justify : Alignment := Left;
kono
parents:
diff changeset
530 Pad : Wide_Wide_Character := Ada.Strings.Wide_Wide_Space)
kono
parents:
diff changeset
531 is
kono
parents:
diff changeset
532 begin
kono
parents:
diff changeset
533 Move (Source => Tail (Source, Count, Pad),
kono
parents:
diff changeset
534 Target => Source,
kono
parents:
diff changeset
535 Drop => Error,
kono
parents:
diff changeset
536 Justify => Justify,
kono
parents:
diff changeset
537 Pad => Pad);
kono
parents:
diff changeset
538 end Tail;
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 ---------------
kono
parents:
diff changeset
541 -- Translate --
kono
parents:
diff changeset
542 ---------------
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 function Translate
kono
parents:
diff changeset
545 (Source : Wide_Wide_String;
kono
parents:
diff changeset
546 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
kono
parents:
diff changeset
547 return Wide_Wide_String
kono
parents:
diff changeset
548 is
kono
parents:
diff changeset
549 Result : Wide_Wide_String (1 .. Source'Length);
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 begin
kono
parents:
diff changeset
552 for J in Source'Range loop
kono
parents:
diff changeset
553 Result (J - (Source'First - 1)) := Value (Mapping, Source (J));
kono
parents:
diff changeset
554 end loop;
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 return Result;
kono
parents:
diff changeset
557 end Translate;
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 procedure Translate
kono
parents:
diff changeset
560 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
561 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping)
kono
parents:
diff changeset
562 is
kono
parents:
diff changeset
563 begin
kono
parents:
diff changeset
564 for J in Source'Range loop
kono
parents:
diff changeset
565 Source (J) := Value (Mapping, Source (J));
kono
parents:
diff changeset
566 end loop;
kono
parents:
diff changeset
567 end Translate;
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 function Translate
kono
parents:
diff changeset
570 (Source : Wide_Wide_String;
kono
parents:
diff changeset
571 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
kono
parents:
diff changeset
572 return Wide_Wide_String
kono
parents:
diff changeset
573 is
kono
parents:
diff changeset
574 Result : Wide_Wide_String (1 .. Source'Length);
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 begin
kono
parents:
diff changeset
577 for J in Source'Range loop
kono
parents:
diff changeset
578 Result (J - (Source'First - 1)) := Mapping (Source (J));
kono
parents:
diff changeset
579 end loop;
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 return Result;
kono
parents:
diff changeset
582 end Translate;
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 procedure Translate
kono
parents:
diff changeset
585 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
586 Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function)
kono
parents:
diff changeset
587 is
kono
parents:
diff changeset
588 begin
kono
parents:
diff changeset
589 for J in Source'Range loop
kono
parents:
diff changeset
590 Source (J) := Mapping (Source (J));
kono
parents:
diff changeset
591 end loop;
kono
parents:
diff changeset
592 end Translate;
kono
parents:
diff changeset
593
kono
parents:
diff changeset
594 ----------
kono
parents:
diff changeset
595 -- Trim --
kono
parents:
diff changeset
596 ----------
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 function Trim
kono
parents:
diff changeset
599 (Source : Wide_Wide_String;
kono
parents:
diff changeset
600 Side : Trim_End) return Wide_Wide_String
kono
parents:
diff changeset
601 is
kono
parents:
diff changeset
602 Low : Natural := Source'First;
kono
parents:
diff changeset
603 High : Natural := Source'Last;
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 begin
kono
parents:
diff changeset
606 if Side = Left or else Side = Both then
kono
parents:
diff changeset
607 while Low <= High and then Source (Low) = Wide_Wide_Space loop
kono
parents:
diff changeset
608 Low := Low + 1;
kono
parents:
diff changeset
609 end loop;
kono
parents:
diff changeset
610 end if;
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 if Side = Right or else Side = Both then
kono
parents:
diff changeset
613 while High >= Low and then Source (High) = Wide_Wide_Space loop
kono
parents:
diff changeset
614 High := High - 1;
kono
parents:
diff changeset
615 end loop;
kono
parents:
diff changeset
616 end if;
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 -- All blanks case
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 if Low > High then
kono
parents:
diff changeset
621 return "";
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 -- At least one non-blank
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 else
kono
parents:
diff changeset
626 declare
kono
parents:
diff changeset
627 Result : constant Wide_Wide_String (1 .. High - Low + 1) :=
kono
parents:
diff changeset
628 Source (Low .. High);
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 begin
kono
parents:
diff changeset
631 return Result;
kono
parents:
diff changeset
632 end;
kono
parents:
diff changeset
633 end if;
kono
parents:
diff changeset
634 end Trim;
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 procedure Trim
kono
parents:
diff changeset
637 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
638 Side : Trim_End;
kono
parents:
diff changeset
639 Justify : Alignment := Left;
kono
parents:
diff changeset
640 Pad : Wide_Wide_Character := Wide_Wide_Space)
kono
parents:
diff changeset
641 is
kono
parents:
diff changeset
642 begin
kono
parents:
diff changeset
643 Move (Source => Trim (Source, Side),
kono
parents:
diff changeset
644 Target => Source,
kono
parents:
diff changeset
645 Justify => Justify,
kono
parents:
diff changeset
646 Pad => Pad);
kono
parents:
diff changeset
647 end Trim;
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 function Trim
kono
parents:
diff changeset
650 (Source : Wide_Wide_String;
kono
parents:
diff changeset
651 Left : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
652 Right : Wide_Wide_Maps.Wide_Wide_Character_Set) return Wide_Wide_String
kono
parents:
diff changeset
653 is
kono
parents:
diff changeset
654 Low : Natural := Source'First;
kono
parents:
diff changeset
655 High : Natural := Source'Last;
kono
parents:
diff changeset
656
kono
parents:
diff changeset
657 begin
kono
parents:
diff changeset
658 while Low <= High and then Is_In (Source (Low), Left) loop
kono
parents:
diff changeset
659 Low := Low + 1;
kono
parents:
diff changeset
660 end loop;
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 while High >= Low and then Is_In (Source (High), Right) loop
kono
parents:
diff changeset
663 High := High - 1;
kono
parents:
diff changeset
664 end loop;
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 -- Case where source comprises only characters in the sets
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 if Low > High then
kono
parents:
diff changeset
669 return "";
kono
parents:
diff changeset
670 else
kono
parents:
diff changeset
671 declare
kono
parents:
diff changeset
672 subtype WS is Wide_Wide_String (1 .. High - Low + 1);
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 begin
kono
parents:
diff changeset
675 return WS (Source (Low .. High));
kono
parents:
diff changeset
676 end;
kono
parents:
diff changeset
677 end if;
kono
parents:
diff changeset
678 end Trim;
kono
parents:
diff changeset
679
kono
parents:
diff changeset
680 procedure Trim
kono
parents:
diff changeset
681 (Source : in out Wide_Wide_String;
kono
parents:
diff changeset
682 Left : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
683 Right : Wide_Wide_Maps.Wide_Wide_Character_Set;
kono
parents:
diff changeset
684 Justify : Alignment := Strings.Left;
kono
parents:
diff changeset
685 Pad : Wide_Wide_Character := Wide_Wide_Space)
kono
parents:
diff changeset
686 is
kono
parents:
diff changeset
687 begin
kono
parents:
diff changeset
688 Move (Source => Trim (Source, Left, Right),
kono
parents:
diff changeset
689 Target => Source,
kono
parents:
diff changeset
690 Justify => Justify,
kono
parents:
diff changeset
691 Pad => Pad);
kono
parents:
diff changeset
692 end Trim;
kono
parents:
diff changeset
693
kono
parents:
diff changeset
694 end Ada.Strings.Wide_Wide_Fixed;