Refactor getWaypointLinesFromFile function in _bot_utility.gsc

This commit refactors the implementation of the getWaypointLinesFromFile function in the _bot_utility.gsc file. The changes include improved handling of newline characters and more efficient processing of lines from the input waypoint string. Additionally, the code now correctly accounts for both '\n' and '\r\n' line endings. These modifications aim to enhance the overall readability and maintainability of the code.
This commit is contained in:
ineed bots 2023-12-06 12:27:46 -06:00
parent f4434277a5
commit 0f6dd0891f

View File

@ -995,24 +995,27 @@ getWaypointLinesFromFile( filename )
if ( !isDefined( waypointStr ) ) if ( !isDefined( waypointStr ) )
return result; return result;
line = ""; linecount = 0;
linestart = 0;
for ( i = 0; i < waypointStr.size; i++ ) for ( i = 0; i < waypointStr.size; i++ )
{ {
c = waypointStr[i]; if ( waypointStr[i] == "\n" || waypointStr[i] == "\r" )
if ( c == "\n" )
{ {
result.lines[result.lines.size] = line; result.lines[result.lines.size] = getSubStr( waypointStr, linestart, linestart + linecount );
line = ""; if ( waypointStr[i] == "\r" && i < waypointStr.size - 1 && waypointStr[i + 1] == "\n" )
i++;
linecount = 0;
linestart = i + 1;
continue; continue;
} }
line += c; linecount++;
} }
result.lines[result.lines.size] = line; result.lines[result.lines.size] = getSubStr( waypointStr, linestart, linestart + linecount );
return result; return result;
} }