ParserExtensions.cs 903 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. namespace Jint.Parser
  3. {
  4. public static class ParserExtensions
  5. {
  6. public static string Slice(this string source, int start, int end)
  7. {
  8. return source.Substring(start, end - start);
  9. }
  10. public static char CharCodeAt(this string source, int index)
  11. {
  12. if (index < 0 || index > source.Length - 1)
  13. {
  14. // char.MinValue is used as the null value
  15. return char.MinValue;
  16. }
  17. return source[index];
  18. }
  19. public static T Pop<T>(this List<T> list)
  20. {
  21. var lastIndex = list.Count - 1;
  22. var last = list[lastIndex];
  23. list.RemoveAt(lastIndex);
  24. return last;
  25. }
  26. public static void Push<T>(this List<T> list, T item)
  27. {
  28. list.Add(item);
  29. }
  30. }
  31. }