adacl-wide_strings.ads

1--------------------------------------------------------------- {{{1 ----------
2--: Copyright © 2003 … 2023 Martin Krischik «krischik@users.sourceforge.net»
3------------------------------------------------------------------------------
4--: This library is free software; you can redistribute it and/or modify it
5--: under the terms of the GNU Library General Public License as published by
6--: the Free Software Foundation; either version 2 of the License, or (at your
7--: option) any later version.
8--:
9--: This library is distributed in the hope that it will be useful, but
10--: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11--: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12--: License for more details.
13--:
14--: You should have received a copy of the GNU Library General Public License
15--: along with this library; if not, write to the Free Software Foundation,
16--: Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17--------------------------------------------------------------- }}}1 ----------
18
19pragma License (Modified_Gpl);
20pragma Ada_2022;
21
22with Ada.Strings.Wide_Unbounded;
23with Ada.Strings.Wide_Maps;
24with Ada.Containers;
25
26---
27-- @summary
28--
29-- @description
30-- No, I have not created some new Wide_String class - yet. Just a few string tools.
31--
32package AdaCL.Wide_Strings is
33
34 subtype Hex_Digit is Natural range 0 .. 16#F#;
35
36 ---
37 -- Replace all Search with Replace
38 --
39 --: @param Source String to be changed
40 --: @param Search String we look for
41 --: @param Replace String we want to have
42 --: @param Mapping Search mapping
43 procedure Change_All
44 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
45 Search : in Wide_String;
46 Replace : in Wide_String;
47 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
48
49 ---
50 -- Replace all Search with Replace and Count how often it was done.
51 --
52 --: @param Source String to be changed
53 --: @param Search String we look for
54 --: @param Replace String we want to have
55 --: @param Mapping Search mapping
56 --: @param Count Count of replaces done
57 procedure Change_All
58 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
59 Search : in Wide_String;
60 Replace : in Wide_String;
61 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
62 Count : out Natural);
63
64 ---
65 -- Replace all Search with Replace
66 --
67 --: @param Source String to be changed
68 --: @param Search String we look for
69 --: @param Replace String we want to have
70 --: @param Mapping Search mapping
71 procedure Change_First
72 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
73 Search : in Wide_String;
74 Replace : in Wide_String;
75 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
76
77 ---
78 -- Replace First Search with Replace and return success flag.
79 --
80 --: @param Source String to be changed
81 --: @param Search String we look for
82 --: @param Replace String we want to have
83 --: @param Mapping Search mapping
84 --: @param Found Count of replaces done
85 procedure Change_First
86 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
87 Search : in Wide_String;
88 Replace : in Wide_String;
89 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
90 Found : out Boolean);
91
92 ---
93 -- Replace Last Search with Replace
94 --
95 --: @param Source : String we look for
96 --: @param Search : String to be changed
97 --: @param Replace : String we want to have
98 --: @param Mapping : Search mapping
99 procedure Change_Last
100 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
101 Search : in Wide_String;
102 Replace : in Wide_String;
103 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
104
105 ---
106 -- Replace Last Search with Replace and return success flag.
107 --
108 --: @param Source String to be changed
109 --: @param Search String we look for
110 --: @param Replace String we want to have
111 --: @param Mapping Search mapping
112 --: @param Found Count of replaces done
113 procedure Change_Last
114 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
115 Search : in Wide_String;
116 Replace : in Wide_String;
117 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
118 Found : out Boolean);
119
120 ---
121 -- Searches for all occurences of text "Search" and Inserts text "Insert" after the found text but only when
122 -- "Insert" is not allready there.
123 --
124 --: @param Source String to be changed
125 --: @param Search String we look for
126 --: @param New_Item String we want to insert
127 --: @param Mapping Search mapping
128 procedure Append_All
129 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
130 Search : in Wide_String;
131 New_Item : in Wide_String;
132 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
133
134 ---
135 -- Searches for all occurences of text "Search" and Inserts text "Insert" after the found text but only when
136 -- "Insert" is not allready there.
137 --
138 --: @param Source String to be changed
139 --: @param Search String we look for
140 --: @param New_Item String we want to insert
141 --: @param Mapping Search mapping
142 --: @param Count Count of replaces done
143 procedure Append_All
144 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
145 Search : in Wide_String;
146 New_Item : in Wide_String;
147 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
148 Count : out Natural);
149
150 ---
151 -- Searches for first occurence of text "Search" and Inserts text "Insert" after the found text but only when
152 -- "Insert" is not allready there.
153 --
154 --: @param Source String to be changed
155 --: @param Search String we look for
156 --: @param New_Item String we want to insert
157 --: @param Mapping Search mapping
158 procedure Append_First
159 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
160 Search : in Wide_String;
161 New_Item : in Wide_String;
162 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
163
164 ---
165 -- Searches for first occurence of text "Search" and Inserts text "Insert" after the found text but only when
166 -- "Insert" is not allready there.
167 --
168 --: @param Source String to be changed
169 --: @param Search String we look for
170 --: @param New_Item String we want to insert
171 --: @param Mapping Search mapping
172 --: @param Found Count of replaces done
173 procedure Append_First
174 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
175 Search : in Wide_String;
176 New_Item : in Wide_String;
177 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
178 Found : out Boolean);
179
180 ---
181 -- Searches for last occurence of text "Search" and Inserts text "Insert" after the found text but only when
182 -- "Insert" is not allready there.
183 --
184 --: @param Source String to be changed
185 --: @param Search String we look for
186 --: @param New_Item String we want to insert
187 --: @param Mapping Search mapping
188 procedure Append_Last
189 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
190 Search : in Wide_String;
191 New_Item : in Wide_String;
192 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
193
194 ---
195 -- Searches for last occurence of text "Search" and Inserts text "Insert" after the found text but only when
196 -- "Insert" is not allready there.
197 --
198 --: @param Source String to be changed
199 --: @param Search String we look for
200 --: @param New_Item String we want to insert
201 --: @param Mapping Search mapping
202 --: @param Found Count of replaces done
203 procedure Append_Last
204 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
205 Search : in Wide_String;
206 New_Item : in Wide_String;
207 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
208 Found : out Boolean);
209
210 ---
211 -- Return the end-of-field position in Data after "Starting_Index", assuming that fields are separated by the
212 -- Field_Separator. If there's no Field_Separator, return the end of the Data.
213 --: @param Source String to search in
214 --: @param Field_Separator Field seperator.
215 --: @param Starting_At Start search at.
216 function Field_End
217 (Source : in Wide_String;
218 Field_Separator : in Wide_Character;
219 Starting_At : Positive)
220 return Natural with
221 Pure_Function;
222
223 ---
224 -- Searches for first occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
225 --
226 --: @param Source String to be changed
227 --: @param Search String we look for
228 --: @param New_Item String we want to insert
229 --: @param Mapping Search mapping
230 procedure Insert_First
231 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
232 Search : in Wide_String;
233 New_Item : in Wide_String;
234 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
235
236 ---
237 -- Searches for first occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
238 --
239 --: @param Source String to be changed
240 --: @param Search String we look for
241 --: @param New_Item String we want to insert
242 --: @param Mapping Search mapping
243 --: @param Found Count of replaces done
244 procedure Insert_First
245 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
246 Search : in Wide_String;
247 New_Item : in Wide_String;
248 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
249 Found : out Boolean);
250
251 ---
252 -- Searches for all occurences of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
253 --
254 --: @param Source Search mapping
255 --: @param Search String we want to insert
256 --: @param New_Item String we look for
257 --: @param Mapping String to be changed
258 procedure Insert_All
259 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
260 Search : in Wide_String;
261 New_Item : in Wide_String;
262 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
263
264 ---
265 -- Searches for all occurences of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
266 --
267 --: @param Source String to be changed
268 --: @param Search String we look for
269 --: @param New_Item String we want to insert
270 --: @param Mapping Search mapping
271 --: @param Count Count of replaces done
272 procedure Insert_All
273 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
274 Search : in Wide_String;
275 New_Item : in Wide_String;
276 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
277 Count : out Natural);
278
279 ---
280 -- Searches for last occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
281 --
282 --: @param Source String to be changed
283 --: @param Search String we look for
284 --: @param New_Item String we want to insert
285 --: @param Mapping Search mapping
286 procedure Insert_Last
287 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
288 Search : in Wide_String;
289 New_Item : in Wide_String;
290 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity);
291
292 ---
293 -- Searches for last occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
294 --
295 --: @param Source String to be changed
296 --: @param Search String we look for
297 --: @param New_Item String we want to insert
298 --: @param Mapping Search mapping
299 --: @param Found Count of replaces done
300 procedure Insert_Last
301 (Source : in out Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
302 Search : in Wide_String;
303 New_Item : in Wide_String;
304 Mapping : in Ada.Strings.Wide_Maps.Wide_Character_Mapping := Ada.Strings.Wide_Maps.Identity;
305 Found : out Boolean);
306
307 ------------------------------------------------------------------------------
308
309 ---
310 -- Hash function for booch components.
311 --
312 --: @param Key String to calculate a hash value form
313 --: @return hash value
314 function Hash (Key : Wide_String) return Natural with
315 Pure_Function;
316
317 ---
318 -- Hash function for booch components.
319 --
320 --: @param Key String to calculate a hash value form
321 --: @return hash value
322 function Hash (Key : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String) return Natural with
323 Pure_Function;
324
325 ---
326 -- Hash function for Ada components.
327 --
328 --: @param Key String to calculate a hash value form
329 --: @return hash value
330 function Hash (Key : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String) return Ada.Containers.Hash_Type with
331 Pure_Function;
332
333 ---
334 -- Hash function for Ada components.
335 --
336 --: @param Key String to calculate a hash value form
337 --: @return hash value
338 function Hash (Key : Wide_String) return Ada.Containers.Hash_Type with
339 Pure_Function;
340
341 ---
342 -- convert Wide_String into Integer
343 --
344 --: @param Image String to to be shown as Integer
345 --: @return pased integer value
346 function Value (Image : Ada.Strings.Wide_Unbounded.Unbounded_Wide_String) return Integer with
347 Pure_Function;
348
349 ------------------------------------------------------------------------------
350
351 ---
352 -- Extract the first word.
353 --
354 --: @param Source String to search
355 --: @param Delimiter word delimiter. Default is space.
356 function First_Word
357 (Source : in Wide_String;
358 Delimiter : in Wide_Character := ' ')
359 return Wide_String with
360 Pure_Function;
361
362 ---
363 -- Extract the last word.
364 --
365 --: @param Source String to search
366 --: @param Delimiter word delimiter. Default is space.
367 function Last_Word
368 (Source : in Wide_String;
369 Delimiter : in Wide_Character := ' ')
370 return Wide_String with
371 Pure_Function;
372
373end AdaCL.Wide_Strings;
374
375---------------------------------------------------------------- {{{ ----------
376--: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
377--: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr :
378--: vim: set spell spelllang=en_gb