<commit_before>//-----------------------------------------------------------------------------
// <copyright file="JsonWriter.cs" company="Dropbox Inc">
//  Copyright (c) Dropbox Inc. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------------

namespace <Namespace>.Stone
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;

    using Newtonsoft.Json;

    /// <summary>
    /// Write json as string.
    /// </summary>
    internal sealed class JsonWriter : IJsonWriter
    {
        /// <summary>
        /// The json text writer.
        /// </summary>
        private readonly JsonTextWriter writer;

        /// <summary>
        /// Initializes a new instance of the <see cref="JsonWriter"/> class.
        /// </summary>
        /// <param name="writer">The text writer.</param>
        private JsonWriter(JsonTextWriter writer)
        {
            this.writer = writer;
        }

        /// <summary>
        /// Write the specified object.
        /// </summary>
        /// <typeparam name="T">The type of the object to write.</typeparam>
        /// <param name="encodable">The object to write.</param>
        /// <param name="encoder">The encoder.</param>
        /// <param name="escapeNonAscii">If escape non-ascii characters.</param>
        /// <returns>The encoded object as a JSON string.</returns>
        public static string Write<T>(T encodable, IEncoder<T> encoder, bool escapeNonAscii = false)
        {
            var builder = new StringBuilder();
            var textWriter = new JsonTextWriter(new StringWriter(builder)) { DateFormatString = "yyyy-MM-ddTHH:mm:ssZ" };

            if (escapeNonAscii)
            {
                textWriter.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;
            }

            var writer = new JsonWriter(textWriter);
            encoder.Encode(encodable, writer);

            var json = builder.ToString();

            return !string.IsNullOrEmpty(json) ? json : "null";
        }

        /// <summary>
        /// Write a Int32 value.
        /// </summary><commit_msg>Escapte 0x7f in json serialization.<commit_after>//-----------------------------------------------------------------------------
// <copyright file="JsonWriter.cs" company="Dropbox Inc">
//  Copyright (c) Dropbox Inc. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------------

namespace <Namespace>.Stone
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;

    using Newtonsoft.Json;

    /// <summary>
    /// Write json as string.
    /// </summary>
    internal sealed class JsonWriter : IJsonWriter
    {
        /// <summary>
        /// The json text writer.
        /// </summary>
        private readonly JsonTextWriter writer;

        /// <summary>
        /// Initializes a new instance of the <see cref="JsonWriter"/> class.
        /// </summary>
        /// <param name="writer">The text writer.</param>
        private JsonWriter(JsonTextWriter writer)
        {
            this.writer = writer;
        }

        /// <summary>
        /// Write the specified object.
        /// </summary>
        /// <typeparam name="T">The type of the object to write.</typeparam>
        /// <param name="encodable">The object to write.</param>
        /// <param name="encoder">The encoder.</param>
        /// <param name="escapeNonAscii">If escape non-ascii characters.</param>
        /// <returns>The encoded object as a JSON string.</returns>
        public static string Write<T>(T encodable, IEncoder<T> encoder, bool escapeNonAscii = false)
        {
            var builder = new StringBuilder();
            var textWriter = new JsonTextWriter(new StringWriter(builder)) { DateFormatString = "yyyy-MM-ddTHH:mm:ssZ" };

            if (escapeNonAscii)
            {
                textWriter.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;
            }

            var writer = new JsonWriter(textWriter);
            encoder.Encode(encodable, writer);

            var json = builder.ToString();

            return !string.IsNullOrEmpty(json) ? json .Replace("\x7f", "\\u007f"): "null";
        }

        /// <summary>
        /// Write a Int32 value.
        /// </summary>
{'fraction_non_alphanumeric': 0.19384264538198404, 'fraction_numerical': 0.002280501710376283, 'mean_word_length': 1.5784832451499118, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, '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': '1867571', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1081, 'n_words': 293}