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 |
1252 |
|
stInBlock: |
1253 |
|
begin |
1254 |
|
case token of |
1255 |
< |
sqltBegin: |
1255 |
> |
sqltBegin, |
1256 |
> |
sqltCase: |
1257 |
|
Inc(FNested); |
1258 |
|
|
1259 |
|
sqltEnd: |
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 |
|
|
1506 |
– |
sqltCR: {ignore}; |
1507 |
– |
|
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 |
+ |
for i := length(S) downto 1 do |
1868 |
+ |
begin |
1869 |
+ |
if S[i] = AnsiChar(DecimalSeparator) then |
1870 |
+ |
begin |
1871 |
+ |
if ds <> 0 then Exit; {only one allowed} |
1872 |
+ |
ds := i; |
1873 |
+ |
dec(exponent); |
1874 |
+ |
system.Delete(S,i,1); |
1875 |
+ |
end |
1876 |
+ |
else |
1877 |
+ |
if S[i] in ['+','-'] then |
1878 |
+ |
begin |
1879 |
+ |
if (i > 1) and not (S[i-1] in ['e','E']) then |
1880 |
+ |
Exit; {malformed} |
1881 |
+ |
end |
1882 |
+ |
else |
1883 |
+ |
if S[i] in ['e','E'] then {scientific notation} |
1884 |
+ |
begin |
1885 |
+ |
if ds <> 0 then Exit; {not permitted in exponent} |
1886 |
+ |
if exponent <> 0 then Exit; {only one allowed} |
1887 |
+ |
exponent := i; |
1888 |
+ |
end |
1889 |
+ |
else |
1890 |
+ |
if not (S[i] in ['0'..'9']) then |
1891 |
+ |
{Note: ThousandSeparator not allowed by Delphi specs} |
1892 |
+ |
Exit; {bad character} |
1893 |
+ |
end; |
1894 |
+ |
|
1895 |
+ |
if exponent > 0 then |
1896 |
+ |
begin |
1897 |
+ |
Result := TryStrToInt(system.copy(S,exponent+1,maxint),Scale); |
1898 |
+ |
if Result then |
1899 |
+ |
begin |
1900 |
+ |
{adjust scale for decimal point} |
1901 |
+ |
if ds <> 0 then |
1902 |
+ |
Scale := Scale - (exponent - ds); |
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) - 1; |
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. |