adacl-wide_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_Wide_Unbounded;
23with Ada.Strings.Wide_Wide_Maps;
24with Ada.Containers;
25
26---
27-- @summary
28--
29-- @description
30-- No, I have not created some new Wide_Wide_String class - yet. Just a few string tools.
31--
32package AdaCL.Wide_Wide_Strings is
33
34 ---
35 -- Replace all Search with Replace
36 --
37 --: @param Source String to be changed
38 --: @param Search String we look for
39 --: @param Replace String we want to have
40 --: @param Mapping Search mapping
41 procedure Change_All
42 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
43 Search : in Wide_Wide_String;
44 Replace : in Wide_Wide_String;
45 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
46
47 ---
48 -- Replace all Search with Replace and Count how often it was done.
49 --
50 --: @param Source String to be changed
51 --: @param Search String we look for
52 --: @param Replace String we want to have
53 --: @param Mapping Search mapping
54 --: @param Count Count of replaces done
55 procedure Change_All
56 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
57 Search : in Wide_Wide_String;
58 Replace : in Wide_Wide_String;
59 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
60 Count : out Natural);
61
62 ---
63 -- Replace all Search with Replace
64 --
65 --: @param Source String to be changed
66 --: @param Search String we look for
67 --: @param Replace String we want to have
68 --: @param Mapping Search mapping
69 procedure Change_First
70 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
71 Search : in Wide_Wide_String;
72 Replace : in Wide_Wide_String;
73 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
74
75 ---
76 -- Replace First Search with Replace and return success flag.
77 --
78 --: @param Source String to be changed
79 --: @param Search String we look for
80 --: @param Replace String we want to have
81 --: @param Mapping Search mapping
82 --: @param Found Count of replaces done
83 procedure Change_First
84 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
85 Search : in Wide_Wide_String;
86 Replace : in Wide_Wide_String;
87 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
88 Found : out Boolean);
89
90 ---
91 -- Replace Last Search with Replace
92 --
93 --: @param Source : String we look for
94 --: @param Search : String to be changed
95 --: @param Replace : String we want to have
96 --: @param Mapping : Search mapping
97 procedure Change_Last
98 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
99 Search : in Wide_Wide_String;
100 Replace : in Wide_Wide_String;
101 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
102
103 ---
104 -- Replace Last Search with Replace and return success flag.
105 --
106 --: @param Source String to be changed
107 --: @param Search String we look for
108 --: @param Replace String we want to have
109 --: @param Mapping Search mapping
110 --: @param Found Count of replaces done
111 procedure Change_Last
112 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
113 Search : in Wide_Wide_String;
114 Replace : in Wide_Wide_String;
115 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
116 Found : out Boolean);
117
118 ---
119 -- Searches for all occurences of text "Search" and Inserts text "Insert" after the found text but only when
120 -- "Insert" is not allready there.
121 --
122 --: @param Source String to be changed
123 --: @param Search String we look for
124 --: @param New_Item String we want to insert
125 --: @param Mapping Search mapping
126 procedure Append_All
127 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
128 Search : in Wide_Wide_String;
129 New_Item : in Wide_Wide_String;
130 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
131
132 ---
133 -- Searches for all occurences of text "Search" and Inserts text "Insert" after the found text but only when
134 -- "Insert" is not allready there.
135 --
136 --: @param Source String to be changed
137 --: @param Search String we look for
138 --: @param New_Item String we want to insert
139 --: @param Mapping Search mapping
140 --: @param Count Count of replaces done
141 procedure Append_All
142 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
143 Search : in Wide_Wide_String;
144 New_Item : in Wide_Wide_String;
145 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
146 Count : out Natural);
147
148 ---
149 -- Searches for first occurence of text "Search" and Inserts text "Insert" after the found text but only when
150 -- "Insert" is not allready there.
151 --
152 --: @param Source String to be changed
153 --: @param Search String we look for
154 --: @param New_Item String we want to insert
155 --: @param Mapping Search mapping
156 procedure Append_First
157 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
158 Search : in Wide_Wide_String;
159 New_Item : in Wide_Wide_String;
160 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
161
162 ---
163 -- Searches for first occurence of text "Search" and Inserts text "Insert" after the found text but only when
164 -- "Insert" is not allready there.
165 --
166 --: @param Source String to be changed
167 --: @param Search String we look for
168 --: @param New_Item String we want to insert
169 --: @param Mapping Search mapping
170 --: @param Found Count of replaces done
171 procedure Append_First
172 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
173 Search : in Wide_Wide_String;
174 New_Item : in Wide_Wide_String;
175 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
176 Found : out Boolean);
177
178 ---
179 -- Searches for last occurence of text "Search" and Inserts text "Insert" after the found text but only when
180 -- "Insert" is not allready there.
181 --
182 --: @param Source String to be changed
183 --: @param Search String we look for
184 --: @param New_Item String we want to insert
185 --: @param Mapping Search mapping
186 procedure Append_Last
187 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
188 Search : in Wide_Wide_String;
189 New_Item : in Wide_Wide_String;
190 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
191
192 ---
193 -- Searches for last occurence of text "Search" and Inserts text "Insert" after the found text but only when
194 -- "Insert" is not allready there.
195 --
196 --: @param Source String to be changed
197 --: @param Search String we look for
198 --: @param New_Item String we want to insert
199 --: @param Mapping Search mapping
200 --: @param Found Count of replaces done
201 procedure Append_Last
202 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
203 Search : in Wide_Wide_String;
204 New_Item : in Wide_Wide_String;
205 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
206 Found : out Boolean);
207
208 ---
209 -- Return the end-of-field position in Data after "Starting_Index", assuming that fields are separated by the
210 -- Field_Separator. If there's no Field_Separator, return the end of the Data.
211 --: @param Source String to search in
212 --: @param Field_Separator Field seperator.
213 --: @param Starting_At Start search at.
214 function Field_End
215 (Source : in Wide_Wide_String;
216 Field_Separator : in Wide_Wide_Character;
217 Starting_At : Positive)
218 return Natural with
219 Pure_Function;
220
221 ---
222 -- Searches for first occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
223 --
224 --: @param Source String to be changed
225 --: @param Search String we look for
226 --: @param New_Item String we want to insert
227 --: @param Mapping Search mapping
228 procedure Insert_First
229 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
230 Search : in Wide_Wide_String;
231 New_Item : in Wide_Wide_String;
232 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
233
234 ---
235 -- Searches for first occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
236 --
237 --: @param Source String to be changed
238 --: @param Search String we look for
239 --: @param New_Item String we want to insert
240 --: @param Mapping Search mapping
241 --: @param Found Count of replaces done
242 procedure Insert_First
243 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
244 Search : in Wide_Wide_String;
245 New_Item : in Wide_Wide_String;
246 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
247 Found : out Boolean);
248
249 ---
250 -- Searches for all occurences of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
251 --
252 --: @param Source Search mapping
253 --: @param Search String we want to insert
254 --: @param New_Item String we look for
255 --: @param Mapping String to be changed
256 procedure Insert_All
257 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
258 Search : in Wide_Wide_String;
259 New_Item : in Wide_Wide_String;
260 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
261
262 ---
263 -- Searches for all occurences of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
264 --
265 --: @param Source String to be changed
266 --: @param Search String we look for
267 --: @param New_Item String we want to insert
268 --: @param Mapping Search mapping
269 --: @param Count Count of replaces done
270 procedure Insert_All
271 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
272 Search : in Wide_Wide_String;
273 New_Item : in Wide_Wide_String;
274 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
275 Count : out Natural);
276
277 ---
278 -- Searches for last occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
279 --
280 --: @param Source String to be changed
281 --: @param Search String we look for
282 --: @param New_Item String we want to insert
283 --: @param Mapping Search mapping
284 procedure Insert_Last
285 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
286 Search : in Wide_Wide_String;
287 New_Item : in Wide_Wide_String;
288 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity);
289
290 ---
291 -- Searches for last occurence of text "Search" and Inserts text "Insert" bevore when "Insert" is there.
292 --
293 --: @param Source String to be changed
294 --: @param Search String we look for
295 --: @param New_Item String we want to insert
296 --: @param Mapping Search mapping
297 --: @param Found Count of replaces done
298 procedure Insert_Last
299 (Source : in out Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
300 Search : in Wide_Wide_String;
301 New_Item : in Wide_Wide_String;
302 Mapping : in Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Mapping := Ada.Strings.Wide_Wide_Maps.Identity;
303 Found : out Boolean);
304
305 ---
306 -- Hash function for booch components.
307 --
308 --: @param Key String to calculate a hash value form
309 --: @return hash value
310 function Hash (Key : Wide_Wide_String) return Natural with
311 Pure_Function;
312
313 ---
314 -- Hash function for booch components.
315 --
316 --: @param Key String to calculate a hash value form
317 --: @return hash value
318 function Hash (Key : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String) return Natural with
319 Pure_Function;
320
321 ---
322 -- Hash function for Ada components.
323 --
324 --: @param Key String to calculate a hash value form
325 --: @return hash value
326 function Hash
327 (Key : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String) return Ada.Containers.Hash_Type with
328 Pure_Function;
329
330 ---
331 -- Hash function for Ada components.
332 --
333 --: @param Key String to calculate a hash value form
334 --: @return hash value
335 function Hash (Key : Wide_Wide_String) return Ada.Containers.Hash_Type with
336 Pure_Function;
337
338 ---
339 -- convert Wide_Wide_String into Integer
340 --
341 --: @param Image String to to be shown as Integer
342 --: @return passed integer value
343 function Value (Image : Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String) return Integer with
344 Pure_Function;
345 ------------------------------------------------------------------------------
346
347 ---
348 -- Extract the first word.
349 --
350 --: @param Source String to search
351 --: @param Delimiter word delimiter. Default is space.
352 function First_Word
353 (Source : in Wide_Wide_String;
354 Delimiter : in Wide_Wide_Character := ' ')
355 return Wide_Wide_String with
356 Pure_Function;
357
358 ---
359 -- Extract the last word.
360 --
361 --: @param Source String to search
362 --: @param Delimiter word delimiter. Default is space.
363 function Last_Word
364 (Source : in Wide_Wide_String;
365 Delimiter : in Wide_Wide_Character := ' ')
366 return Wide_Wide_String with
367 Pure_Function;
368
369end AdaCL.Wide_Wide_Strings;
370
371---------------------------------------------------------------- {{{ ----------
372--: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
373--: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr :
374--: vim: set spell spelllang=en_gb