From 5b0d47dddb4d48abf0c9b6dfbed4f70718fcdf7c Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Fri, 30 May 2008 07:38:45 +0000 Subject: thanks krtaylor for a Patch to cleanup some incorrect parsing, boundry conditions and error checking in the llGetNotecardLine and llGetNumberOfNotecardLines functions. --- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 9a2d240..33aa905 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -3827,7 +3827,11 @@ namespace OpenSim.Region.ScriptEngine.Common // once it is implemented - krtaylor String[] notecardLines = GetNotecardLines(name); - if (!String.IsNullOrEmpty(notecardLines[0])) + + line--; // array starts at 0 + if ((!String.IsNullOrEmpty(notecardLines[0])) && + (line >= 0) && + (line < notecardLines.Length)) { return notecardLines[line]; } @@ -3858,7 +3862,7 @@ namespace OpenSim.Region.ScriptEngine.Common { // good, we have the notecard data as a string // now parse the text lines using the Linden Text delimiters - notecardIndex = dataString.IndexOf("}\n"); + notecardIndex = dataString.IndexOf("}\nText length "); if (notecardIndex > 0) { notecardIndex = notecardIndex + 2; //get past delimiter @@ -3867,23 +3871,20 @@ namespace OpenSim.Region.ScriptEngine.Common { // Finally got to the first line of the notecard // now find the end of the notecard text delimited by } - // parse the lines, delimited by - char[] delimChar = { '\n' }; - int notecardEof = dataString.IndexOf("}\n", notecardIndex); - if (notecardEof > 0) - { - int notecardLength = notecardEof - notecardIndex - 1; - notecardIndex = dataString.IndexOf("\n", notecardIndex); - notecardIndex++; // get past delimiter + // parse the lines, delimited by + notecardIndex = dataString.IndexOf("\n", notecardIndex); + notecardIndex++; // get past delimiter - // create new string to parse that only consists of the actual lines in the asset - Char[] notecardCharArray = dataString.ToCharArray(notecardIndex, notecardLength); - String notecardString = new String(notecardCharArray); + int notecardLength = dataString.Length - notecardIndex - 3; - // split the lines of the notecard into separate strings - notecardLines = notecardString.Split(delimChar); - return notecardLines; - } + // create new string to parse that only consists of the actual lines in the asset + Char[] notecardCharArray = dataString.ToCharArray(notecardIndex, notecardLength); + String notecardString = new String(notecardCharArray); + + // split the lines of the notecard into separate strings + char[] delimChar = { '\n' }; + notecardLines = notecardString.Split(delimChar); + return notecardLines; } } } -- cgit v1.1