PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/UiException/StackTraceAnalysers/PathCompositeParser.cs

#
C# | 102 lines | 45 code | 15 blank | 42 comment | 4 complexity | 61f7be708e99aba5e3902829056ab4eb MD5 | raw file
  1// ****************************************************************
  2// This is free software licensed under the NUnit license. You may
  3// obtain a copy of the license at http://nunit.org
  4// ****************************************************************
  5
  6using System;
  7using System.Collections.Generic;
  8using System.Text;
  9using NUnit.UiException.StackTraceAnalyzers;
 10
 11namespace NUnit.UiException.StackTraceAnalysers
 12{
 13    /// <summary>
 14    /// Encapsulates a set of algorithms that try to match and locate
 15    /// a path value coming from a raw stack trace line.
 16    /// </summary>
 17    public class PathCompositeParser :
 18        IErrorParser
 19    {
 20        /// <summary>
 21        /// This array encapsulates a list of classes that inherit from
 22        /// IErrorParser. Each instance is made for handling a path from
 23        /// a specific file system such as: Windows or UNIX.
 24        /// </summary>
 25        private IErrorParser[] _array;
 26
 27        /// <summary>
 28        /// Build a new instance of PathParser.
 29        /// </summary>
 30        public PathCompositeParser()
 31        {
 32            // setup this array with a couple of algorithms
 33            // that handle respectively Windows and Unix like paths.
 34            
 35            _array = new IErrorParser[] { 
 36                new WindowsPathParser(),
 37                new UnixPathParser()
 38
 39                // add your own parser here
 40            };
 41
 42            return;
 43        }
 44
 45        /// <summary>
 46        /// Gives access to the IErrorParser instance that handles
 47        /// Windows like path values.
 48        /// </summary>
 49        public IErrorParser WindowsPathParser
 50        {
 51            get { return (_array[0]); }
 52        }
 53
 54        /// <summary>
 55        /// Gives access to the IErrorParser instance that handles
 56        /// Unix like path values.
 57        /// </summary>
 58        public IErrorParser UnixPathParser
 59        {
 60            get { return (_array[1]); }
 61        }
 62
 63        #region IErrorParser Membres
 64
 65        /// <summary>
 66        /// Try to read from a stack trace line a path value given either
 67        /// under the form of a Windows path or a UNIX path. If a match occurs
 68        /// the method fills args.Function with the identified data.
 69        /// </summary>
 70        /// <param name="parser">The instance of StackTraceParser, this parameter
 71        /// cannot be null.</param>
 72        /// <param name="args">The instance of RawError from where read and write
 73        /// RawError.Input and RawError.Function properties. This parameter
 74        /// cannot be null.</param>
 75        /// <returns>True if a match occurs, false otherwise.</returns>
 76        public bool TryParse(StackTraceParser parser, RawError args)
 77        {
 78            foreach (IErrorParser item in _array)
 79                if (item.TryParse(parser, args))
 80                    return (true);
 81
 82            return (false);
 83        }
 84
 85        #endregion
 86
 87        /// <summary>
 88        /// Helper method that locate the trailing ':' in a stack trace row.
 89        /// </summary>
 90        /// <returns>The index position of ':' in the string or -1 if not found.</returns>
 91        public static int IndexOfTrailingColon(string error, int startIndex)
 92        {
 93            int i;
 94
 95            for (i = startIndex; i < error.Length; ++i)
 96                if (error[i] == ':')
 97                    return (i);
 98
 99            return (-1);
100        }                                
101    }
102}