| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- A D A . S T R I N G S . W I D E _ W I D E _ S U P E R B O U N D E D -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2003-2025, Free Software Foundation, Inc. -- |
| 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 |
-- This non generic package contains most of the implementation of the |
| 33 |
-- generic package Ada.Strings.Wide_Wide_Bounded.Generic_Bounded_Length. |
| 34 |
|
| 35 |
-- It defines type Super_String as a discriminated record with the maximum |
| 36 |
-- length as the discriminant. Individual instantiations of the package |
| 37 |
-- Strings.Wide_Wide_Bounded.Generic_Bounded_Length use this type with |
| 38 |
-- an appropriate discriminant value set. |
| 39 |
|
| 40 |
with Ada.Strings.Text_Buffers; |
| 41 |
with Ada.Strings.Wide_Wide_Maps; |
| 42 |
|
| 43 |
package Ada.Strings.Wide_Wide_Superbounded is |
| 44 |
pragma Preelaborate; |
| 45 |
|
| 46 |
Wide_Wide_NUL : constant Wide_Wide_Character := |
| 47 |
Wide_Wide_Character'Val (0); |
| 48 |
|
| 49 |
-- Wide_Wide_Bounded.Generic_Bounded_Length.Wide_Wide_Bounded_String is |
| 50 |
-- derived from Super_String, with the constraint of the maximum length. |
| 51 |
|
| 52 |
type Super_String (Max_Length : Positive) is record |
| 53 |
Current_Length : Natural := 0; |
| 54 |
Data : Wide_Wide_String (1 .. Max_Length); |
| 55 |
-- A previous version had a default initial value for Data, which is |
| 56 |
-- no longer necessary, because we now special-case this type in the |
| 57 |
-- compiler, so "=" composes properly for descendants of this type. |
| 58 |
-- Leaving it out is more efficient. |
| 59 |
end record |
| 60 |
with Put_Image => Put_Image; |
| 61 |
|
| 62 |
-- The subprograms defined for Super_String are similar to those defined |
| 63 |
-- for Bounded_Wide_Wide_String, except that they have different names, so |
| 64 |
-- that they can be renamed in Wide_Wide_Bounded.Generic_Bounded_Length. |
| 65 |
|
| 66 |
function Super_Length (Source : Super_String) return Natural; |
| 67 |
|
| 68 |
-------------------------------------------------------- |
| 69 |
-- Conversion, Concatenation, and Selection Functions -- |
| 70 |
-------------------------------------------------------- |
| 71 |
|
| 72 |
function To_Super_String |
| 73 |
(Source : Wide_Wide_String; |
| 74 |
Max_Length : Natural; |
| 75 |
Drop : Truncation := Error) return Super_String; |
| 76 |
-- Note the additional parameter Max_Length, which specifies the maximum |
| 77 |
-- length setting of the resulting Super_String value. |
| 78 |
|
| 79 |
-- The following procedures have declarations (and semantics) that are |
| 80 |
-- exactly analogous to those declared in Ada.Strings.Wide_Wide_Bounded. |
| 81 |
|
| 82 |
function Super_To_String (Source : Super_String) return Wide_Wide_String; |
| 83 |
|
| 84 |
procedure Set_Super_String |
| 85 |
(Target : out Super_String; |
| 86 |
Source : Wide_Wide_String; |
| 87 |
Drop : Truncation := Error); |
| 88 |
|
| 89 |
function Super_Append |
| 90 |
(Left : Super_String; |
| 91 |
Right : Super_String; |
| 92 |
Drop : Truncation := Error) return Super_String; |
| 93 |
|
| 94 |
function Super_Append |
| 95 |
(Left : Super_String; |
| 96 |
Right : Wide_Wide_String; |
| 97 |
Drop : Truncation := Error) return Super_String; |
| 98 |
|
| 99 |
function Super_Append |
| 100 |
(Left : Wide_Wide_String; |
| 101 |
Right : Super_String; |
| 102 |
Drop : Truncation := Error) return Super_String; |
| 103 |
|
| 104 |
function Super_Append |
| 105 |
(Left : Super_String; |
| 106 |
Right : Wide_Wide_Character; |
| 107 |
Drop : Truncation := Error) return Super_String; |
| 108 |
|
| 109 |
function Super_Append |
| 110 |
(Left : Wide_Wide_Character; |
| 111 |
Right : Super_String; |
| 112 |
Drop : Truncation := Error) return Super_String; |
| 113 |
|
| 114 |
procedure Super_Append |
| 115 |
(Source : in out Super_String; |
| 116 |
New_Item : Super_String; |
| 117 |
Drop : Truncation := Error); |
| 118 |
|
| 119 |
procedure Super_Append |
| 120 |
(Source : in out Super_String; |
| 121 |
New_Item : Wide_Wide_String; |
| 122 |
Drop : Truncation := Error); |
| 123 |
|
| 124 |
procedure Super_Append |
| 125 |
(Source : in out Super_String; |
| 126 |
New_Item : Wide_Wide_Character; |
| 127 |
Drop : Truncation := Error); |
| 128 |
|
| 129 |
function Concat |
| 130 |
(Left : Super_String; |
| 131 |
Right : Super_String) return Super_String; |
| 132 |
|
| 133 |
function Concat |
| 134 |
(Left : Super_String; |
| 135 |
Right : Wide_Wide_String) return Super_String; |
| 136 |
|
| 137 |
function Concat |
| 138 |
(Left : Wide_Wide_String; |
| 139 |
Right : Super_String) return Super_String; |
| 140 |
|
| 141 |
function Concat |
| 142 |
(Left : Super_String; |
| 143 |
Right : Wide_Wide_Character) return Super_String; |
| 144 |
|
| 145 |
function Concat |
| 146 |
(Left : Wide_Wide_Character; |
| 147 |
Right : Super_String) return Super_String; |
| 148 |
|
| 149 |
function Super_Element |
| 150 |
(Source : Super_String; |
| 151 |
Index : Positive) return Wide_Wide_Character; |
| 152 |
|
| 153 |
procedure Super_Replace_Element |
| 154 |
(Source : in out Super_String; |
| 155 |
Index : Positive; |
| 156 |
By : Wide_Wide_Character); |
| 157 |
|
| 158 |
function Super_Slice |
| 159 |
(Source : Super_String; |
| 160 |
Low : Positive; |
| 161 |
High : Natural) return Wide_Wide_String; |
| 162 |
|
| 163 |
function Super_Slice |
| 164 |
(Source : Super_String; |
| 165 |
Low : Positive; |
| 166 |
High : Natural) return Super_String; |
| 167 |
|
| 168 |
procedure Super_Slice |
| 169 |
(Source : Super_String; |
| 170 |
Target : out Super_String; |
| 171 |
Low : Positive; |
| 172 |
High : Natural); |
| 173 |
|
| 174 |
function "=" |
| 175 |
(Left : Super_String; |
| 176 |
Right : Super_String) return Boolean; |
| 177 |
|
| 178 |
function Equal |
| 179 |
(Left : Super_String; |
| 180 |
Right : Super_String) return Boolean renames "="; |
| 181 |
|
| 182 |
function Equal |
| 183 |
(Left : Super_String; |
| 184 |
Right : Wide_Wide_String) return Boolean; |
| 185 |
|
| 186 |
function Equal |
| 187 |
(Left : Wide_Wide_String; |
| 188 |
Right : Super_String) return Boolean; |
| 189 |
|
| 190 |
function Less |
| 191 |
(Left : Super_String; |
| 192 |
Right : Super_String) return Boolean; |
| 193 |
|
| 194 |
function Less |
| 195 |
(Left : Super_String; |
| 196 |
Right : Wide_Wide_String) return Boolean; |
| 197 |
|
| 198 |
function Less |
| 199 |
(Left : Wide_Wide_String; |
| 200 |
Right : Super_String) return Boolean; |
| 201 |
|
| 202 |
function Less_Or_Equal |
| 203 |
(Left : Super_String; |
| 204 |
Right : Super_String) return Boolean; |
| 205 |
|
| 206 |
function Less_Or_Equal |
| 207 |
(Left : Super_String; |
| 208 |
Right : Wide_Wide_String) return Boolean; |
| 209 |
|
| 210 |
function Less_Or_Equal |
| 211 |
(Left : Wide_Wide_String; |
| 212 |
Right : Super_String) return Boolean; |
| 213 |
|
| 214 |
function Greater |
| 215 |
(Left : Super_String; |
| 216 |
Right : Super_String) return Boolean; |
| 217 |
|
| 218 |
function Greater |
| 219 |
(Left : Super_String; |
| 220 |
Right : Wide_Wide_String) return Boolean; |
| 221 |
|
| 222 |
function Greater |
| 223 |
(Left : Wide_Wide_String; |
| 224 |
Right : Super_String) return Boolean; |
| 225 |
|
| 226 |
function Greater_Or_Equal |
| 227 |
(Left : Super_String; |
| 228 |
Right : Super_String) return Boolean; |
| 229 |
|
| 230 |
function Greater_Or_Equal |
| 231 |
(Left : Super_String; |
| 232 |
Right : Wide_Wide_String) return Boolean; |
| 233 |
|
| 234 |
function Greater_Or_Equal |
| 235 |
(Left : Wide_Wide_String; |
| 236 |
Right : Super_String) return Boolean; |
| 237 |
|
| 238 |
---------------------- |
| 239 |
-- Search Functions -- |
| 240 |
---------------------- |
| 241 |
|
| 242 |
function Super_Index |
| 243 |
(Source : Super_String; |
| 244 |
Pattern : Wide_Wide_String; |
| 245 |
Going : Direction := Forward; |
| 246 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping := |
| 247 |
Wide_Wide_Maps.Identity) |
| 248 |
return Natural; |
| 249 |
|
| 250 |
function Super_Index |
| 251 |
(Source : Super_String; |
| 252 |
Pattern : Wide_Wide_String; |
| 253 |
Going : Direction := Forward; |
| 254 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function) |
| 255 |
return Natural; |
| 256 |
|
| 257 |
function Super_Index |
| 258 |
(Source : Super_String; |
| 259 |
Set : Wide_Wide_Maps.Wide_Wide_Character_Set; |
| 260 |
Test : Membership := Inside; |
| 261 |
Going : Direction := Forward) return Natural; |
| 262 |
|
| 263 |
function Super_Index |
| 264 |
(Source : Super_String; |
| 265 |
Pattern : Wide_Wide_String; |
| 266 |
From : Positive; |
| 267 |
Going : Direction := Forward; |
| 268 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping := |
| 269 |
Wide_Wide_Maps.Identity) |
| 270 |
return Natural; |
| 271 |
|
| 272 |
function Super_Index |
| 273 |
(Source : Super_String; |
| 274 |
Pattern : Wide_Wide_String; |
| 275 |
From : Positive; |
| 276 |
Going : Direction := Forward; |
| 277 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function) |
| 278 |
return Natural; |
| 279 |
|
| 280 |
function Super_Index |
| 281 |
(Source : Super_String; |
| 282 |
Set : Wide_Wide_Maps.Wide_Wide_Character_Set; |
| 283 |
From : Positive; |
| 284 |
Test : Membership := Inside; |
| 285 |
Going : Direction := Forward) return Natural; |
| 286 |
|
| 287 |
function Super_Index_Non_Blank |
| 288 |
(Source : Super_String; |
| 289 |
Going : Direction := Forward) return Natural; |
| 290 |
|
| 291 |
function Super_Index_Non_Blank |
| 292 |
(Source : Super_String; |
| 293 |
From : Positive; |
| 294 |
Going : Direction := Forward) return Natural; |
| 295 |
|
| 296 |
function Super_Count |
| 297 |
(Source : Super_String; |
| 298 |
Pattern : Wide_Wide_String; |
| 299 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping := |
| 300 |
Wide_Wide_Maps.Identity) |
| 301 |
return Natural; |
| 302 |
|
| 303 |
function Super_Count |
| 304 |
(Source : Super_String; |
| 305 |
Pattern : Wide_Wide_String; |
| 306 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function) |
| 307 |
return Natural; |
| 308 |
|
| 309 |
function Super_Count |
| 310 |
(Source : Super_String; |
| 311 |
Set : Wide_Wide_Maps.Wide_Wide_Character_Set) return Natural; |
| 312 |
|
| 313 |
procedure Super_Find_Token |
| 314 |
(Source : Super_String; |
| 315 |
Set : Wide_Wide_Maps.Wide_Wide_Character_Set; |
| 316 |
From : Positive; |
| 317 |
Test : Membership; |
| 318 |
First : out Positive; |
| 319 |
Last : out Natural); |
| 320 |
|
| 321 |
procedure Super_Find_Token |
| 322 |
(Source : Super_String; |
| 323 |
Set : Wide_Wide_Maps.Wide_Wide_Character_Set; |
| 324 |
Test : Membership; |
| 325 |
First : out Positive; |
| 326 |
Last : out Natural); |
| 327 |
|
| 328 |
------------------------------------ |
| 329 |
-- String Translation Subprograms -- |
| 330 |
------------------------------------ |
| 331 |
|
| 332 |
function Super_Translate |
| 333 |
(Source : Super_String; |
| 334 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping) |
| 335 |
return Super_String; |
| 336 |
|
| 337 |
procedure Super_Translate |
| 338 |
(Source : in out Super_String; |
| 339 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping); |
| 340 |
|
| 341 |
function Super_Translate |
| 342 |
(Source : Super_String; |
| 343 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function) |
| 344 |
return Super_String; |
| 345 |
|
| 346 |
procedure Super_Translate |
| 347 |
(Source : in out Super_String; |
| 348 |
Mapping : Wide_Wide_Maps.Wide_Wide_Character_Mapping_Function); |
| 349 |
|
| 350 |
--------------------------------------- |
| 351 |
-- String Transformation Subprograms -- |
| 352 |
--------------------------------------- |
| 353 |
|
| 354 |
function Super_Replace_Slice |
| 355 |
(Source : Super_String; |
| 356 |
Low : Positive; |
| 357 |
High : Natural; |
| 358 |
By : Wide_Wide_String; |
| 359 |
Drop : Truncation := Error) return Super_String; |
| 360 |
|
| 361 |
procedure Super_Replace_Slice |
| 362 |
(Source : in out Super_String; |
| 363 |
Low : Positive; |
| 364 |
High : Natural; |
| 365 |
By : Wide_Wide_String; |
| 366 |
Drop : Truncation := Error); |
| 367 |
|
| 368 |
function Super_Insert |
| 369 |
(Source : Super_String; |
| 370 |
Before : Positive; |
| 371 |
New_Item : Wide_Wide_String; |
| 372 |
Drop : Truncation := Error) return Super_String; |
| 373 |
|
| 374 |
procedure Super_Insert |
| 375 |
(Source : in out Super_String; |
| 376 |
Before : Positive; |
| 377 |
New_Item : Wide_Wide_String; |
| 378 |
Drop : Truncation := Error); |
| 379 |
|
| 380 |
function Super_Overwrite |
| 381 |
(Source : Super_String; |
| 382 |
Position : Positive; |
| 383 |
New_Item : Wide_Wide_String; |
| 384 |
Drop : Truncation := Error) return Super_String; |
| 385 |
|
| 386 |
procedure Super_Overwrite |
| 387 |
(Source : in out Super_String; |
| 388 |
Position : Positive; |
| 389 |
New_Item : Wide_Wide_String; |
| 390 |
Drop : Truncation := Error); |
| 391 |
|
| 392 |
function Super_Delete |
| 393 |
(Source : Super_String; |
| 394 |
From : Positive; |
| 395 |
Through : Natural) return Super_String; |
| 396 |
|
| 397 |
procedure Super_Delete |
| 398 |
(Source : in out Super_String; |
| 399 |
From : Positive; |
| 400 |
Through : Natural); |
| 401 |
|
| 402 |
--------------------------------- |
| 403 |
-- String Selector Subprograms -- |
| 404 |
--------------------------------- |
| 405 |
|
| 406 |
function Super_Trim |
| 407 |
(Source : Super_String; |
| 408 |
Side : Trim_End) return Super_String; |
| 409 |
|
| 410 |
procedure Super_Trim |
| 411 |
(Source : in out Super_String; |
| 412 |
Side : Trim_End); |
| 413 |
|
| 414 |
function Super_Trim |
| 415 |
(Source : Super_String; |
| 416 |
Left : Wide_Wide_Maps.Wide_Wide_Character_Set; |
| 417 |
Right : Wide_Wide_Maps.Wide_Wide_Character_Set) return Super_String; |
| 418 |
|
| 419 |
procedure Super_Trim |
| 420 |
(Source : in out Super_String; |
| 421 |
Left : Wide_Wide_Maps.Wide_Wide_Character_Set; |
| 422 |
Right : Wide_Wide_Maps.Wide_Wide_Character_Set); |
| 423 |
|
| 424 |
function Super_Head |
| 425 |
(Source : Super_String; |
| 426 |
Count : Natural; |
| 427 |
Pad : Wide_Wide_Character := Wide_Wide_Space; |
| 428 |
Drop : Truncation := Error) return Super_String; |
| 429 |
|
| 430 |
procedure Super_Head |
| 431 |
(Source : in out Super_String; |
| 432 |
Count : Natural; |
| 433 |
Pad : Wide_Wide_Character := Wide_Wide_Space; |
| 434 |
Drop : Truncation := Error); |
| 435 |
|
| 436 |
function Super_Tail |
| 437 |
(Source : Super_String; |
| 438 |
Count : Natural; |
| 439 |
Pad : Wide_Wide_Character := Wide_Wide_Space; |
| 440 |
Drop : Truncation := Error) return Super_String; |
| 441 |
|
| 442 |
procedure Super_Tail |
| 443 |
(Source : in out Super_String; |
| 444 |
Count : Natural; |
| 445 |
Pad : Wide_Wide_Character := Wide_Wide_Space; |
| 446 |
Drop : Truncation := Error); |
| 447 |
|
| 448 |
------------------------------------ |
| 449 |
-- String Constructor Subprograms -- |
| 450 |
------------------------------------ |
| 451 |
|
| 452 |
-- Note: in some of the following routines, there is an extra parameter |
| 453 |
-- Max_Length which specifies the value of the maximum length for the |
| 454 |
-- resulting Super_String value. |
| 455 |
|
| 456 |
function Times |
| 457 |
(Left : Natural; |
| 458 |
Right : Wide_Wide_Character; |
| 459 |
Max_Length : Positive) return Super_String; |
| 460 |
-- Note the additional parameter Max_Length |
| 461 |
|
| 462 |
function Times |
| 463 |
(Left : Natural; |
| 464 |
Right : Wide_Wide_String; |
| 465 |
Max_Length : Positive) return Super_String; |
| 466 |
-- Note the additional parameter Max_Length |
| 467 |
|
| 468 |
function Times |
| 469 |
(Left : Natural; |
| 470 |
Right : Super_String) return Super_String; |
| 471 |
|
| 472 |
function Super_Replicate |
| 473 |
(Count : Natural; |
| 474 |
Item : Wide_Wide_Character; |
| 475 |
Drop : Truncation := Error; |
| 476 |
Max_Length : Positive) return Super_String; |
| 477 |
-- Note the additional parameter Max_Length |
| 478 |
|
| 479 |
function Super_Replicate |
| 480 |
(Count : Natural; |
| 481 |
Item : Wide_Wide_String; |
| 482 |
Drop : Truncation := Error; |
| 483 |
Max_Length : Positive) return Super_String; |
| 484 |
-- Note the additional parameter Max_Length |
| 485 |
|
| 486 |
function Super_Replicate |
| 487 |
(Count : Natural; |
| 488 |
Item : Super_String; |
| 489 |
Drop : Truncation := Error) return Super_String; |
| 490 |
|
| 491 |
procedure Put_Image |
| 492 |
(S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; |
| 493 |
Source : Super_String); |
| 494 |
|
| 495 |
private |
| 496 |
-- Pragma Inline declarations |
| 497 |
|
| 498 |
pragma Inline ("="); |
| 499 |
pragma Inline (Less); |
| 500 |
pragma Inline (Less_Or_Equal); |
| 501 |
pragma Inline (Greater); |
| 502 |
pragma Inline (Greater_Or_Equal); |
| 503 |
pragma Inline (Concat); |
| 504 |
pragma Inline (Super_Count); |
| 505 |
pragma Inline (Super_Element); |
| 506 |
pragma Inline (Super_Find_Token); |
| 507 |
pragma Inline (Super_Index); |
| 508 |
pragma Inline (Super_Index_Non_Blank); |
| 509 |
pragma Inline (Super_Length); |
| 510 |
pragma Inline (Super_Replace_Element); |
| 511 |
pragma Inline (Super_Slice); |
| 512 |
pragma Inline (Super_To_String); |
| 513 |
|
| 514 |
end Ada.Strings.Wide_Wide_Superbounded; |