private static string MakeStructFieldsPublic( string _Source )
{
int CurrentPosition = 0;
while ( true )
{
int StructIndex = _Source.IndexOf( "struct", CurrentPosition, StringComparison.InvariantCultureIgnoreCase );
if ( StructIndex == -1 )
break;
int StructBeginIndex = _Source.IndexOf( "{", StructIndex, StringComparison.InvariantCultureIgnoreCase );
if ( StructBeginIndex == -1 )
throw new ConverterException( "Failed to retrieve opening { for struct!", _Source, StructIndex );
int StructEndIndex = _Source.IndexOf( "}", StructBeginIndex, StringComparison.InvariantCultureIgnoreCase );
if ( StructEndIndex == -1 )
throw new ConverterException( "Failed to retrieve closing } for struct!", _Source, StructIndex );
CurrentPosition = FindEOL( _Source, StructBeginIndex );
if ( CurrentPosition == -1 )
throw new ConverterException( "Failed to retrieve end of line after struct { !", _Source, StructIndex );
CurrentPosition++; // Start at new line
while ( CurrentPosition < StructEndIndex )
{
int EOLIndex = FindEOL( _Source, CurrentPosition );
// Retrieve and check for valid field
int FieldIndex = CurrentPosition;
string Field = _Source.Substring( FieldIndex, EOLIndex - FieldIndex );
Field = Field.Trim();
int SemicolonIndex = Field.IndexOf( ";" );
SemicolonIndex = SemicolonIndex == -1 ? Field.Length : SemicolonIndex;
bool IsCommented = IsCommentedLine( Field, SemicolonIndex ); // The line is commented if we find a // before any ; terminator
if ( Field == "" || IsCommented )
{ // This line is either empty or is a comment...
CurrentPosition = EOLIndex+1;
continue;
}
// Insert the public keyword at the beginning of this field declaration
_Source = _Source.Insert( CurrentPosition, "public " );
// Go to next line...
CurrentPosition = FindEOL( _Source, CurrentPosition );
if ( CurrentPosition == -1 )
throw new ConverterException( "Failed to retrieve end of line after struct field \"" + Field + "\"!", _Source, FieldIndex, EOLIndex );
CurrentPosition++; // Start at new line
// Update position of end of structure
StructEndIndex = _Source.IndexOf( "}", StructBeginIndex, StringComparison.InvariantCultureIgnoreCase );
}
}
return _Source;
}