ParserExtensions.cs 942 B

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