Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


A.4.3 Fixed-Length String Handling

(1)
The language-defined package Strings.Fixed provides string-handling subprograms for fixed-length strings; that is, for values of type Standard.String. Several of these subprograms are procedures that modify the contents of a String that is passed as an out or an in out parameter; each has additional parameters to control the effect when the logical length of the result differs from the parameter's length.
(2)
For each function that returns a String, the lower bound of the returned value is 1.
(3)
The basic model embodied in the package is that a fixed-length string comprises significant characters and possibly padding (with space characters) on either or both ends. When a shorter string is copied to a longer string, padding is inserted, and when a longer string is copied to a shorter one, padding is stripped. The Move procedure in Strings.Fixed, which takes a String as an out parameter, allows the programmer to control these effects. Similar control is provided by the string transformation procedures.
Static Semantics
(4)
The library package Strings.Fixed has the following declaration:
(5)
       with Ada.Strings.Maps;
       package Ada.Strings.Fixed is
          pragma Preelaborate(Fixed);
(6)
       -- "Copy" procedure for strings of possibly different lengths
(7)
          procedure Move (Source  : in  String;
                          Target  : out String;
                          Drop    : in  Truncation := Error;
                          Justify : in  Alignment  := Left;
                          Pad     : in  Character  := Space);
(8)
       -- Search subprograms
(9)
          function Index (Source   : in String;
                          Pattern  : in String;
                          Going    : in Direction := Forward;
                          Mapping  : in Maps.Character_Mapping
                                       := Maps.Identity)
             return Natural;
(10)
          function Index (Source   : in String;
                          Pattern  : in String;
                          Going    : in Direction := Forward;
                          Mapping  : in Maps.Character_Mapping_Function)
             return Natural;
(11)
          function Index (Source : in String;
                          Set    : in Maps.Character_Set;
                          Test   : in Membership := Inside;
                          Going  : in Direction  := Forward)
             return Natural;
(12)
          function Index_Non_Blank (Source : in String;
                                    Going  : in Direction := Forward)
             return Natural;
(13)
          function Count (Source   : in String;
                          Pattern  : in String;
                          Mapping  : in Maps.Character_Mapping
                                        := Maps.Identity)
             return Natural;
(14)
          function Count (Source   : in String;
                          Pattern  : in String;
                          Mapping  : in Maps.Character_Mapping_Function)
             return Natural;
(15)
          function Count (Source   : in String;
                          Set      : in Maps.Character_Set)
             return Natural;
(16)
          procedure Find_Token (Source : in String;
                                Set    : in Maps.Character_Set;
                                Test   : in Membership;
                                First  : out Positive;
                                Last   : out Natural);
(17)
       -- String translation subprograms
(18)
          function Translate (Source  : in String;
                              Mapping : in Maps.Character_Mapping)
             return String;
(19)
          procedure Translate (Source  : in out String;
                               Mapping : in Maps.Character_Mapping);
(20)
          function Translate (Source  : in String;
                              Mapping : in Maps.Character_Mapping_Function)
             return String;
(21)
          procedure Translate (Source  : in out String;
                               Mapping : in Maps.Character_Mapping_Function);
(22)
       -- String transformation subprograms
(23)
          function Replace_Slice (Source   : in String;
                                  Low      : in Positive;
                                  High     : in Natural;
                                  By       : in String)
             return String;
(24)
          procedure Replace_Slice (Source   : in out String;
                                   Low      : in Positive;
                                   High     : in Natural;
                                   By       : in String;
                                   Drop     : in Truncation := Error;
                                   Justify  : in Alignment  := Left;
                                   Pad      : in Character  := Space);
(25)
          function Insert (Source   : in String;
                           Before   : in Positive;
                           New_Item : in String)
             return String;
(26)
          procedure Insert (Source   : in out String;
                            Before   : in Positive;
                            New_Item : in String;
                            Drop     : in Truncation := Error);
(27)
          function Overwrite (Source   : in String;
                              Position : in Positive;
                              New_Item : in String)
             return String;
(28)
          procedure Overwrite (Source   : in out String;
                               Position : in Positive;
                               New_Item : in String;
                               Drop     : in Truncation := Right);
(29)
          function Delete (Source  : in String;
                           From    : in Positive;
                           Through : in Natural)
             return String;
(30)
          procedure Delete (Source  : in out String;
                            From    : in Positive;
                            Through : in Natural;
                            Justify : in Alignment := Left;
                            Pad     : in Character := Space);
(31)
        --String selector subprograms
          function Trim (Source : in String;
                         Side   : in Trim_End)
             return String;
(32)
          procedure Trim (Source  : in out String;
                          Side    : in Trim_End;
                          Justify : in Alignment := Left;
                          Pad     : in Character := Space);
(33)
          function Trim (Source : in String;
                         Left   : in Maps.Character_Set;
                         Right  : in Maps.Character_Set)
             return String;
(34)
          procedure Trim (Source  : in out String;
                          Left    : in Maps.Character_Set;
                          Right   : in Maps.Character_Set;
                          Justify : in Alignment := Strings.Left;
                          Pad     : in Character := Space);
(35)
          function Head (Source : in String;
                         Count  : in Natural;
                         Pad    : in Character := Space)
             return String;
(36)
          procedure Head (Source  : in out String;
                          Count   : in Natural;
                          Justify : in Alignment := Left;
                          Pad     : in Character := Space);
(37)
          function Tail (Source : in String;
                         Count  : in Natural;
                         Pad    : in Character := Space)
             return String;
