home *** CD-ROM | disk | FTP | other *** search
- pragma c_include('implement.pf');
- pragma c_include('language.pf');
- package Strings;
- pragma Routine_aliasing_convention(Implement.RTE_aliasing);
- type Cardinal = Standard.Cardinal;
- {
- MetaWare Pascal String functions.
- Some of these routines yield a fixed-size 256-byte string.
- Others take by "var" the destination of their output.
- Still others are functions producing a pointer to their output;
- the string is allocated on the heap.
- The latter two classes of functions are used by the compiler to
- implement the intrinsic string functions.
- Strings allocated on the heap are freed by calling Stringrls(M),
- where M := Stringmark() was issued before the allocations occurred.
- The first class of functions were those provided in earlier versions
- of Professional Pascal, when the compiler did not have the
- string intrinsics built-in. We continue to provide them for
- backwards compatibility.
- }
- type
- String256 = String(256);
- Dynamic_string = string(MAXCARD-2);
- PDynamic_string = ^Dynamic_string;
- String_heap_mark = Cardinal;
-
- -- Take the substring of a string beginning at Start for Length characters.
- -- We require that Start <= Length(S). If Length is too long we truncate
- -- without warning. If Length = SUBSTR_TO_END, we take the characters
- -- from Start to the end of the string.
-
- const SUBSTR_TO_END = #ffff;
- function Substr(const S: String; Start,Length: Cardinal): String256;
- External;
- procedure VSubstr(var Dest:String; const S: String; Start,Length: Cardinal);
- External;
- function Psubstr(const S:String; Start,Length:Cardinal):PDynamic_string;
- External;
-
- -- Trim off blanks to the left.
- procedure Vltrim(var Dest:String; const Source: String);
- External;
- function Pltrim(const Source:String):PDynamic_string;
- External;
- -- Trim off blanks to the right.
- procedure Vtrim(var Dest:String; const Source: String);
- External;
- function Ptrim(const Source:String):PDynamic_string; External;
-
- -- Compress blanks to a single blank throughout.
- -- If Dest cannot hold the result, silent truncation occurs.
- procedure Vcompress(var Dest:String; const Source: String);
- External;
- function Pcompress(const Source:String):PDynamic_string;
- External;
-
-
- -- Delete characters in S starting at Start and going for Length.
- -- To avoid a run-time error message, we require:
- -- (Start in [1..(Slen := Length(Source))]) and
- -- (Start+Length-1 <= Slen) and
- -- (Maxlength(Dest) >= Slen-Length).
- -- Deletestring deletes in-place.
- procedure Deletestring(var Source_and_dest:String; Start, Length: Cardinal);
- External;
- procedure Vdelete(var Dest:String; const Source:String; Start, Length:Cardinal);
- External;
- function Pdelete(const Source:String; Start,Length:Cardinal):PDynamic_string;
- External;
-
- -- Pad S to length Length; any added characters have the value C.
- procedure Padstring(var S: String; Length: Cardinal; C: Char);
- External;
-
- -- Append Suffix to S. If S won't hold the result,
- -- truncation occurs without warning.
- procedure Append(var S: String; const Suffix: String);
- External;
-
- { Insert Insert_me into Into_here just before Just_before. }
- { Error if Maxlength(Into_here) < Length(Insert_me) + Length(Into_here) }
- { or Just_before > Length(Into_here)+1. }
- { (We allow an "insertion" just at the end of the string; }
- { it turns into a concatenation. This is an improvement over}
- { the Microsoft Pascal version of this intrinsic.) }
- procedure Insertstring(const Insert_me:String; var Into_here: String;
- Just_before:Cardinal); External;
-
- -- String search functions.
-
- -- Index returns the first I, 1 <= I <= Length(S),
- -- such that Substr(S,I,Length(Pattern)) = Pattern.
- -- 0 is returned if Pattern is not found in S.
- -- Index2 is the same as Index, except search starts at Where_to_start_in_S.
- -- rather than 1. 1 <= Where_to_start_in_S <= Length(S).
- -- Rindex and its variant Rindex2 start the search at the right end of S.
-
- function Index(const S,Pattern: String): Cardinal; External;
- function Index2(const S,Pattern: String; Where_to_start_in_S:Cardinal)
- : Cardinal; External;
- function RIndex(const S,Pattern: String): Cardinal; External;
- function RIndex2(const S,Pattern: String; Where_to_start_in_S:Cardinal)
- : Cardinal; External;
-
-
- -- This function is called when one of the string functions
- -- discovers an error. The default is to print the message
- -- and do a stack dump. You may replace it with your own.
- procedure String_error(const S:String); External;
-
- pragma calling_convention(Language.C);
- -- This is called by the compiler to concatenate an arbitrary
- -- sequence of strings. The parameter list is ended by a nil pointer.
- -- This function would be difficult for a user to call due to parm checking.
- function Pcat(POpd1:PDynamic_string):PDynamic_string; External;
- pragma calling_convention();
-
- -- These functions are used to allocate string temporaries on the
- -- heap. Due to organization of the library, they will be dragged
- -- in whenever you call function Vxxx where function Pxxx exists
- -- (e.g. if you call Vsubstr; Psubstr exists).
- -- If you are trying to exclude the heap manager from the link
- -- you can replace these functions with some of your own.
- function Allocate_string(Size:Cardinal):Pdynamic_string; External;
- function Stringmark():String_heap_mark; External;
- procedure Stringrls(M:String_heap_mark); External;
-
- -- Returns the parameters on the command line. The string can
- -- be of arbitrary length, so that VS_pascal.Parms calls one of these
- -- two:
- procedure VVSparms(var Dest:String); External;
- function PVSparms():PDynamic_string; External;
- end;