1 |
tony |
1 |
{************************************************************************} |
2 |
|
|
{ } |
3 |
|
|
{ Borland Delphi Visual Component Library } |
4 |
|
|
{ InterBase Express core components } |
5 |
|
|
{ } |
6 |
|
|
{ Copyright (c) 1998-2000 Inprise Corporation } |
7 |
|
|
{ } |
8 |
|
|
{ InterBase Express is based in part on the product } |
9 |
|
|
{ Free IB Components, written by Gregory H. Deatz for } |
10 |
|
|
{ Hoagland, Longo, Moran, Dunst & Doukas Company. } |
11 |
|
|
{ Free IB Components is used under license. } |
12 |
|
|
{ } |
13 |
|
|
{ The contents of this file are subject to the InterBase } |
14 |
|
|
{ Public License Version 1.0 (the "License"); you may not } |
15 |
|
|
{ use this file except in compliance with the License. You } |
16 |
|
|
{ may obtain a copy of the License at http://www.Inprise.com/IPL.html } |
17 |
|
|
{ Software distributed under the License is distributed on } |
18 |
|
|
{ an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either } |
19 |
|
|
{ express or implied. See the License for the specific language } |
20 |
|
|
{ governing rights and limitations under the License. } |
21 |
|
|
{ The Original Code was created by InterBase Software Corporation } |
22 |
|
|
{ and its successors. } |
23 |
|
|
{ Portions created by Inprise Corporation are Copyright (C) Inprise } |
24 |
|
|
{ Corporation. All Rights Reserved. } |
25 |
|
|
{ Contributor(s): Jeff Overcash } |
26 |
|
|
{ } |
27 |
|
|
{************************************************************************} |
28 |
|
|
|
29 |
|
|
unit IBUtils; |
30 |
|
|
|
31 |
|
|
interface |
32 |
|
|
|
33 |
|
|
uses |
34 |
|
|
Windows, Classes, SysUtils; |
35 |
|
|
|
36 |
|
|
const |
37 |
|
|
CRLF = #13 + #10; |
38 |
|
|
CR = #13; |
39 |
|
|
LF = #10; |
40 |
|
|
TAB = #9; |
41 |
|
|
NULL_TERMINATOR = #0; |
42 |
|
|
|
43 |
|
|
function Max(n1, n2: Integer): Integer; |
44 |
|
|
function Min(n1, n2: Integer): Integer; |
45 |
|
|
function RandomString(iLength: Integer): String; |
46 |
|
|
function RandomInteger(iLow, iHigh: Integer): Integer; |
47 |
|
|
function StripString(st: String; CharsToStrip: String): String; |
48 |
|
|
function FormatIdentifier(Dialect: Integer; Value: String): String; |
49 |
|
|
function FormatIdentifierValue(Dialect: Integer; Value: String): String; |
50 |
|
|
function ExtractIdentifier(Dialect: Integer; Value: String): String; |
51 |
|
|
|
52 |
|
|
implementation |
53 |
|
|
|
54 |
|
|
function Max(n1, n2: Integer): Integer; |
55 |
|
|
begin |
56 |
|
|
if (n1 > n2) then |
57 |
|
|
result := n1 |
58 |
|
|
else |
59 |
|
|
result := n2; |
60 |
|
|
end; |
61 |
|
|
|
62 |
|
|
function Min(n1, n2: Integer): Integer; |
63 |
|
|
begin |
64 |
|
|
if (n1 < n2) then |
65 |
|
|
result := n1 |
66 |
|
|
else |
67 |
|
|
result := n2; |
68 |
|
|
end; |
69 |
|
|
|
70 |
|
|
function RandomString(iLength: Integer): String; |
71 |
|
|
begin |
72 |
|
|
result := ''; |
73 |
|
|
while Length(result) < iLength do |
74 |
|
|
result := result + IntToStr(RandomInteger(0, High(Integer))); |
75 |
|
|
if Length(result) > iLength then |
76 |
|
|
result := Copy(result, 1, iLength); |
77 |
|
|
end; |
78 |
|
|
|
79 |
|
|
function RandomInteger(iLow, iHigh: Integer): Integer; |
80 |
|
|
begin |
81 |
|
|
result := Trunc(Random(iHigh - iLow)) + iLow; |
82 |
|
|
end; |
83 |
|
|
|
84 |
|
|
function StripString(st: String; CharsToStrip: String): String; |
85 |
|
|
var |
86 |
|
|
i: Integer; |
87 |
|
|
begin |
88 |
|
|
result := ''; |
89 |
|
|
for i := 1 to Length(st) do begin |
90 |
|
|
if AnsiPos(st[i], CharsToStrip) = 0 then |
91 |
|
|
result := result + st[i]; |
92 |
|
|
end; |
93 |
|
|
end; |
94 |
|
|
|
95 |
|
|
function FormatIdentifier(Dialect: Integer; Value: String): String; |
96 |
|
|
begin |
97 |
|
|
Value := Trim(Value); |
98 |
|
|
if Dialect = 1 then |
99 |
|
|
Value := AnsiUpperCase(Value) |
100 |
|
|
else |
101 |
|
|
if (Value <> '') and (Value[1] = '"') then |
102 |
|
|
Value := '"' + StringReplace (TrimRight(Value), '"', '""', [rfReplaceAll]) + '"' |
103 |
|
|
else |
104 |
|
|
Value := AnsiUpperCase(Value); |
105 |
|
|
Result := Value; |
106 |
|
|
end; |
107 |
|
|
|
108 |
|
|
function FormatIdentifierValue(Dialect: Integer; Value: String): String; |
109 |
|
|
begin |
110 |
|
|
Value := Trim(Value); |
111 |
|
|
if Dialect = 1 then |
112 |
|
|
Value := AnsiUpperCase(Value) |
113 |
|
|
else |
114 |
|
|
begin |
115 |
|
|
if (Value <> '') and (Value[1] = '"') then |
116 |
|
|
begin |
117 |
|
|
Delete(Value, 1, 1); |
118 |
|
|
Delete(Value, Length(Value), 1); |
119 |
|
|
Value := StringReplace (Value, '""', '"', [rfReplaceAll]); |
120 |
|
|
end |
121 |
|
|
else |
122 |
|
|
Value := AnsiUpperCase(Value); |
123 |
|
|
end; |
124 |
|
|
Result := Value; |
125 |
|
|
end; |
126 |
|
|
|
127 |
|
|
function ExtractIdentifier(Dialect: Integer; Value: String): String; |
128 |
|
|
begin |
129 |
|
|
Value := Trim(Value); |
130 |
|
|
if Dialect = 1 then |
131 |
|
|
Value := AnsiUpperCase(Value) |
132 |
|
|
else |
133 |
|
|
begin |
134 |
|
|
if (Value <> '') and (Value[1] = '"') then |
135 |
|
|
begin |
136 |
|
|
Delete(Value, 1, 1); |
137 |
|
|
Delete(Value, Length(Value), 1); |
138 |
|
|
Value := StringReplace (Value, '""', '"', [rfReplaceAll]); |
139 |
|
|
end |
140 |
|
|
else |
141 |
|
|
Value := AnsiUpperCase(Value); |
142 |
|
|
end; |
143 |
|
|
Result := Value; |
144 |
|
|
end; |
145 |
|
|
|
146 |
|
|
end. |