(38)
          procedure Tail (Source  : in out String;
                          Count   : in Natural;
                          Justify : in Alignment := Left;
                          Pad     : in Character := Space);
(39)
       --String constructor functions
(40)
          function "*" (Left  : in Natural;
                        Right : in Character) return String;
(41)
          function "*" (Left  : in Natural;
                        Right : in String) return String;
(42)
       end Ada.Strings.Fixed;
(43)
The effects of the above subprograms are as follows.
(44)
       procedure Move (Source  : in  String;
                       Target  : out String;
                       Drop    : in  Truncation := Error;
                       Justify : in  Alignment  := Left;
                       Pad     : in  Character  := Space);
(45)
(46)
(47)
(48)
(49)
(50)
(51)
(52)
(53)
(54)
(55)
(56)
(57)
       function Index (Source   : in String;
                       Pattern  : in String;
                       Going    : in Direction := Forward;
                       Mapping  : in Maps.Character_Mapping
                                     := Maps.Identity)
          return Natural;

       function Index (Source   : in String;
                       Pattern  : in String;
                       Going    : in Direction := Forward;
                       Mapping  : in Maps.Character_Mapping_Function)
          return Natural;
(58)
(59)
       function Index (Source : in String;
                       Set    : in Maps.Character_Set;
                       Test   : in Membership := Inside;
                       Going  : in Direction  := Forward)
          return Natural;
(60)
(61)
       function Index_Non_Blank (Source : in String;
                                 Going  : in Direction := Forward)
          return Natural;
(62)
(63)
       function Count (Source   : in String;
                       Pattern  : in String;
                       Mapping  : in Maps.Character_Mapping
                                    := Maps.Identity)
          return Natural;

       function Count (Source   : in String;
                       Pattern  : in String;
                       Mapping  : in Maps.Character_Mapping_Function)
          return Natural;
(64)
(65)
       function Count (Source   : in String;
                       Set      : in Maps.Character_Set)
          return Natural;
(66)
(67)
       procedure Find_Token (Source : in String;
                             Set    : in Maps.Character_Set;
                             Test   : in Membership;
                             First  : out Positive;
                             Last   : out Natural);
(68)
(69)
       function Translate (Source  : in String;
                           Mapping : in Maps.Character_Mapping)
          return String;

       function Translate (Source  : in String;
                           Mapping : in Maps.Character_Mapping_Function)
          return String;
(70)
(71)
       procedure Translate (Source  : in out String;
                            Mapping : in Maps.Character_Mapping);

       procedure Translate (Source  : in out String;
                            Mapping : in Maps.Character_Mapping_Function);
(72)
(73)
       function Replace_Slice (Source   : in String;
                               Low      : in Positive;
                               High     : in Natural;
                               By       : in String)
          return String;
(74)
(75)
       procedure Replace_Slice (Source   : in out String;
                                Low      : in Positive;
                                High     : in Natural;
                                By       : in String;
                                Drop     : in Truncation := Error;
                                Justify  : in Alignment  := Left;
                                Pad      : in Character  := Space);
(76)
(77)
       function Insert (Source   : in String;
                        Before   : in Positive;
                        New_Item : in String)
          return String;
(78)
(79)
       procedure Insert (Source   : in out String;
                         Before   : in Positive;
                         New_Item : in String;
                         Drop     : in Truncation := Error);
(80)
(81)
       function Overwrite (Source   : in String;
                           Position : in Positive;
                           New_Item : in String)
          return String;
(82)
(83)
       procedure Overwrite (Source   : in out String;
                            Position : in Positive;
                            New_Item : in String;
                            Drop     : in Truncation := Right);
(84)
(85)
       function Delete (Source  : in String;
                        From    : in Positive;
                        Through : in Natural)
          return String;
(86)
(87)
       procedure Delete (Source  : in out String;
                         From    : in Positive;
                         Through : in Natural;
                         Justify : in Alignment := Left;
                         Pad     : in Character := Space);
(88)
(89)
       function Trim (Source : in String;
                      Side   : in Trim_End)
         return String;
(90)
(91)
       procedure Trim (Source  : in out String;
                       Side    : in Trim_End;
                       Justify : in Alignment := Left;
                       Pad     : in Character := Space);
(92)
(93)
       function Trim (Source : in String;
                      Left   : in Maps.Character_Set;
                      Right  : in Maps.Character_Set)
          return String;
(94)
(95)
       procedure Trim (Source  : in out String;
                       Left    : in Maps.Character_Set;
                       Right   : in Maps.Character_Set;
                       Justify : in Alignment := Strings.Left;
                       Pad     : in Character := Space);
(96)
(97)
       function Head (Source : in String;
                      Count  : in Natural;
                      Pad    : in Character := Space)
          return String;
(98)
(99)
       procedure Head (Source  : in out String;
                       Count   : in Natural;
                       Justify : in Alignment := Left;
                       Pad     : in Character := Space);
(100)
(101)
       function Tail (Source : in String;
                      Count  : in Natural;
                      Pad    : in Character := Space)
          return String;
(102)
(103)
       procedure Tail (Source  : in out String;
                       Count   : in Natural;
                       Justify : in Alignment := Left;
                       Pad     : in Character := Space);
(104)
(105)
       function "*" (Left  : in Natural;
                     Right : in Character) return String;

       function "*" (Left  : in Natural;
                     Right : in String) return String;
(106)

(107)
(108)
(109)

Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12