unit StringChecker;
interface
function StringPartEnd (
const Str :
string;
const Start : Integer) : Integer;
function StringPartStart (
const Str :
string;
const Start : Integer) : Integer;
function CopyWord(Text:
String; Position: integer) :
String;
implementation
uses unit1, SysUtils;
function CheckStartInRange (
const Str :
string;
const Start : Integer) : Integer;
begin
if (Start < 1)
or (Length (Str) < Start)
then
Result := 0
else
Result := Start
end;
function IsWhitespace (
const Str :
string;
const Start : Integer) : Boolean;
begin
Result := CharInSet (Str [Start], [#9, #10, #13, #32])
end;
function StringPartStart (
const Str :
string;
const Start : Integer) : Integer;
begin
Result := CheckStartInRange (Str, Start);
if Result = 0
then
Exit;
if IsWhitespace (Str, Result)
then
Exit;
while (Result > 1)
and (Str [Result - 1] <> '
')
do
Dec (Result)
end;
function StringPartEnd (
const Str :
string;
const Start : Integer) : Integer;
var
l : Integer;
begin
Result := CheckStartInRange (Str, Start);
if Result = 0
then
Exit;
if IsWhitespace (Str, Result)
then
Exit;
l := Length (Str);
while (Result < l)
and (Str [Result + 1] <> '
')
do
Inc (Result)
end;
function CopyWord(Text:
String; Position: integer) :
String;
var
i, j: integer;
begin
i := StringPartStart (Text, Position);
j := StringPartEnd (Text, Position);
Result := Copy (Text, i, j - i + 1);
end;
end.