private static string ConvertRegisters( string _Source )
{
int CurrentPosition = 0;
int MatchIndex = 0;
while ( true )
{
MatchIndex = _Source.IndexOf( ": register", CurrentPosition, StringComparison.InvariantCultureIgnoreCase );
if ( MatchIndex == -1 )
MatchIndex = _Source.IndexOf( ":register", CurrentPosition, StringComparison.InvariantCultureIgnoreCase );
if ( MatchIndex == -1 )
break;
int BOLIndex = FindBOL( _Source, MatchIndex );
int EOLIndex = FindEOL( _Source, MatchIndex );
if ( IsCommentedLine( _Source, MatchIndex ) )
{ // Skip this line if it's a comment
CurrentPosition = MatchIndex+1;
continue;
}
// Find beginning of register specification
int RegisterStart = IndexOfBetween( _Source, "register", MatchIndex, EOLIndex );
RegisterStart += "register".Length;
RegisterStart = IndexOfBetween( _Source, "(", RegisterStart, EOLIndex );
if ( RegisterStart == -1 )
throw new ConverterException( "Failed to retrieve opening parenthesis for register specification!", _Source, MatchIndex, EOLIndex );
// Find end of register specification
int RegisterEnd = IndexOfBetween( _Source, ")", RegisterStart, EOLIndex );
if ( RegisterStart == -1 )
throw new ConverterException( "Failed to retrieve closing parenthesis for register specification!", _Source, MatchIndex, EOLIndex );
// Retrieve register spec
string Register = _Source.Substring( RegisterStart+1, RegisterEnd-RegisterStart-1 );
Register = Register.Trim();
// Remove unsupported syntax
_Source = _Source.Remove( MatchIndex, RegisterEnd+1-MatchIndex );
// Replace by inserting a register attribute
string RegisterAttrib = "[Register( \"" + Register + "\" )]\n";
_Source = _Source.Insert( BOLIndex, RegisterAttrib );
// New position for starting our search...
CurrentPosition = MatchIndex;
}
return _Source;
}