PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

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