summary refs log tree commit diff stats
path: root/nim/strutils.pas
diff options
context:
space:
mode:
Diffstat (limited to 'nim/strutils.pas')
-rw-r--r--nim/strutils.pas32
1 files changed, 19 insertions, 13 deletions
diff --git a/nim/strutils.pas b/nim/strutils.pas
index 71a428dbb..cd07105be 100644
--- a/nim/strutils.pas
+++ b/nim/strutils.pas
@@ -28,6 +28,7 @@ function cmp(const x, y: string): int;
 function cmpIgnoreCase(const x, y: string): int;
 
 function format(const f: string; const args: array of string): string;
+procedure addf(var result: string; const f: string; args: array of string);
 
 function toHex(x: BiggestInt; len: int): string;
 function toOctal(value: Char): string;
@@ -47,7 +48,7 @@ function ToString(b: Boolean): string; overload;
 
 function IntToStr(i: BiggestInt; minChars: int): string;
 
-function findSubStr(const sub, s: string; start: int = 1): int;
+function find(const s, sub: string; start: int = 1): int; overload;
 function replaceStr(const s, search, by: string): string;
 procedure deleteStr(var s: string; first, last: int);
 
@@ -81,8 +82,8 @@ implementation
 
 function quoteIfContainsWhite(const s: string): string;
 begin
-  if ((findSubStr(' ', s) >= strStart)
-  or (findSubStr(#9, s) >= strStart)) and (s[strStart] <> '"') then
+  if ((find(s, ' ') >= strStart)
+  or (find(s, #9) >= strStart)) and (s[strStart] <> '"') then
     result := '"' +{&} s +{&} '"'
   else
     result := s
@@ -247,7 +248,7 @@ begin
       result := result + s[i]
 end;
 
-function findSubStr(const sub, s: string; start: int = 1): int;
+function find(const s, sub: string; start: int = 1): int;
 var
   i, j, M, N: int;
 begin
@@ -277,7 +278,7 @@ begin
   result := '';
   i := 1;
   repeat
-    j := findSubStr(search, s, i);
+    j := find(s, search, i);
     if j = 0 then begin
       // copy the rest:
       result := result + copy(s, i, length(s) - i + 1);
@@ -475,7 +476,7 @@ begin
   until false
 end;
 
-function find(const x: string; const inArray: array of string): int;
+function find(const x: string; const inArray: array of string): int; overload;
 var
   i: int;
   y: string;
@@ -491,30 +492,29 @@ begin
   result := -1
 end;
 
-function format(const f: string; const args: array of string): string;
+procedure addf(var result: string; const f: string; args: array of string);
 const
   PatternChars = ['a'..'z', 'A'..'Z', '0'..'9', '_', #128..#255];
 var
   i, j, x: int;
 begin
-  result := '';
   i := 1;
   while i <= length(f) do
     if f[i] = '$' then begin
       case f[i+1] of
         '$': begin
-          result := result + '$';
+          addChar(result, '$');
           inc(i, 2);
         end;
         '1'..'9': begin
-          result := result + args[ord(f[i+1]) - ord('0') - 1];
+          add(result, args[ord(f[i+1]) - ord('0') - 1]);
           inc(i, 2);
         end;
         '{': begin
           j := i+1;
           while (j <= length(f)) and (f[j] <> '}') do inc(j);
           x := find(ncopy(f, i+2, j-1), args);
-          if (x >= 0) and (x < high(args)) then result := result + args[x+1]
+          if (x >= 0) and (x < high(args)) then add(result, args[x+1])
           else raise EInvalidFormatStr.create('');
           i := j+1
         end;
@@ -522,7 +522,7 @@ begin
           j := i+1;
           while (j <= length(f)) and (f[j] in PatternChars) do inc(j);
           x := find(ncopy(f, i+1, j-1), args);
-          if (x >= 0) and (x < high(args)) then result := result + args[x+1]
+          if (x >= 0) and (x < high(args)) then add(result, args[x+1])
           else raise EInvalidFormatStr.create(ncopy(f, i+1, j-1));
           i := j
         end
@@ -530,11 +530,17 @@ begin
       end
     end
     else begin
-      result := result + f[i];
+      addChar(result, f[i]);
       inc(i)
     end
 end;
 
+function format(const f: string; const args: array of string): string;
+begin
+  result := '';
+  addf(result, f, args)
+end;
+
 {@ignore}
 {$ifopt Q-} {$Q+}
 {$else}     {$define Q_off}
a8f9cf2c ^
e7f81766 ^





















ae57e587 ^



e7f81766 ^
a8f9cf2c ^

e7f81766 ^













865ae865 ^













3fdfc107 ^
e7f81766 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161