home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 4.ddi / LIB / SRC / STRINGS.PF < prev    next >
Encoding:
Text File  |  1990-12-16  |  6.1 KB  |  133 lines

  1. pragma c_include('implement.pf');
  2. pragma c_include('language.pf');
  3. package Strings;
  4.    pragma Routine_aliasing_convention(Implement.RTE_aliasing);
  5.    type Cardinal = Standard.Cardinal; 
  6.    {
  7.      MetaWare Pascal String functions.
  8.      Some of these routines yield a fixed-size 256-byte string.
  9.      Others take by "var" the destination of their output.
  10.      Still others are functions producing a pointer to their output;
  11.         the string is allocated on the heap.
  12.      The latter two classes of functions are used by the compiler to
  13.         implement the intrinsic string functions.
  14.         Strings allocated on the heap are freed by calling Stringrls(M),
  15.         where M := Stringmark() was issued before the allocations occurred. 
  16.      The first class of functions were those provided in earlier versions
  17.         of Professional Pascal, when the compiler did not have the
  18.         string intrinsics built-in.  We continue to provide them for
  19.         backwards compatibility.
  20.    }
  21.    type 
  22.       String256 = String(256);
  23.       Dynamic_string = string(MAXCARD-2);
  24.       PDynamic_string = ^Dynamic_string;
  25.       String_heap_mark = Cardinal; 
  26.  
  27.    -- Take the substring of a string beginning at Start for Length characters.
  28.    -- We require that Start <= Length(S).  If Length is too long we truncate
  29.    -- without warning.  If Length = SUBSTR_TO_END, we take the characters
  30.    -- from Start to the end of the string.
  31.  
  32.    const SUBSTR_TO_END = #ffff;
  33.    function Substr(const S: String; Start,Length: Cardinal): String256; 
  34.                                External;
  35.    procedure VSubstr(var Dest:String; const S: String; Start,Length: Cardinal); 
  36.                                External;
  37.    function Psubstr(const S:String; Start,Length:Cardinal):PDynamic_string;
  38.                                External;
  39.  
  40.    -- Trim off blanks to the left.
  41.    procedure Vltrim(var Dest:String; const Source: String);     
  42.                                External;
  43.    function Pltrim(const Source:String):PDynamic_string;        
  44.                                External;
  45.    -- Trim off blanks to the right.
  46.    procedure Vtrim(var Dest:String; const Source: String);
  47.                                External;
  48.    function Ptrim(const Source:String):PDynamic_string;    External;
  49.    
  50.    -- Compress blanks to a single blank throughout.
  51.    -- If Dest cannot hold the result, silent truncation occurs.
  52.    procedure Vcompress(var Dest:String; const Source: String);
  53.                                External;
  54.    function Pcompress(const Source:String):PDynamic_string;    
  55.                                External;
  56.    
  57.  
  58.    -- Delete characters in S starting at Start and going for Length.
  59.    -- To avoid a run-time error message, we require:
  60.    -- (Start in [1..(Slen := Length(Source))]) and
  61.    -- (Start+Length-1 <= Slen) and
  62.    -- (Maxlength(Dest) >= Slen-Length).
  63.    -- Deletestring deletes in-place.
  64.    procedure Deletestring(var Source_and_dest:String; Start, Length: Cardinal);
  65.                             External;
  66.    procedure Vdelete(var Dest:String; const Source:String; Start, Length:Cardinal);
  67.                                External;
  68.    function Pdelete(const Source:String; Start,Length:Cardinal):PDynamic_string;
  69.                                External;
  70.    
  71.    -- Pad S to length Length; any added characters have the value C.
  72.    procedure Padstring(var S: String; Length: Cardinal; C: Char); 
  73.                                External;
  74.  
  75.    -- Append Suffix to S.  If S won't hold the result, 
  76.    -- truncation occurs without warning.
  77.    procedure Append(var S: String; const Suffix: String);      
  78.                                External;
  79.  
  80.    { Insert Insert_me into Into_here just before Just_before.    }
  81.    { Error if Maxlength(Into_here) < Length(Insert_me) + Length(Into_here) }
  82.    { or Just_before > Length(Into_here)+1.            }
  83.    { (We allow an "insertion" just at the end of the string;    }
  84.    { it turns into a concatenation.  This is an improvement over}
  85.    { the Microsoft Pascal version of this intrinsic.)        }
  86.    procedure Insertstring(const Insert_me:String; var Into_here: String;
  87.                 Just_before:Cardinal);    External;
  88.                 
  89.    -- String search functions.
  90.    
  91.    -- Index returns the first I, 1 <= I <= Length(S), 
  92.    -- such that Substr(S,I,Length(Pattern)) = Pattern.
  93.    -- 0 is returned if Pattern is not found in S.
  94.    -- Index2 is the same as Index, except search starts at Where_to_start_in_S.
  95.    -- rather than 1.  1 <= Where_to_start_in_S <= Length(S).
  96.    -- Rindex and its variant Rindex2 start the search at the right end of S.
  97.    
  98.    function Index(const S,Pattern: String): Cardinal;    External;
  99.    function Index2(const S,Pattern: String; Where_to_start_in_S:Cardinal)
  100.        : Cardinal;                    External;
  101.    function RIndex(const S,Pattern: String): Cardinal;    External;
  102.    function RIndex2(const S,Pattern: String; Where_to_start_in_S:Cardinal)
  103.        : Cardinal;                    External;
  104.  
  105.  
  106.    -- This function is called when one of the string functions
  107.    -- discovers an error.  The default is to print the message
  108.    -- and do a stack dump.  You may replace it with your own.
  109.    procedure String_error(const S:String);                      External;
  110.    
  111.    pragma calling_convention(Language.C);               
  112.    -- This is called by the compiler to concatenate an arbitrary
  113.    -- sequence of strings.  The parameter list is ended by a nil pointer.
  114.    -- This function would be difficult for a user to call due to parm checking.
  115.    function Pcat(POpd1:PDynamic_string):PDynamic_string;    External;
  116.    pragma calling_convention();
  117.    
  118.    -- These functions are used to allocate string temporaries on the
  119.    -- heap.  Due to organization of the library, they will be dragged
  120.    -- in whenever you call function Vxxx where function Pxxx exists
  121.    -- (e.g. if you call Vsubstr; Psubstr exists).
  122.    -- If you are trying to exclude the heap manager from the link
  123.    -- you can replace these functions with some of your own.  
  124.    function Allocate_string(Size:Cardinal):Pdynamic_string;    External;
  125.    function Stringmark():String_heap_mark;                      External;
  126.    procedure Stringrls(M:String_heap_mark);                     External;
  127.  
  128.    -- Returns the parameters on the command line.  The string can 
  129.    -- be of arbitrary length, so that VS_pascal.Parms calls one of these
  130.    -- two:
  131.    procedure VVSparms(var Dest:String);                External;
  132.    function PVSparms():PDynamic_string;                External;
  133.    end;