ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBUtils.pas
Revision: 5
Committed: Fri Feb 18 16:26:16 2011 UTC (13 years, 1 month ago) by tony
Content type: text/x-pascal
File size: 5072 byte(s)
Log Message:
Committing updates for Release pre-release

File Contents

# Content
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 {$Mode Delphi}
32
33 interface
34
35 uses
36 {$IFDEF LINUX }
37 unix,
38 {$ELSE}
39 Windows,
40 {$ENDIF}
41 Classes, SysUtils;
42
43 const
44 CRLF = #13 + #10;
45 CR = #13;
46 LF = #10;
47 TAB = #9;
48 NULL_TERMINATOR = #0;
49
50 function Max(n1, n2: Integer): Integer;
51 function Min(n1, n2: Integer): Integer;
52 function RandomString(iLength: Integer): String;
53 function RandomInteger(iLow, iHigh: Integer): Integer;
54 function StripString(st: String; CharsToStrip: String): String;
55 function FormatIdentifier(Dialect: Integer; Value: String): String;
56 function FormatIdentifierValue(Dialect: Integer; Value: String): String;
57 function ExtractIdentifier(Dialect: Integer; Value: String): String;
58 function QuoteIdentifier(Dialect: Integer; Value: String): String;
59
60 implementation
61
62 function Max(n1, n2: Integer): Integer;
63 begin
64 if (n1 > n2) then
65 result := n1
66 else
67 result := n2;
68 end;
69
70 function Min(n1, n2: Integer): Integer;
71 begin
72 if (n1 < n2) then
73 result := n1
74 else
75 result := n2;
76 end;
77
78 function RandomString(iLength: Integer): String;
79 begin
80 result := '';
81 while Length(result) < iLength do
82 result := result + IntToStr(RandomInteger(0, High(Integer)));
83 if Length(result) > iLength then
84 result := Copy(result, 1, iLength);
85 end;
86
87 function RandomInteger(iLow, iHigh: Integer): Integer;
88 begin
89 result := Trunc(Random(iHigh - iLow)) + iLow;
90 end;
91
92 function StripString(st: String; CharsToStrip: String): String;
93 var
94 i: Integer;
95 begin
96 result := '';
97 for i := 1 to Length(st) do begin
98 if AnsiPos(st[i], CharsToStrip) = 0 then
99 result := result + st[i];
100 end;
101 end;
102
103 function FormatIdentifier(Dialect: Integer; Value: String): String;
104 begin
105 Value := Trim(Value);
106 if Dialect = 1 then
107 Value := AnsiUpperCase(Value)
108 else
109 if (Value <> '') and (Value[1] = '"') then
110 Value := '"' + StringReplace (TrimRight(Value), '"', '""', [rfReplaceAll]) + '"'
111 else
112 Value := AnsiUpperCase(Value);
113 Result := Value;
114 end;
115
116 function FormatIdentifierValue(Dialect: Integer; Value: String): String;
117 begin
118 Value := Trim(Value);
119 if Dialect = 1 then
120 Value := AnsiUpperCase(Value)
121 else
122 begin
123 if (Value <> '') and (Value[1] = '"') then
124 begin
125 Delete(Value, 1, 1);
126 Delete(Value, Length(Value), 1);
127 Value := StringReplace (Value, '""', '"', [rfReplaceAll]);
128 end
129 else
130 Value := AnsiUpperCase(Value);
131 end;
132 Result := Value;
133 end;
134
135 function ExtractIdentifier(Dialect: Integer; Value: String): String;
136 begin
137 Value := Trim(Value);
138 if Dialect = 1 then
139 Value := AnsiUpperCase(Value)
140 else
141 begin
142 if (Value <> '') and (Value[1] = '"') then
143 begin
144 Delete(Value, 1, 1);
145 Delete(Value, Length(Value), 1);
146 Value := StringReplace (Value, '""', '"', [rfReplaceAll]);
147 end
148 else
149 Value := AnsiUpperCase(Value);
150 end;
151 Result := Value;
152 end;
153
154 function QuoteIdentifier(Dialect: Integer; Value: String): String;
155 begin
156 if Dialect = 1 then
157 Value := AnsiUpperCase(Trim(Value))
158 else
159 Value := '"' + Value + '"';
160 Result := Value;
161 end;
162
163 end.