Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.5 KiB

  1. using System;
  2. namespace mbsh
  3. {
  4. /// <summary>
  5. /// Summary description for CTokenizer.
  6. /// </summary>
  7. public class CTokenizer
  8. {
  9. public CTokenizer(string inputLine, char[] delim)
  10. {
  11. int iNonEmpty = 0;
  12. int i = 0;
  13. int index = 0;
  14. string[] a_sAllTok = inputLine.Split(delim);
  15. // remove the empty tokens
  16. for (i = 0; i < a_sAllTok.Length; i++)
  17. {
  18. if (false == a_sAllTok[i].Equals(String.Empty))
  19. {
  20. iNonEmpty++;
  21. }
  22. }
  23. a_sCommands = (string[])Array.CreateInstance(typeof(string), iNonEmpty);
  24. index = 0;
  25. for (i = 0; i < a_sAllTok.Length; i++)
  26. {
  27. if (false == a_sAllTok[i].Equals(String.Empty))
  28. {
  29. a_sCommands[index] = String.Copy(a_sAllTok[i]);
  30. index++;
  31. }
  32. }
  33. }
  34. private string[] a_sCommands;
  35. public string this[int index]
  36. {
  37. get
  38. {
  39. if (index < a_sCommands.Length)
  40. {
  41. return a_sCommands[index];
  42. }
  43. else
  44. {
  45. return null;
  46. }
  47. }
  48. }
  49. /// <summary>
  50. /// Gets the next token in the tokenizer
  51. /// </summary>
  52. public string GetNextToken()
  53. {
  54. if (m_tokIndex < a_sCommands.Length)
  55. {
  56. m_tokIndex++;
  57. return a_sCommands[m_tokIndex-1];
  58. }
  59. else
  60. {
  61. return null;
  62. }
  63. }
  64. private int m_tokIndex = 0;
  65. /// <summary>
  66. /// Returns the number of tokens in the input line
  67. /// </summary>
  68. public int NumToks
  69. {
  70. get
  71. {
  72. return a_sCommands.Length;
  73. }
  74. }
  75. }
  76. }