JSONValue.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Text;
  2. /**
  3. * A value can be a string in double quotes, or a number, or true or false or null, or an object or an array.
  4. * These structures can be nested.
  5. * @author zeh
  6. */
  7. public abstract class JSONValue {
  8. // Properties
  9. protected int inputStart;
  10. protected int inputLength;
  11. protected StringBuilder input;
  12. // ================================================================================================================
  13. // CONSTRUCTOR ----------------------------------------------------------------------------------------------------
  14. public JSONValue() {
  15. }
  16. public JSONValue(object value) {
  17. setValue(value);
  18. }
  19. public JSONValue(StringBuilder input, int position) {
  20. parseInput(input, position);
  21. }
  22. // ================================================================================================================
  23. // PUBLIC INTERFACE -----------------------------------------------------------------------------------------------
  24. public void parseInput(StringBuilder parseInput, int parseInputStart) {
  25. input = parseInput;
  26. inputStart = parseInputStart;
  27. parseValueFromInput();
  28. }
  29. public string ToString(int indentLevel, JSONStringifyOptions options) {
  30. return stringifyValue(indentLevel, options);
  31. }
  32. public abstract object getValue();
  33. public abstract void setValue(object newValue);
  34. public int getInputLength() {
  35. return inputLength;
  36. }
  37. // ================================================================================================================
  38. // INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
  39. protected abstract void parseValueFromInput();
  40. protected abstract string stringifyValue(int indentLevel, JSONStringifyOptions options);
  41. }