Exemplo n.º 1
0
        public static void ReadSourceCodeRequirements(string filePath, ref ReqPathMatrix codeReqLookup)
        {
            // Read the file as one string.
            System.IO.StreamReader fileAsStream = new System.IO.StreamReader(filePath);
            string fileAsString = fileAsStream.ReadToEnd();

            fileAsStream.Close();

            // Look for requirement references in the format something_SRS_something_123 or SRS_something_123
            // or _something_SRS_something_123 and _SRS_something_123
            string pattern = @"\b[A-Za-z_]*_?SRS_\w+_\d{2}_\d{3}";
            int    lineNum = 1; // Start counting lines from 1.
            int    pos     = 0; // First character index for a regular expression match is 0.

            foreach (Match m in Regex.Matches(fileAsString, pattern))
            {
                while (pos < fileAsString.Length && pos < m.Index)
                {
                    if (fileAsString[pos] == '\n')
                    {
                        lineNum++;
                    }
                    pos++;
                }
                codeReqLookup.Add(m.Value, new FilePathLineNum(filePath, lineNum));
            }
        }