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

namespace Cxxi
{
    public class TextGenerator
    {
        private const uint DefaultIndent = 4;
        private const uint MaxIndent = 80;

        private readonly StringBuilder sb;
        private bool isStartOfLine;
        private bool needsNewLine;

        protected readonly Stack<uint> CurrentIndent;

        public TextGenerator()
        {
            sb = new StringBuilder();
            isStartOfLine = false;
            CurrentIndent = new Stack<uint>();
        }

        public void Write(string msg, params object[] args)
        {
            if (isStartOfLine)
                sb.Append(new string(' ', (int)CurrentIndent.Sum(u => u)));

            if (args.Length > 0)
                msg = string.Format(msg, args);

            if (msg.Length > 0)
                isStartOfLine = false;

            sb.Append(msg);
        }

        public void WriteLine(string msg, params object[] args)
        {
            Write(msg, args);
            NewLine();
        }

        public void WriteLineIndent(string msg, params object[] args)
        {
            PushIndent();
            WriteLine(msg, args);
            PopIndent();
        }

        public void NewLine()
        {
            sb.AppendLine(string.Empty);
            isStartOfLine = true;
        }

        public void NewLineIfNeeded()
        {
            if (!needsNewLine) return;

            NewLine();
            needsNewLine = false;
        }

        public void NeedNewLine()
        {
            needsNewLine = true;
        }

        public void PushIndent(uint indent = DefaultIndent)
        {
            CurrentIndent.Push(indent);
        }

        public void PopIndent()
        {
            CurrentIndent.Pop();
        }

        public void WriteStartBraceIndent()
        {
            WriteLine("{");
            PushIndent();
        }

        public void WriteCloseBraceIndent()
        {
            PopIndent();
            WriteLine("}");
        }

        public override string ToString()
        {
            return sb.ToString();
        }

        public static implicit operator string(TextGenerator tg)
        {
            return tg.ToString();
        }

    }
}
<commit_msg>Fixed missing indentation when calling TextGenerator.Write with a string ending with new line<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cxxi
{
    public class TextGenerator
    {
        private const uint DefaultIndent = 4;
        private const uint MaxIndent = 80;

        private readonly StringBuilder sb;
        private bool isStartOfLine;
        private bool needsNewLine;

        protected readonly Stack<uint> CurrentIndent;

        public TextGenerator()
        {
            sb = new StringBuilder();
            isStartOfLine = false;
            CurrentIndent = new Stack<uint>();
        }

        public void Write(string msg, params object[] args)
        {
            if (isStartOfLine)
                sb.Append(new string(' ', (int)CurrentIndent.Sum(u => u)));

            if (args.Length > 0)
                msg = string.Format(msg, args);

            if (msg.Length > 0)
                isStartOfLine = msg.EndsWith(System.Environment.NewLine);

            sb.Append(msg);
        }

        public void WriteLine(string msg, params object[] args)
        {
            Write(msg, args);
            NewLine();
        }

        public void WriteLineIndent(string msg, params object[] args)
        {
            PushIndent();
            WriteLine(msg, args);
            PopIndent();
        }

        public void NewLine()
        {
            sb.AppendLine(string.Empty);
            isStartOfLine = true;
        }

        public void NewLineIfNeeded()
        {
            if (!needsNewLine) return;

            NewLine();
            needsNewLine = false;
        }

        public void NeedNewLine()
        {
            needsNewLine = true;
        }

        public void PushIndent(uint indent = DefaultIndent)
        {
            CurrentIndent.Push(indent);
        }

        public void PopIndent()
        {
            CurrentIndent.Pop();
        }

        public void WriteStartBraceIndent()
        {
            WriteLine("{");
            PushIndent();
        }

        public void WriteCloseBraceIndent()
        {
            PopIndent();
            WriteLine("}");
        }

        public override string ToString()
        {
            return sb.ToString();
        }

        public static implicit operator string(TextGenerator tg)
        {
            return tg.ToString();
        }

    }
}

{'fraction_non_alphanumeric': 0.08824150306100907, 'fraction_numerical': 0.0021110407430863414, 'mean_word_length': 1.448578811369509, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '1541768', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1185, 'n_words': 302}