Recurity.Swf.AVM1Modifier.Modification.PrepareAndReplaceLabel C# (CSharp) Method

PrepareAndReplaceLabel() private method

TODO : Documentation
private PrepareAndReplaceLabel ( string statement, string &actionName ) : string
statement string
actionName string
return string
        private string PrepareAndReplaceLabel( string statement, out string actionName )
        {
            actionName = null;

            char[] delims = { ' ', '\t' };
            string[] token = statement.Split( delims, StringSplitOptions.RemoveEmptyEntries );

            if ( 0 == token.Length )
                return null;

            actionName = token[ 0 ];

            for ( int i = 0; i < token.Length; i++ )
            {
                //
                // replace Label in statement (token ending in ':') with
                // index of instruction referenced. Index is resolved in Populate().
                //
                if ( token[ i ].EndsWith( ":" ) )
                {
                    //
                    // find label
                    //
                    for ( int j = 0; j < _InnerCode.Count; j++ )
                    {
                        if ( null != _InnerCode[ j ].Label )
                        {
                            if ( _InnerCode[ j ].Label.Equals( token[ i ], StringComparison.InvariantCulture ) )
                            {
                                token[ i ] = j.ToString( "d" );
                            }
                        }
                    }
                }

                //
                // replace variables
                //
                if ( token[ i ].Contains( "$" ) )
                {
                    Match m = Regex.Match( token[i], @"(\$[A-Z]+)" );
                    if ( m.Success )
                    {
                        string vName = m.Value;
                        bool replacementDone = false;

                        for ( int j = 0; j < _Variables.Count; j++ )
                        {
                            if ( vName.Equals( _Variables[ j ].Name, StringComparison.InvariantCulture ) )
                            {
                                token[ i ] = token[ i ].Replace( vName, _Variables[ j ].Value );
                                replacementDone = true;
                                break;
                            }
                        }

                        if ( !replacementDone )
                        {
                            AVM1ExceptionSourceFormat e = new AVM1ExceptionSourceFormat( "Variable " + vName + " not found" );
                            throw e;
                        }
                    }
                }
            }

            return String.Join( " ", token );
        }