<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;

namespace BLTools.Json {
  public class JsonPair : IDisposable, IJsonPair {

    public static JsonPair Default => new JsonPair("(default)", new JsonNull());

    public string Key { get; private set; }

    public IJsonValue Content { get; private set; }

    #region --- Typed content --------------------------------------------
    public JsonString StringContent => Content is JsonString Temp ? Temp : null;

    public JsonInt IntContent => Content is JsonInt Temp ? Temp : null;

    public JsonLong LongContent => Content is JsonLong Temp ? Temp : null;

    public JsonFloat FloatContent => Content is JsonFloat Temp ? Temp : null;

    public JsonDouble DoubleContent => Content is JsonDouble Temp ? Temp : null;

    public JsonBool BoolContent => Content is JsonBool Temp ? Temp : null;

    public JsonDateTime DateTimeContent => Content is JsonDateTime Temp ? Temp : null;

    public JsonArray ArrayContent => Content is JsonArray Temp ? Temp : null;

    public JsonObject ObjectContent => Content is JsonObject Temp ? Temp : null;
    #endregion --- Typed content --------------------------------------------

    #region --- Constructor(s) ---------------------------------------------------------------------------------
    public JsonPair() { }

    public JsonPair(string key, IJsonValue jsonValue) {
      Key = key;
      Content = jsonValue;
    }

    public JsonPair(IJsonPair jsonPair) {
      Key = jsonPair.Key;
      Content = jsonPair.Content;
    }

    public JsonPair(string key, string content) {
      Key = key;
      Content = new JsonString(content);
    }

    public JsonPair(string key, int content) {
      Key = key;
      Content = new JsonInt(content);
    }

    public JsonPair(string key, long content) {
      Key = key;
      Content = new JsonLong(content);
    }

    public JsonPair(string key, float content) {
      Key = key;
      Content = new JsonFloat(content);
    }

    public JsonPair(string key, double content) {
      Key = key;
      Content = new JsonDouble(content);
    }

    public JsonPair(string key, DateTime content) {
      Key = key;
      Content = new JsonDateTime(content);
    }

    public JsonPair(string key, bool content) {
      Key = key;
      Content = new JsonBool(content);
    }

    public void Dispose() {
      Key = null;
      Content.Dispose();
    }
    #endregion --- Constructor(s) ------------------------------------------------------------------------------

    public override string ToString() {
      StringBuilder RetVal = new StringBuilder();
      RetVal.Append($"{Key} {Json.INNER_FIELD_SEPARATOR} {Content.ToString()}");
      return RetVal.ToString();
    }

    public string RenderAsString(bool formatted = false, int indent = 0, bool needFrontSpaces = true) {
      StringBuilder RetVal = new StringBuilder();

      if ( formatted && needFrontSpaces ) {
        RetVal.Append($"{StringExtension.Spaces(indent)}");
      }

      if ( formatted && !needFrontSpaces ) {
        RetVal.Append(StringExtension.Spaces(1));
      }

      RetVal.Append($"\"{Key}\" {Json.INNER_FIELD_SEPARATOR} ");

      RetVal.Append(Content.RenderAsString(formatted, indent, false));

      return RetVal.ToString();
    }

    public byte[] RenderAsBytes(bool formatted = false, int indent = 0) {

      using ( MemoryStream RetVal = new MemoryStream() ) {
        using ( JsonWriter Writer = new JsonWriter(RetVal) ) {

          if ( formatted ) {
            Writer.Write($"{StringExtension.Spaces(indent)}");
            Writer.Write($"\"{Key}\" {Json.INNER_FIELD_SEPARATOR} ");
          } else {<commit_msg>Oups, removed too much lines. Fixed<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;

namespace BLTools.Json {
  public class JsonPair : IDisposable, IJsonPair {

    public static JsonPair Default => new JsonPair("(default)", new JsonNull());

    public string Key { get; private set; }

    public IJsonValue Content { get; private set; }

    #region --- Typed content --------------------------------------------
    public JsonString StringContent => Content is JsonString Temp ? Temp : null;

    public JsonInt IntContent => Content is JsonInt Temp ? Temp : null;

    public JsonLong LongContent => Content is JsonLong Temp ? Temp : null;

    public JsonFloat FloatContent => Content is JsonFloat Temp ? Temp : null;

    public JsonDouble DoubleContent => Content is JsonDouble Temp ? Temp : null;

    public JsonBool BoolContent => Content is JsonBool Temp ? Temp : null;

    public JsonDateTime DateTimeContent => Content is JsonDateTime Temp ? Temp : null;

    public JsonArray ArrayContent => Content is JsonArray Temp ? Temp : null;

    public JsonObject ObjectContent => Content is JsonObject Temp ? Temp : null;
    #endregion --- Typed content --------------------------------------------

    #region --- Constructor(s) ---------------------------------------------------------------------------------
    public JsonPair() { }

    public JsonPair(string key, IJsonValue jsonValue) {
      Key = key;
      Content = jsonValue;
    }

    public JsonPair(IJsonPair jsonPair) {
      Key = jsonPair.Key;
      Content = jsonPair.Content;
    }

    public JsonPair(string key, string content) {
      Key = key;
      Content = new JsonString(content);
    }

    public JsonPair(string key, int content) {
      Key = key;
      Content = new JsonInt(content);
    }

    public JsonPair(string key, long content) {
      Key = key;
      Content = new JsonLong(content);
    }

    public JsonPair(string key, float content) {
      Key = key;
      Content = new JsonFloat(content);
    }

    public JsonPair(string key, double content) {
      Key = key;
      Content = new JsonDouble(content);
    }

    public JsonPair(string key, DateTime content) {
      Key = key;
      Content = new JsonDateTime(content);
    }

    public JsonPair(string key, bool content) {
      Key = key;
      Content = new JsonBool(content);
    }

    public void Dispose() {
      Key = null;
      Content.Dispose();
    }
    #endregion --- Constructor(s) ------------------------------------------------------------------------------

    public override string ToString() {
      StringBuilder RetVal = new StringBuilder();
      RetVal.Append($"{Key} {Json.INNER_FIELD_SEPARATOR} {Content.ToString()}");
      return RetVal.ToString();
    }

    public string RenderAsString(bool formatted = false, int indent = 0, bool needFrontSpaces = true) {
      StringBuilder RetVal = new StringBuilder();

      if ( formatted && needFrontSpaces ) {
        RetVal.Append($"{StringExtension.Spaces(indent)}");
      }

      if ( formatted && !needFrontSpaces ) {
        RetVal.Append(StringExtension.Spaces(1));
      }

      if ( formatted ) {
        RetVal.Append($"\"{Key}\" {Json.INNER_FIELD_SEPARATOR} ");
      } else {
        RetVal.Append($"\"{Key}\"{Json.INNER_FIELD_SEPARATOR}");
      }

      RetVal.Append(Content.RenderAsString(formatted, indent, false));

      return RetVal.ToString();
    }

    public byte[] RenderAsBytes(bool formatted = false, int indent = 0) {

      using ( MemoryStream RetVal = new MemoryStream() ) {
        using ( JsonWriter Writer = new JsonWriter(RetVal) ) {

          if ( formatted ) {
            Writer.Write($"{StringExtension.Spaces(indent)}");
            Writer.Write($"\"{Key}\" {Json.INNER_FIELD_SEPARATOR} ");
          } else {
{'fraction_non_alphanumeric': 0.1640533886225217, 'fraction_numerical': 0.0007775042114811456, 'mean_word_length': 2.2360587002096435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5616353', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1995, 'n_words': 595}