ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/IBUtils.pas
(Generate patch)

Comparing ibx/trunk/fbintf/IBUtils.pas (file contents):
Revision 348 by tony, Wed Oct 6 09:38:14 2021 UTC vs.
Revision 353 by tony, Sat Oct 23 14:11:37 2021 UTC

# Line 648 | Line 648 | function FBFormatDateTime(fmt: AnsiStrin
648   function FormatTimeZoneOffset(EffectiveTimeOffsetMins: integer): AnsiString;
649   function DecodeTimeZoneOffset(TZOffset: AnsiString; var dstOffset: integer): boolean;
650   function StripLeadingZeros(Value: AnsiString): AnsiString;
651 + function TryStrToNumeric(S: Ansistring; out Value: int64; out scale: integer): boolean;
652 + function NumericToDouble(aValue: Int64; aScale: integer): double;
653 +
654  
655   implementation
656  
657 < uses FBMessages
657 > uses FBMessages, Math
658  
659   {$IFDEF FPC}
660   ,RegExpr
# Line 1472 | Line 1475 | begin
1475      GetNext;
1476  
1477    repeat
1478 +    if FSkipNext then
1479 +    begin
1480 +      FSkipNext := false;
1481 +      GetNext;
1482 +    end;
1483 +
1484      Result := FNextToken;
1485      C := FLastChar;
1486      GetNext;
1487  
1488 <    if FSkipNext then
1488 >    if (Result = sqltCR) and (FNextToken = sqltEOL) then
1489      begin
1490 <      FSkipNext := false;
1491 <      continue;
1490 >      FSkipNext := true;
1491 >      Result := sqltEOL;
1492 >      C := LF;
1493      end;
1494  
1495      case FState of
# Line 1492 | Line 1502 | begin
1502            GetNext;
1503          end
1504          else
1505 +        if Result = sqltEOL then
1506 +          FString := FString + LineEnding
1507 +        else
1508            FString := FString + C;
1509        end;
1510  
# Line 1504 | Line 1517 | begin
1517              Result := sqltCommentLine;
1518            end;
1519  
1507        sqltCR: {ignore};
1508
1520          else
1521            FString := FString + C;
1522          end;
# Line 1527 | Line 1538 | begin
1538            end;
1539          end
1540          else
1541 +        if Result = sqltEOL then
1542 +          FString := FString + LineEnding
1543 +        else
1544            FString := FString + C;
1545        end;
1546  
# Line 1546 | Line 1560 | begin
1560            end;
1561          end
1562          else
1563 +        if Result = sqltEOL then
1564 +          FString := FString + LineEnding
1565 +        else
1566            FString := FString + C;
1567        end;
1568  
# Line 1626 | Line 1643 | begin
1643          sqltNumberString:
1644            if FNextToken in [sqltNumberString,sqltPeriod] then
1645              FState := stInNumeric;
1646 +
1647 +        sqltEOL:
1648 +          FString := LineEnding;
1649          end;
1650        end;
1651      end;
# Line 1823 | Line 1843 | begin
1843      end;
1844   end;
1845  
1846 + function TryStrToNumeric(S: Ansistring; out Value: int64; out scale: integer): boolean;
1847 + var i: integer;
1848 +    ds: integer;
1849 +    exponent: integer;
1850 + begin
1851 +  Result := false;
1852 +  ds := 0;
1853 +  exponent := 0;
1854 +  S := Trim(S);
1855 +  Value := 0;
1856 +  scale := 0;
1857 +  if Length(S) = 0 then
1858 +    Exit;
1859 +  {$IF declared(DefaultFormatSettings)}
1860 +  with DefaultFormatSettings do
1861 +  {$ELSE}
1862 +  {$IF declared(FormatSettings)}
1863 +  with FormatSettings do
1864 +  {$IFEND}
1865 +  {$IFEND}
1866 +  begin
1867 +    {ThousandSeparator not allowed as by Delphi specs}
1868 +    if (ThousandSeparator <> DecimalSeparator) and
1869 +       (Pos(ThousandSeparator, S) <> 0) then
1870 +        Exit;
1871 +
1872 +    for i := length(S) downto 1 do
1873 +    begin
1874 +      if S[i] = AnsiChar(DecimalSeparator) then
1875 +      begin
1876 +          if ds <> 0 then Exit; {only one allowed}
1877 +          ds := i-1;
1878 +          dec(exponent);
1879 +          system.Delete(S,i,1);
1880 +      end
1881 +      else
1882 +      if (i > 1) and (S[i] in ['+','-']) and not (S[i-1] in ['e','E']) then
1883 +          Exit {malformed}
1884 +      else
1885 +      if S[i] in ['e','E'] then {scientific notation}
1886 +      begin
1887 +        if ds <> 0 then Exit; {not permitted in exponent}
1888 +        if exponent <> 0 then Exit; {only one allowed}
1889 +        exponent := i;
1890 +      end
1891 +      else
1892 +      if not (S[i] in ['0'..'9']) then
1893 +          Exit; {bad character}
1894 +    end;
1895 +
1896 +    if exponent > 0 then
1897 +    begin
1898 +      Result := TryStrToInt(system.copy(S,exponent+1,maxint),Scale);
1899 +      if Result then
1900 +      begin
1901 +        {adjust scale for decimal point}
1902 +        Scale := Scale - (exponent - ds - 1);
1903 +        Result := TryStrToInt64(system.copy(S,1,exponent-1),Value);
1904 +      end;
1905 +    end
1906 +    else
1907 +    begin
1908 +      if ds <> 0 then
1909 +        scale := ds - Length(S);
1910 +      Result := TryStrToInt64(S,Value);
1911 +    end;
1912 +  end;
1913 + end;
1914 +
1915 + function NumericToDouble(aValue: Int64; aScale: integer): double;
1916 + begin
1917 +  Result := aValue * IntPower(10,aScale)
1918 + end;
1919 +
1920   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines