DtoaBuilder.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #nullable disable
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. namespace Jint.Native.Number.Dtoa
  6. {
  7. internal sealed class DtoaBuilder
  8. {
  9. // allocate buffer for generated digits + extra notation + padding zeroes
  10. internal readonly char[] _chars;
  11. internal int Length;
  12. public DtoaBuilder(int size)
  13. {
  14. _chars = new char[size];
  15. }
  16. public DtoaBuilder() : this(FastDtoa.KFastDtoaMaximalLength + 8)
  17. {
  18. }
  19. internal void Append(char c)
  20. {
  21. _chars[Length++] = c;
  22. }
  23. internal void DecreaseLast()
  24. {
  25. _chars[Length - 1]--;
  26. }
  27. public void Reset()
  28. {
  29. Length = 0;
  30. System.Array.Clear(_chars, 0, _chars.Length);
  31. }
  32. public char this[int i]
  33. {
  34. get => _chars[i];
  35. set
  36. {
  37. _chars[i] = value;
  38. Length = System.Math.Max(Length, i + 1);
  39. }
  40. }
  41. public override string ToString()
  42. {
  43. return "[chars:" + new string(_chars, 0, Length) + "]";
  44. }
  45. }
  46. }