File: dbf\format_string.adb
1 --::::::::::
2 --formstri.adb
3 --::::::::::
4 -- Developed by (C) Wasiliy W. Molostoff 1994, 1995.
5 -- Moscow, Russia,
6 -- Voice: 7 (095) 398-23-38
7 -- e-mail: edv@edv.msk.ru
8 -- This is free software; you can freely redistribute it and/or
9 -- modify it without any restrictions. Please report any errors.
10 -- All corrections will be made as soon as possible.
11 function format_string (fmt: string) return string is
12 arg: natural;
13 separator: constant character := '%';
14 begin
15 if fmt'length > 1
16 then
17 if fmt (fmt'first) /= separator
18 then
19 for n in fmt'first + 1 .. fmt'last
20 loop
21 if fmt (n) = separator
22 then
23 return fmt (fmt'first..n - 1) &
24 format_string ( fmt (n..fmt'last));
25 end if;
26 end loop;
27 else
28 arg := 0;
29 for n in fmt'first + 1 .. fmt'last
30 loop -- read arg
31 if fmt (n) in '0'..'9'
32 then
33 arg := 10 * arg + character'pos (fmt (n))
34 - character'pos ('0');
35 else
36 return argument (arg) & format_string (fmt (n..fmt'last));
37 end if;
38 end loop;
39 return argument (arg);
40 end if;
41 end if;
42 return fmt;
43 end;
44