Subversion Repositories oidplus

Rev

Rev 744 | Rev 748 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 744 Rev 747
Line 1... Line 1...
1
unit VTSFUNCS;
1
unit VTSFUNCS;
2
 
2
 
3
(************************************************)
3
(************************************************)
4
(* VTSFUNCS.PAS                                 *)
4
(* VTSFUNCS.PAS                                 *)
5
(* Author:   Daniel Marschall                   *)
5
(* Author:   Daniel Marschall                   *)
6
(* Revision: 2022-02-14                         *)
6
(* Revision: 2022-02-16                         *)
7
(* License:  Apache 2.0                         *)
7
(* License:  Apache 2.0                         *)
8
(* This file contains:                          *)
8
(* This file contains:                          *)
9
(* - Various functions                          *)
9
(* - Various functions                          *)
10
(************************************************)
10
(************************************************)
11
 
11
 
Line 27... Line 27...
27
function RepeatStr(ch: char; n: integer): string;
27
function RepeatStr(ch: char; n: integer): string;
28
 
28
 
29
function DeleteFile(filename: string): boolean;
29
function DeleteFile(filename: string): boolean;
30
function FileExists(filename: string): boolean;
30
function FileExists(filename: string): boolean;
31
 
31
 
32
function IsPositiveInteger(s: string): boolean;
32
function IsPositiveIntegerOrZero(s: string): boolean;
33
function StrToInt(s: string): Integer;
33
function StrToInt(s: string): Integer;
34
function IntToStr(Value: Integer): string;
34
function IntToStr(Value: Integer): string;
35
 
35
 
-
 
36
function StringReplace(s, search, replace: string): string;
-
 
37
 
36
implementation
38
implementation
37
 
39
 
38
uses
40
uses
39
  Crt;
41
  Crt;
40
 
42
 
Line 200... Line 202...
200
  begin
202
  begin
201
    FileExists := false;
203
    FileExists := false;
202
  end;
204
  end;
203
end;
205
end;
204
 
206
 
205
function IsPositiveInteger(s: string): boolean;
207
function IsPositiveIntegerOrZero(s: string): boolean;
206
var
208
var
207
  i: integer;
209
  i: integer;
208
begin
210
begin
209
  IsPositiveInteger := false;
211
  IsPositiveIntegerOrZero := false;
210
 
212
 
211
  if Length(s) = 0 then exit;
213
  if Length(s) = 0 then exit;
212
  if (s[1] = '0') and (s <> '0') then exit;
214
  if (s[1] = '0') and (s <> '0') then exit;
213
  for i := 1 to Length(s) do
215
  for i := 1 to Length(s) do
214
  begin
216
  begin
215
    if not (s[i] in ['0'..'9']) then exit;
217
    if not (s[i] in ['0'..'9']) then exit;
216
  end;
218
  end;
217
 
219
 
218
  IsPositiveInteger := true;
220
  IsPositiveIntegerOrZero := true;
219
end;
221
end;
220
 
222
 
221
function StrToInt(s: string): Integer;
223
function StrToInt(s: string): Integer;
222
var
224
var
223
  i, Error: Integer;
225
  i, Error: Integer;
Line 232... Line 234...
232
begin
234
begin
233
  Str(Value, s);
235
  Str(Value, s);
234
  IntToStr := s;
236
  IntToStr := s;
235
end;
237
end;
236
 
238
 
-
 
239
function StringReplace(s, search, replace: string): string;
-
 
240
var
-
 
241
  i: integer;
-
 
242
  output: string;
-
 
243
begin
-
 
244
  if s = '' then exit;
-
 
245
  if search = '' then exit; (* invalid arg *)
-
 
246
 
-
 
247
  output := '';
-
 
248
  while s <> '' do
-
 
249
  begin
-
 
250
    if Copy(s, 1, Length(search)) = search then
-
 
251
    begin
-
 
252
      output := output + replace;
-
 
253
      Delete(s, 1, Length(search));
-
 
254
    end
-
 
255
    else
-
 
256
    begin
-
 
257
      output := output + Copy(s, 1, 1);
-
 
258
      Delete(s, 1, 1);
-
 
259
    end;
-
 
260
  end;
-
 
261
 
-
 
262
  StringReplace := output;
-
 
263
end;
-
 
264
 
237
end.
265
end.