< Ada Programming < Libraries 
 
 
 
 
 
      
Ada. Time-tested, safe and secure.
This language feature is available from Ada 95 on. Ada.Strings.Unbounded is a unit of the Predefined Language Environment since Ada 95.
This package defines the operations for unbounded string handling.
Usage
Ada.Strings.Unbounded is used in several places. Here some relevant extracts. As always you can follow the download links to see the full examples.
Conversion between unbounded and bounded strings:
withAda.Strings.Unbounded;packageSUrenamesAda.Strings.Unbounded; X : SU.Unbounded_String := SU.To_Unbounded_String (CL.Argument (1)); T_IO.Put_Line (SU.To_String (X)); X := SU.To_Unbounded_String (CL.Argument (2)); T_IO.Put_Line (SU.To_String (X));
Another example:
with
  Ada.Text_IO,
  Ada.Integer_Text_IO,
  Ada.Strings.Unbounded,
  Ada.Text_IO.Unbounded_IO;
procedure User_Input2 is
   S : Ada.Strings.Unbounded.Unbounded_String;
   I : Integer;
begin
   Ada.Text_IO.Put("Enter a string: ");
   S := Ada.Strings.Unbounded.To_Unbounded_String(Ada.Text_IO.Get_Line);
   Ada.Text_IO.Put_Line(Ada.Strings.Unbounded.To_String(S));
   Ada.Text_IO.Unbounded_IO.Put_Line(S);
   Ada.Text_IO.Put("Enter an integer: ");
   Ada.Integer_Text_IO.Get(I);
   Ada.Text_IO.Put_Line(Integer'Image(I));
end User_Input2;
withAda.Strings.Unbounded;packageStrrenamesAda.Strings.Unbounded;functionGet_LinereturnStr.Unbounded_String;usetypeStr.Unbounded_String; Operation : Str.Unbounded_String;functionGet_LinereturnStr.Unbounded_StringisBufferSize :constant:= 2000; Retval : Str.Unbounded_String := Str.Null_Unbounded_String; Item : String (1 .. BufferSize); Last : Natural;beginGet_Whole_Line :loopT_IO.Get_Line (Item => Item, Last => Last); Str.Append (Source => Retval, New_Item => Item (1 .. Last));exitGet_Whole_LinewhenLast < Item'Last;endloopGet_Whole_Line;returnRetval;endGet_Line;
Specification
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <[email protected]> -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual -- -------------------------------------------------------------------------withAda.Strings.Maps;packageAda.Strings.UnboundedispragmaPreelaborate (Unbounded);typeUnbounded_Stringisprivate;pragmaPreelaborable_Initialization (Unbounded_String); Null_Unbounded_String :constantUnbounded_String;functionLength (Source :inUnbounded_String)returnNatural;typeString_AccessisaccessallString;procedureFree (X :inoutString_Access); -- Conversion, Concatenation, and Selection functionsfunctionTo_Unbounded_String (Source :inString)returnUnbounded_String;functionTo_Unbounded_String (Length :inNatural)returnUnbounded_String;functionTo_String (Source :inUnbounded_String)returnString;procedureSet_Unbounded_String (Target :outUnbounded_String; Source :inString);procedureAppend (Source :inoutUnbounded_String; New_Item :inUnbounded_String);procedureAppend (Source :inoutUnbounded_String; New_Item :inString);procedureAppend (Source :inoutUnbounded_String; New_Item :inCharacter);function"&" (Left, Right :inUnbounded_String)returnUnbounded_String;function"&" (Left :inUnbounded_String; Right :inString)returnUnbounded_String;function"&" (Left :inString; Right :inUnbounded_String)returnUnbounded_String;function"&" (Left :inUnbounded_String; Right :inCharacter)returnUnbounded_String;function"&" (Left :inCharacter; Right :inUnbounded_String)returnUnbounded_String;functionElement (Source :inUnbounded_String; Index :inPositive)returnCharacter;procedureReplace_Element (Source :inoutUnbounded_String; Index :inPositive; By :inCharacter);functionSlice (Source :inUnbounded_String; Low :inPositive; High :inNatural)returnString;functionUnbounded_Slice (Source :inUnbounded_String; Low :inPositive; High :inNatural)returnUnbounded_String;procedureUnbounded_Slice (Source :inUnbounded_String; Target :outUnbounded_String; Low :inPositive; High :inNatural);function"=" (Left, Right :inUnbounded_String)returnBoolean;function"=" (Left :inUnbounded_String; Right :inString)returnBoolean;function"=" (Left :inString; Right :inUnbounded_String)returnBoolean;function"<" (Left, Right :inUnbounded_String)returnBoolean;function"<" (Left :inUnbounded_String; Right :inString)returnBoolean;function"<" (Left :inString; Right :inUnbounded_String)returnBoolean;function"<=" (Left, Right :inUnbounded_String)returnBoolean;function"<=" (Left :inUnbounded_String; Right :inString)returnBoolean;function"<=" (Left :inString; Right :inUnbounded_String)returnBoolean;function">" (Left, Right :inUnbounded_String)returnBoolean;function">" (Left :inUnbounded_String; Right :inString)returnBoolean;function">" (Left :inString; Right :inUnbounded_String)returnBoolean;function">=" (Left, Right :inUnbounded_String)returnBoolean;function">=" (Left :inUnbounded_String; Right :inString)returnBoolean;function">=" (Left :inString; Right :inUnbounded_String)returnBoolean; -- Search subprogramsfunctionIndex (Source :inUnbounded_String; Pattern :inString; From :inPositive; Going :inDirection := Forward; Mapping :inMaps.Character_Mapping := Maps.Identity)returnNatural;functionIndex (Source :inUnbounded_String; Pattern :inString; From :inPositive; Going :inDirection := Forward; Mapping :inMaps.Character_Mapping_Function)returnNatural;functionIndex (Source :inUnbounded_String; Pattern :inString; Going :inDirection := Forward; Mapping :inMaps.Character_Mapping := Maps.Identity)returnNatural;functionIndex (Source :inUnbounded_String; Pattern :inString; Going :inDirection := Forward; Mapping :inMaps.Character_Mapping_Function)returnNatural;functionIndex (Source :inUnbounded_String; Set :inMaps.Character_Set; From :inPositive; Test :inMembership := Inside; Going :inDirection := Forward)returnNatural;functionIndex (Source :inUnbounded_String; Set :inMaps.Character_Set; Test :inMembership := Inside; Going :inDirection := Forward)returnNatural;functionIndex_Non_Blank (Source :inUnbounded_String; From :inPositive; Going :inDirection := Forward)returnNatural;functionIndex_Non_Blank (Source :inUnbounded_String; Going :inDirection := Forward)returnNatural;functionCount (Source :inUnbounded_String; Pattern :inString; Mapping :inMaps.Character_Mapping := Maps.Identity)returnNatural;functionCount (Source :inUnbounded_String; Pattern :inString; Mapping :inMaps.Character_Mapping_Function)returnNatural;functionCount (Source :inUnbounded_String; Set :inMaps.Character_Set)returnNatural;procedureFind_Token (Source :inUnbounded_String; Set :inMaps.Character_Set; Test :inMembership; First :outPositive; Last :outNatural); -- String translation subprogramsfunctionTranslate (Source :inUnbounded_String; Mapping :inMaps.Character_Mapping)returnUnbounded_String;procedureTranslate (Source :inoutUnbounded_String; Mapping :inMaps.Character_Mapping);functionTranslate (Source :inUnbounded_String; Mapping :inMaps.Character_Mapping_Function)returnUnbounded_String;procedureTranslate (Source :inoutUnbounded_String; Mapping :inMaps.Character_Mapping_Function); -- String transformation subprogramsfunctionReplace_Slice (Source :inUnbounded_String; Low :inPositive; High :inNatural; By :inString)returnUnbounded_String;procedureReplace_Slice (Source :inoutUnbounded_String; Low :inPositive; High :inNatural; By :inString);functionInsert (Source :inUnbounded_String; Before :inPositive; New_Item :inString)returnUnbounded_String;procedureInsert (Source :inoutUnbounded_String; Before :inPositive; New_Item :inString);functionOverwrite (Source :inUnbounded_String; Position :inPositive; New_Item :inString)returnUnbounded_String;procedureOverwrite (Source :inoutUnbounded_String; Position :inPositive; New_Item :inString);functionDelete (Source :inUnbounded_String; From :inPositive; Through :inNatural)returnUnbounded_String;procedureDelete (Source :inoutUnbounded_String; From :inPositive; Through :inNatural);functionTrim (Source :inUnbounded_String; Side :inTrim_End)returnUnbounded_String;procedureTrim (Source :inoutUnbounded_String; Side :inTrim_End);functionTrim (Source :inUnbounded_String; Left :inMaps.Character_Set; Right :inMaps.Character_Set)returnUnbounded_String;procedureTrim (Source :inoutUnbounded_String; Left :inMaps.Character_Set; Right :inMaps.Character_Set);functionHead (Source :inUnbounded_String; Count :inNatural; Pad :inCharacter := Space)returnUnbounded_String;procedureHead (Source :inoutUnbounded_String; Count :inNatural; Pad :inCharacter := Space);functionTail (Source :inUnbounded_String; Count :inNatural; Pad :inCharacter := Space)returnUnbounded_String;procedureTail (Source :inoutUnbounded_String; Count :inNatural; Pad :inCharacter := Space);function"*" (Left :inNatural; Right :inCharacter)returnUnbounded_String;function"*" (Left :inNatural; Right :inString)returnUnbounded_String;function"*" (Left :inNatural; Right :inUnbounded_String)returnUnbounded_String;privatepragmaImport (Ada, Unbounded_String);pragmaImport (Ada, Null_Unbounded_String);endAda.Strings.Unbounded;
See also
Wikibook
Ada Reference Manual
Ada 95
Ada 2005
Ada 2012
Open-Source Implementations
FSF GNAT
- Specification: a-strunb.ads
- Body: a-strunb.adb
drake
- Specification: strings/a-strunb.ads
    This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.