| 1 |
{ |
| 2 |
Copyright 2008-2018 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{$ifdef read_interface} |
| 17 |
|
| 18 |
type |
| 19 |
{ Parse a sequence of integeres inside a string inside an XML element. } |
| 20 |
TIntegersParser = class |
| 21 |
strict private |
| 22 |
Content: string; |
| 23 |
FCurrent: Int64; |
| 24 |
SeekPos: Integer; |
| 25 |
Ended: boolean; |
| 26 |
public |
| 27 |
constructor Create(const PElement: TDOMElement); |
| 28 |
function GetNext: boolean; |
| 29 |
property Current: Int64 read FCurrent; |
| 30 |
end; |
| 31 |
|
| 32 |
{$endif read_interface} |
| 33 |
|
| 34 |
{$ifdef read_implementation} |
| 35 |
|
| 36 |
constructor TIntegersParser.Create(const PElement: TDOMElement); |
| 37 |
begin |
| 38 |
inherited Create; |
| 39 |
Content := PElement.TextData; |
| 40 |
SeekPos := 1; |
| 41 |
end; |
| 42 |
|
| 43 |
function TIntegersParser.GetNext: boolean; |
| 44 |
var |
| 45 |
Token: string; |
| 46 |
begin |
| 47 |
if Ended then Exit(false); |
| 48 |
|
| 49 |
Token := NextToken(Content, SeekPos); |
| 50 |
if Token = '' then |
| 51 |
begin |
| 52 |
Ended := true; |
| 53 |
Result := false; |
| 54 |
end else |
| 55 |
try |
| 56 |
FCurrent := StrToInt(Token); |
| 57 |
Result := true; |
| 58 |
except |
| 59 |
on E: EConvertError do |
| 60 |
begin |
| 61 |
WritelnWarning('Collada', 'Invalid integer: ' + E.Message); |
| 62 |
Ended := true; { don't read further } |
| 63 |
Result := false; |
| 64 |
end; |
| 65 |
end; |
| 66 |
end; |
| 67 |
|
| 68 |
{$endif read_implementation} |