Dec 242017
 
Various string functions in TP 4.0.
File STRNFST4.ZIP from The Programmer’s Corner in
Category Pascal Source Code
Various string functions in TP 4.0.
File Name File Size Zip Size Zip Type
IS.PAS 3327 493 deflated
STRINGS.DOC 4818 2125 deflated
STRINGS.PAS 53236 8942 deflated

Download File STRNFST4.ZIP Here

Contents of the STRINGS.DOC file


January 23, 1988


This ARC contains two Turbo Pascal Version 4 (TP4) units,
Strings.Pas and Is.Pas.

STRINGS.PAS

This is a collection of procedures and functions for string
manipulation (although one is not limited to strings), written
in Inline code for speed. The unit contains all routines found
in my earlier Strnfst2 collection, rewritten (where necessary)
for TP4, plus some additional ones. I wrote all but two.
Mitchell Lazarus wrote FlipChar and StripChar.

The routines are briefly documented in the Interface
section. I duplicate here the entries for the routines not
included in Strnfst2:


Function space (N:integer; C:char):string;

{Returns string of length N, consisting of
N instances of C
}

Procedure Blanker(var tline:string);

{if tline consists entirely of blanks, sets
length(tline) to zero. Otherwise, does not
alter tline
}

Function Break (search: string; var tline): byte;


{returns position of first occurence in string tline of
a character in search. If none is found in tline, returns 0
}

Function Break2 (search,tline:string):byte;

{does exactly what Break does, but by a different method.
Which is faster probably depends on relative lengths of
search and tline.
}

Function Span(search,tline:string):byte;

{returns length of initial segment of tline that consists
entirely of characters found in search. Assuming there are
some characters in tline not in search, the first one
is at tline[span(search,tline) +1]
}

Function LastPosC (find: char; var tst): integer;

{returns position in string tst of last instance of find
}

Function WildPosAfter(find:string; var tline ; after:integer):integer;

{Like PosAfter, but with a wildcard. Returns position of first
instance of find in tline, except that ASCII 255 in find matches
any character in tline. Thus 'c'#255't' matches cat, cot,
cut.
}

I don't write ASM well, so many of these routines could be better
written. But they seem to work, and, because they are in Inline,
they are generally much faster than equivalent routines in
straight TPascal.

You could eliminate a lot of these routines without losing any
capabilities, but with some loss in speed and convenience. I
find it convenient to have them all around, but you may not.


IS.PAS

This unit contains a few well-known character classification
"functions" written as Inline directives: IsDigit, IsLower,
IsUpper, IsAlpha, and IsAlNum. (You can reorganize the file as
an include file without affecting much of anything.)

Borland says Inline directives are intended for procedures
and functions of less than ten bytes. These are bigger.
Presumably Borland's reason is that the actual code gets written
into the EXE file, so you can get the same group of bytes written
into the file many times, where a real function would be included
only once, and an additional few bytes to call it each time it is
used. So you pay a price in program size for the speed of Inline
directives. You could save space (and lose speed) by embedding
each of these routines in a function shell, like this:

Function IsAnUpper(c:char):boolean;
begin
IsAnUpper := IsUpper(c);
end;

But this is not an ideal solution. In fact, if you are going
to have actual functions, you would do just about as well (and
sometimes better) by replacing the "is" routines in the functions
by boolean tests. My "is" functions run at about the same speed
as boolean tests.


-----------------------------------------------------------------

You are free to use the code in this ARC file for any
purpose whatsoever. But that code is provided to you without
warranty of any kind. Use it at your own risk.

If you find these procedures and functions useful, or if you
have any comments, suggestions, or complaints, I would appreciate
your letting me know You can write to me at the address given at
the end of this file, or you can leave a message on Robert
Blacher's bulletin board, 547-2008.

These routines exist only because Dave Baldwin wrote, and
freely distributed, his INLINE assembler. If you find them so
useful that you are moved to send an appropriate contribution, I
recommend that you send it to Baldwin, and not to me. I believe
he uses the following two addresses:

22 Fox Den Rd., (Summer) 144 13th St. East, (Winter)
Hollis, NH 03049 Tierra Verde, FL 33715


David Seidman
2737 Devonshire Pl NW
Washington, DC 20008




 December 24, 2017  Add comments

Leave a Reply