From e8ab3f4e919d31b51a44c1eb0248b2bac1f16e57 Mon Sep 17 00:00:00 2001 From: whiteshark0 Date: Sun, 13 Dec 2009 13:35:42 +0000 Subject: merged trunk r2026 into lua branch git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@2027 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Lua/src/base/USong.pas | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'Lua/src/base/USong.pas') diff --git a/Lua/src/base/USong.pas b/Lua/src/base/USong.pas index c465f198..fccf2757 100644 --- a/Lua/src/base/USong.pas +++ b/Lua/src/base/USong.pas @@ -96,7 +96,7 @@ type function ParseLyricStringParam(const Line: RawByteString; var LinePos: integer): RawByteString; function ParseLyricIntParam(const Line: RawByteString; var LinePos: integer): integer; - function ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): real; + function ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): extended; function ParseLyricCharParam(const Line: RawByteString; var LinePos: integer): AnsiChar; function ParseLyricText(const Line: RawByteString; var LinePos: integer): RawByteString; @@ -346,24 +346,26 @@ var begin OldLinePos := LinePos; Str := ParseLyricStringParam(Line, LinePos); - try - Result := StrToInt(Str); - except // on EConvertError + + if not TryStrToInt(Str, Result) then + begin // on convert error + Result := 0; LinePos := OldLinePos; raise EUSDXParseException.Create('Integer expected'); end; end; -function TSong.ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): real; +function TSong.ParseLyricFloatParam(const Line: RawByteString; var LinePos: integer): extended; var Str: RawByteString; OldLinePos: integer; begin OldLinePos := LinePos; Str := ParseLyricStringParam(Line, LinePos); - try - Result := StrToFloat(Str); - except // on EConvertError + + if not TryStrToFloat(Str, Result) then + begin // on convert error + Result := 0; LinePos := OldLinePos; raise EUSDXParseException.Create('Float expected'); end; @@ -378,6 +380,14 @@ begin Str := ParseLyricStringParam(Line, LinePos); if (Length(Str) <> 1) then begin + { to-do : decide what to do here + usdx < 1.1 does not nead a whitespace after a char param + so we may just write a warning to error.log and use the + first non whitespace character instead of raising an + exception that causes the song not to load. So the more + error resistant code is: + LinePos := OldLinePos + 1; + // raise EUSDXParseException.Create('Character expected'); } LinePos := OldLinePos; raise EUSDXParseException.Create('Character expected'); end; @@ -483,7 +493,7 @@ begin while true do begin - LinePos := 0; + LinePos := 1; Param0 := ParseLyricCharParam(CurLine, LinePos); if (Param0 = 'E') then -- cgit v1.2.3