Code improvement

Nov 12, 2010 at 4:04 PM

At present state the program cannot process such pieces of of Javascipt as

namespace1.prototype.sname = function(properties) {

...

}

and inside of prototype:

set_id: function(value) {
        this._id = value;
    },

To fix this function IsFunctionNameExist should be fixed as:

 private bool IsFunctionNameExist(string lineString)
        {
            lineString=lineString.ToLower().Trim();
            bool FunctionIsFound = false;
            int startIndex = 0;
            while (!FunctionIsFound)
            {
                startIndex = lineString.IndexOf("function", startIndex);
                if (startIndex == -1)
                    break;
                if (startIndex == 0)
                {
                    FunctionIsFound = true;
                    break;
                }
                string prev_symbol = lineString.Substring(startIndex - 1, 1);
                if (prev_symbol == "=" || prev_symbol == ":" || prev_symbol == " ")
                {
                    FunctionIsFound = true;
                    break;
                }
                else
                    startIndex += 8;
            }
            return FunctionIsFound;
           
           
        }

and in function FindJScriptFunction block    if (indOpenRoundBracket >= 0)

 

 

should be replaced by

 if (indOpenRoundBracket >= 0)
            {
                ///if function name is defined then this name is found between
                /// space after "function" word and left open bracket:
                if (indOpenRoundBracket - (IndexOfFunctionWordFounded + 9) > 0)
                {
                    FunctionName = line.Substring(IndexOfFunctionWordFounded + 9,
                                   indOpenRoundBracket - (IndexOfFunctionWordFounded + 9));
                    FunctionName = FunctionName.Trim();
                }
                else
                {
                    ///search index of "="
                    int EqualSymbolIndex = line.IndexOf("=");

                    if (EqualSymbolIndex > 0)
                    {
                        ///get a string before "=" as a funcion name
                        FunctionName = line.Substring(0, EqualSymbolIndex).Trim();
                    }
                    else
                    {
                        int ColonSymbolIndex = line.IndexOf(":");
                        if (ColonSymbolIndex > 0)
                        {
                            ///get a string before ":" as a funcion name
                            FunctionName = line.Substring(0, ColonSymbolIndex ).Trim();
                        }
                        else
                            FunctionName = "anonimous";
                    }
                }

             }