private bool CheckNotFalsePositive(string line, int matchOffset, string searchString)
        {
            if (matchOffset > 0)
            {
                //begin of match is begin of word
                var previousChar = line[matchOffset - 1];
                if (FortranParseHelper.IsWordCharacter(previousChar))
                {
                    return(false);
                }
            }
            var endOfMatch = searchString.Length + matchOffset;

            if (endOfMatch < line.Length)
            {
                //end of match is end of word
                var nextChar = line[endOfMatch];
                if (FortranParseHelper.IsWordCharacter(nextChar))
                {
                    return(false);
                }
            }

            return(!FortranParseHelper.IsIndexInsideCharacterString(line, matchOffset));
        }
        private static LocationInFile FindFirstLocationOfElementNameInLines(IMember member, string variableName, string[] allLines, ref int lineHint)
        {
            for (var i = lineHint; i < allLines.Length; i++)
            {
                var line       = allLines[i];
                var startIndex = 0;
                int indexInLine;
                do
                {
                    indexInLine = line.IndexOf(variableName, startIndex, StringComparison.InvariantCultureIgnoreCase);
                    startIndex  = indexInLine + 2; //+1 = space, so at least +2
                    if (indexInLine >= 0)
                    {
                        if (indexInLine > 0 && FortranParseHelper.IsWordCharacter(line[indexInLine - 1]))
                        {
                            continue; //part of other string
                        }
                        var endOfNameIndex = indexInLine + variableName.Length;
                        if (endOfNameIndex < line.Length && FortranParseHelper.IsWordCharacter(line[endOfNameIndex]))
                        {
                            continue;
                        }

                        lineHint = i;
                        return(new LocationInFile(member.Location.Line + i, indexInLine, -1));
                    }
                } while (indexInLine >= 0 && startIndex < line.Length); //while matches in line
            }
            throw new ArgumentException(string.Format("Cannot find variable {0} in variable declarations, in file {1}",
                                                      variableName, member.Root.CodeFile.ProjectName));
        }
Example #3
0
        public string ReadElementName()
        {
            bool nameStarted = false;

            var start = ReadIndex;

            for (ReadIndex = start; ReadIndex < Text.Length; ReadIndex++)
            {
                var c = Text[ReadIndex];

                if (!nameStarted && c == ' ') //skip spaces in front of name
                {
                    start++;
                    continue;
                }

                nameStarted = true;

                if (FortranParseHelper.IsWhiteSpace(c)) //quick loop
                {
                    //end of name
                    break;
                }

                if (!FortranParseHelper.IsWordCharacter(c))
                {
                    //non valid name characters: end of name
                    break;
                }
            }
            if (ReadIndex < Text.Length)
            {
                var name = Text.Substring(start, ReadIndex - start);
                if (!String.IsNullOrEmpty(name))
                {
                    ReadIndex--;
                }
                return(name);
            }
            return("");
        }