Ada 编程/库/Ada.Strings.Unbounded
外观
此语言功能从 Ada 95 开始可用。
Ada.Strings.Unbounded 是 预定义语言环境 自 Ada 95 以来的一部分。
此包定义了无界字符串处理的操作。
Ada.Strings.Unbounded 在多个地方使用。这里有一些相关的摘录。一如既往,您可以按照下载链接查看完整的示例。
无界字符串和有界字符串之间的转换
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));
另一个例子
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;
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com> -- 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;
FSF GNAT
- 规范:a-strunb.ads
- 主体:a-strunb.adb
drake
