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 |
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 |
1502 |
|
GetNext; |
1503 |
|
end |
1504 |
|
else |
1505 |
+ |
if Result = sqltEOL then |
1506 |
+ |
FString := FString + LineEnding |
1507 |
+ |
else |
1508 |
|
FString := FString + C; |
1509 |
|
end; |
1510 |
|
|
1517 |
|
Result := sqltCommentLine; |
1518 |
|
end; |
1519 |
|
|
1507 |
– |
sqltCR: {ignore}; |
1508 |
– |
|
1520 |
|
else |
1521 |
|
FString := FString + C; |
1522 |
|
end; |
1538 |
|
end; |
1539 |
|
end |
1540 |
|
else |
1541 |
+ |
if Result = sqltEOL then |
1542 |
+ |
FString := FString + LineEnding |
1543 |
+ |
else |
1544 |
|
FString := FString + C; |
1545 |
|
end; |
1546 |
|
|
1560 |
|
end; |
1561 |
|
end |
1562 |
|
else |
1563 |
+ |
if Result = sqltEOL then |
1564 |
+ |
FString := FString + LineEnding |
1565 |
+ |
else |
1566 |
|
FString := FString + C; |
1567 |
|
end; |
1568 |
|
|
1643 |
|
sqltNumberString: |
1644 |
|
if FNextToken in [sqltNumberString,sqltPeriod] then |
1645 |
|
FState := stInNumeric; |
1646 |
+ |
|
1647 |
+ |
sqltEOL: |
1648 |
+ |
FString := LineEnding; |
1649 |
|
end; |
1650 |
|
end; |
1651 |
|
end; |
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 S[i] in ['+','-'] then |
1883 |
+ |
begin |
1884 |
+ |
if (i > 1) and not (S[i-1] in ['e','E']) then |
1885 |
+ |
Exit; {malformed} |
1886 |
+ |
end |
1887 |
+ |
else |
1888 |
+ |
if S[i] in ['e','E'] then {scientific notation} |
1889 |
+ |
begin |
1890 |
+ |
if ds <> 0 then Exit; {not permitted in exponent} |
1891 |
+ |
if exponent <> 0 then Exit; {only one allowed} |
1892 |
+ |
exponent := i; |
1893 |
+ |
end |
1894 |
+ |
else |
1895 |
+ |
if not (S[i] in ['0'..'9']) then |
1896 |
+ |
Exit; {bad character} |
1897 |
+ |
end; |
1898 |
+ |
|
1899 |
+ |
if exponent > 0 then |
1900 |
+ |
begin |
1901 |
+ |
Result := TryStrToInt(system.copy(S,exponent+1,maxint),Scale); |
1902 |
+ |
if Result then |
1903 |
+ |
begin |
1904 |
+ |
{adjust scale for decimal point} |
1905 |
+ |
if ds > 0 then |
1906 |
+ |
Scale := Scale - (exponent - ds - 1); |
1907 |
+ |
Result := TryStrToInt64(system.copy(S,1,exponent-1),Value); |
1908 |
+ |
end; |
1909 |
+ |
end |
1910 |
+ |
else |
1911 |
+ |
begin |
1912 |
+ |
if ds <> 0 then |
1913 |
+ |
scale := ds - Length(S); |
1914 |
+ |
Result := TryStrToInt64(S,Value); |
1915 |
+ |
end; |
1916 |
+ |
end; |
1917 |
+ |
end; |
1918 |
+ |
|
1919 |
+ |
function NumericToDouble(aValue: Int64; aScale: integer): double; |
1920 |
+ |
begin |
1921 |
+ |
Result := aValue * IntPower(10,aScale) |
1922 |
+ |
end; |
1923 |
+ |
|
1924 |
|
end. |