Rev 748 | Rev 750 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 748 | Rev 749 | ||
---|---|---|---|
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-19 *) |
6 | (* Revision: 2022-02-20 *) |
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 StripLeadingZeros(s: string): string; |
|
32 | function IsPositiveIntegerOrZero(s: string): boolean; |
33 | function IsPositiveIntegerOrZero(s: string): boolean; |
- | 34 | function IsBase36String(s: string): boolean; |
|
33 | function StrToInt(s: string): Integer; |
35 | function StrToInt(s: string): Integer; |
34 | function IntToStr(Value: Integer): string; |
36 | function IntToStr(Value: Integer): string; |
35 | 37 | ||
36 | function StringReplace(s, search, replace: string): string; |
38 | function StringReplace(s, search, replace: string): string; |
37 | 39 | ||
Line 206... | Line 208... | ||
206 | begin |
208 | begin |
207 | FileExists := false; |
209 | FileExists := false; |
208 | end; |
210 | end; |
209 | end; |
211 | end; |
210 | 212 | ||
- | 213 | function StripLeadingZeros(s: string): string; |
|
- | 214 | begin |
|
- | 215 | while (s <> '0') and (Copy(s,1,1) = '0') do |
|
- | 216 | Delete(s,1,1); |
|
- | 217 | ||
- | 218 | StripLeadingZeros := s; |
|
- | 219 | end; |
|
- | 220 | ||
211 | function IsPositiveIntegerOrZero(s: string): boolean; |
221 | function IsPositiveIntegerOrZero(s: string): boolean; |
212 | var |
222 | var |
213 | i: integer; |
223 | i: integer; |
214 | begin |
224 | begin |
215 | IsPositiveIntegerOrZero := false; |
225 | IsPositiveIntegerOrZero := false; |
216 | 226 | ||
217 | if Length(s) = 0 then exit; |
227 | if Length(s) = 0 then exit; |
218 | if (s[1] = '0') and (s <> '0') then exit; |
228 | (*if (s[1] = '0') and (s <> '0') then exit;*) |
219 | for i := 1 to Length(s) do |
229 | for i := 1 to Length(s) do |
220 | begin |
230 | begin |
221 | if not (s[i] in ['0'..'9']) then exit; |
231 | if not (s[i] in ['0'..'9']) then exit; |
222 | end; |
232 | end; |
223 | 233 | ||
224 | IsPositiveIntegerOrZero := true; |
234 | IsPositiveIntegerOrZero := true; |
225 | end; |
235 | end; |
226 | 236 | ||
- | 237 | function IsBase36String(s: string): boolean; |
|
- | 238 | var |
|
- | 239 | i: integer; |
|
- | 240 | begin |
|
- | 241 | IsBase36String := false; |
|
- | 242 | ||
- | 243 | if Length(s) = 0 then exit; |
|
- | 244 | (*if (s[1] = '0') and (s <> '0') then exit;*) |
|
- | 245 | for i := 1 to Length(s) do |
|
- | 246 | begin |
|
- | 247 | if not (s[i] in ['0'..'9', 'A'..'Z']) then exit; |
|
- | 248 | end; |
|
- | 249 | ||
- | 250 | IsBase36String := true; |
|
- | 251 | end; |
|
- | 252 | ||
227 | function StrToInt(s: string): Integer; |
253 | function StrToInt(s: string): Integer; |
228 | var |
254 | var |
229 | i, Error: Integer; |
255 | i, Error: Integer; |
230 | begin |
256 | begin |
231 | Val(s, i, Error); |
257 | Val(s, i, Error); |
Line 364... | Line 390... | ||
364 | number[newlen+1] := #0; |
390 | number[newlen+1] := #0; |
365 | Inc(newlen); |
391 | Inc(newlen); |
366 | end; |
392 | end; |
367 | end; |
393 | end; |
368 | len := newlen; |
394 | len := newlen; |
369 | res := tobase_str[divide+1] + res; (* Divide is basically $numstring % $tobase (i.e. the new character) *) |
395 | res := tobase_str[divide+1] + res; (* Divide is basically "numstring mod tobase" (i.e. the new character) *) |
370 | until newlen = 0; |
396 | until newlen = 0; |
371 | base_convert_bigint := res; |
397 | base_convert_bigint := res; |
372 | end; |
398 | end; |
373 | 399 | ||
374 | end. |
400 | end. |