home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Vcl / ibutils.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  3KB  |  115 lines

  1. {********************************************************}
  2. {                                                        }
  3. {       Borland Delphi Visual Component Library          }
  4. {       InterBase Express core components                }
  5. {                                                        }
  6. {       Copyright (c) 1998-1999 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. {********************************************************}
  14.  
  15. unit IBUtils;
  16.  
  17. interface
  18.  
  19. uses
  20.   Windows, Classes, SysUtils;
  21.  
  22. const
  23.   CRLF = #13 + #10;
  24.   CR   = #13;
  25.   LF   = #10;
  26.   TAB  = #9;
  27.   NULL_TERMINATOR = #0;
  28.  
  29. function Max(n1, n2: Integer): Integer;
  30. function Min(n1, n2: Integer): Integer;
  31. function RandomString(iLength: Integer): String;
  32. function RandomInteger(iLow, iHigh: Integer): Integer;
  33. function StripString(st: String; CharsToStrip: String): String;
  34. function FormatIdentifier(Dialect: Integer; Value: String): String;
  35. function FormatIdentifierValue(Dialect: Integer; Value: String): String;
  36. function ExtractIdentifier(Dialect: Integer; Value: String): String;
  37.  
  38. implementation
  39.  
  40. function Max(n1, n2: Integer): Integer;
  41. begin
  42.   if (n1 > n2) then
  43.     result := n1
  44.   else
  45.     result := n2;
  46. end;
  47.  
  48. function Min(n1, n2: Integer): Integer;
  49. begin
  50.   if (n1 < n2) then
  51.     result := n1
  52.   else
  53.     result := n2;
  54. end;
  55.  
  56. function RandomString(iLength: Integer): String;
  57. begin
  58.   result := '';
  59.   while Length(result) < iLength do
  60.     result := result + IntToStr(RandomInteger(0, High(Integer)));
  61.   if Length(result) > iLength then
  62.     result := Copy(result, 1, iLength);
  63. end;
  64.  
  65. function RandomInteger(iLow, iHigh: Integer): Integer;
  66. begin
  67.   result := Trunc(Random(iHigh - iLow)) + iLow;
  68. end;
  69.  
  70. function StripString(st: String; CharsToStrip: String): String;
  71. var
  72.   i: Integer;
  73. begin
  74.   result := '';
  75.   for i := 1 to Length(st) do begin
  76.     if AnsiPos(st[i], CharsToStrip) = 0 then
  77.       result := result + st[i];
  78.   end;
  79. end;
  80.  
  81. function FormatIdentifier(Dialect: Integer; Value: String): String;
  82. begin
  83.   if Dialect = 1 then
  84.     Value := AnsiUpperCase(Trim(Value))
  85.   else
  86.     Value := '"' + StringReplace (TrimRight(Value), '"', '""', [rfReplaceAll]) + '"';
  87.   Result := Value;
  88. end;
  89.  
  90. function FormatIdentifierValue(Dialect: Integer; Value: String): String;
  91. begin
  92.   if Dialect = 1 then
  93.     Result := AnsiUpperCase(Trim(Value))
  94.   else
  95.     Result := Value;
  96. end;
  97.  
  98. function ExtractIdentifier(Dialect: Integer; Value: String): String;
  99. begin
  100.   if Dialect = 1 then
  101.     Value := AnsiUpperCase(Trim(Value))
  102.   else begin
  103.     Value := TrimRight(Value);
  104.     if (Value <> '') and (Value[1] = '"') then
  105.     begin
  106.       Delete(Value, 1, 1);
  107.       Delete(Value, Length(Value), 1);
  108.       Value := StringReplace (Value, '""', '"', [rfReplaceAll]);
  109.     end;
  110.   end;
  111.   Result := Value;
  112. end;
  113.  
  114. end.
  115.