|
| 1 | +using System; |
| 2 | + |
| 3 | +namespace ToonFormat |
| 4 | +{ |
| 5 | + |
| 6 | + public static class Constants |
| 7 | + { |
| 8 | + public const char LIST_ITEM_MARKER = '-'; |
| 9 | + |
| 10 | + public const string LIST_ITEM_PREFIX = "- "; |
| 11 | + |
| 12 | + // #region Structural characters |
| 13 | + public const char COMMA = ','; |
| 14 | + public const char COLON = ':'; |
| 15 | + public const char SPACE = ' '; |
| 16 | + public const char PIPE = '|'; |
| 17 | + public const char HASH = '#'; |
| 18 | + public const char DOT = '.'; |
| 19 | + // #endregion |
| 20 | + |
| 21 | + // #region Brackets and braces |
| 22 | + public const char OPEN_BRACKET = '['; |
| 23 | + public const char CLOSE_BRACKET = ']'; |
| 24 | + public const char OPEN_BRACE = '{'; |
| 25 | + public const char CLOSE_BRACE = '}'; |
| 26 | + // #endregion |
| 27 | + |
| 28 | + // #region Literals |
| 29 | + public const string NULL_LITERAL = "null"; |
| 30 | + public const string TRUE_LITERAL = "true"; |
| 31 | + public const string FALSE_LITERAL = "false"; |
| 32 | + // #endregion |
| 33 | + |
| 34 | + // #region Escape/control characters |
| 35 | + public const char BACKSLASH = '\\'; |
| 36 | + public const char DOUBLE_QUOTE = '"'; |
| 37 | + public const char NEWLINE = '\n'; |
| 38 | + public const char CARRIAGE_RETURN = '\r'; |
| 39 | + public const char TAB = '\t'; |
| 40 | + |
| 41 | + // #region Delimiter defaults and mapping |
| 42 | + public const ToonDelimiter DEFAULT_DELIMITER_ENUM = ToonDelimiter.COMMA; |
| 43 | + |
| 44 | + /// <summary>Default delimiter character (comma).</summary> |
| 45 | + public const char DEFAULT_DELIMITER_CHAR = COMMA; |
| 46 | + |
| 47 | + /// <summary>Maps delimiter enum values to their specific characters.</summary> |
| 48 | + public static char ToDelimiterChar(ToonDelimiter delimiter) => delimiter switch |
| 49 | + { |
| 50 | + ToonDelimiter.COMMA => COMMA, |
| 51 | + ToonDelimiter.TAB => TAB, |
| 52 | + ToonDelimiter.PIPE => PIPE, |
| 53 | + _ => COMMA |
| 54 | + }; |
| 55 | + |
| 56 | + /// <summary>Maps delimiter characters to enum; unknown characters fall back to comma.</summary> |
| 57 | + public static ToonDelimiter FromDelimiterChar(char delimiter) => delimiter switch |
| 58 | + { |
| 59 | + COMMA => ToonDelimiter.COMMA, |
| 60 | + TAB => ToonDelimiter.TAB, |
| 61 | + PIPE => ToonDelimiter.PIPE, |
| 62 | + _ => ToonDelimiter.COMMA |
| 63 | + }; |
| 64 | + |
| 65 | + /// <summary>Returns whether the character is a supported delimiter.</summary> |
| 66 | + public static bool IsDelimiterChar(char c) => c == COMMA || c == TAB || c == PIPE; |
| 67 | + |
| 68 | + /// <summary>Returns whether the character is a whitespace character (space or tab).</summary> |
| 69 | + public static bool IsWhitespace(char c) => c == SPACE || c == TAB; |
| 70 | + |
| 71 | + /// <summary>Returns whether the character is a structural character.</summary> |
| 72 | + public static bool IsStructural(char c) |
| 73 | + => c == COLON || c == OPEN_BRACKET || c == CLOSE_BRACKET || c == OPEN_BRACE || c == CLOSE_BRACE; |
| 74 | + // #endregion |
| 75 | + } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// TOON's unified options configuration, styled to align with System.Text.Json. Used to control indentation, |
| 79 | + /// delimiters, strict mode, length markers, and underlying JSON behavior. |
| 80 | + /// </summary> |
| 81 | + public enum ToonDelimiter |
| 82 | + { |
| 83 | + /// <summary>Comma ,</summary> |
| 84 | + COMMA, |
| 85 | + |
| 86 | + /// <summary>Tab \t</summary> |
| 87 | + TAB, |
| 88 | + |
| 89 | + /// <summary>Pipe |</summary> |
| 90 | + PIPE |
| 91 | + } |
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Key folding options |
| 95 | + /// </summary> |
| 96 | + public enum ToonKeyFolding |
| 97 | + { |
| 98 | + /// <summary>Key folding disabled</summary> |
| 99 | + Off, |
| 100 | + |
| 101 | + /// <summary>Nested objects with single keys are collapsed into dotted paths</summary> |
| 102 | + Safe |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments