<commit_before>#pragma once
#ifndef STRINGSTREAM_H_INCLUDED
#define STRINGSTREAM_H_INCLUDED

#include <z/int.h>
#include "charFunctions.h"
#include "string.h"
#include "stream.h"

namespace z
{
    namespace core
    {
        template <typename CHAR>
        class stringStream : public stream<CHAR>
        {
        private:
            string<CHAR> data;
            Int index;

        public:
            stringStream(const string<CHAR>&);

            CHAR get();
            string<CHAR> get(int);
            void unget();
            void put(CHAR);

            string<CHAR> read(CHAR delim = 0);
            void write(const string<CHAR>&);

            bool empty();
            void seek(int);
            int tell();
        };

        template <typename CHAR>
        stringStream<CHAR>::stringStream(const string<CHAR>& input) : data(input), index(0) {}

        template <typename CHAR>
        CHAR stringStream<CHAR>::get()
        {
            CHAR c = data[index];
            index++;

            return c;
        }

        template <typename CHAR>
        string<CHAR> stringStream<CHAR>::get(int count)
        {
            if (count < 1) return string<CHAR>();

            string<CHAR> result = data.substr(index, index+count-1);
            index += count;

            return result;
        }

        template <typename CHAR>
        void stringStream<CHAR>::unget()
        {
            if (index)
                index--;
        }

        template <typename CHAR>
        void stringStream<CHAR>::put(CHAR c)
        {
            data += string<CHAR>(c);
        }

        template <typename CHAR>
        string<CHAR> stringStream<CHAR>::read(CHAR delim)
        {
            Int begIndex = index;

            if (delim)
            {
                while ((begIndex < data.length()) && (data[begIndex] == delim))
                    begIndex++;
            }
            else
            {
                while ((begIndex < data.length()) && isWhiteSpace(data[begIndex]))
                    begIndex++;
            }


            Int endIndex;

            if (delim)
            {
                endIndex = data.findAfter(delim, begIndex);
                if (endIndex == -1)
                    endIndex = data.length();
            }
            else
            {
                endIndex = begIndex+1;
                while ((endIndex < data.length()) && !isWhiteSpace(data[endIndex]))
                    endIndex++;
            }

            string<CHAR> result = data.substr(begIndex, endIndex-1);
            index = endIndex;

            return result;
        }

        template <typename CHAR>
        void stringStream<CHAR>::write(const string<CHAR>& input)
        {
            data += input;
        }

        template <typename CHAR>
        bool stringStream<CHAR>::empty()
        {
            return (index >= data.length());
        }

        template <typename CHAR>
        void stringStream<CHAR>::seek(int position)
        {
            if ((position < 0) || (position >= data.length()))
                index = data.length();
            else
                index = position;
        }

        template <typename CHAR>
        int stringStream<CHAR>::tell()
        {
            return index;
        }
    }
}

#endif // STRINGSTREAM_H_INCLUDED
<commit_msg>Changed uses of 'int' to Int<commit_after>#pragma once
#ifndef STRINGSTREAM_H_INCLUDED
#define STRINGSTREAM_H_INCLUDED

#include <z/int.h>
#include "charFunctions.h"
#include "string.h"
#include "stream.h"

namespace z
{
    namespace core
    {
        template <typename CHAR>
        class stringStream : public stream<CHAR>
        {
        private:
            string<CHAR> data;
            Int index;

        public:
            stringStream(const string<CHAR>&);

            CHAR get();
            string<CHAR> get(Int);
            void unget();
            void put(CHAR);

            string<CHAR> read(CHAR delim = 0);
            void write(const string<CHAR>&);

            bool empty();
            void seek(Int);
            Int tell();
        };

        template <typename CHAR>
        stringStream<CHAR>::stringStream(const string<CHAR>& input) : data(input), index(0) {}

        template <typename CHAR>
        CHAR stringStream<CHAR>::get()
        {
            CHAR c = data[index];
            index++;

            return c;
        }

        template <typename CHAR>
        string<CHAR> stringStream<CHAR>::get(Int count)
        {
            if (count < 1) return string<CHAR>();

            string<CHAR> result = data.substr(index, index+count-1);
            index += count;

            return result;
        }

        template <typename CHAR>
        void stringStream<CHAR>::unget()
        {
            if (index)
                index--;
        }

        template <typename CHAR>
        void stringStream<CHAR>::put(CHAR c)
        {
            data += string<CHAR>(c);
        }

        template <typename CHAR>
        string<CHAR> stringStream<CHAR>::read(CHAR delim)
        {
            Int begIndex = index;

            if (delim)
            {
                while ((begIndex < data.length()) && (data[begIndex] == delim))
                    begIndex++;
            }
            else
            {
                while ((begIndex < data.length()) && isWhiteSpace(data[begIndex]))
                    begIndex++;
            }


            Int endIndex;

            if (delim)
            {
                endIndex = data.findAfter(delim, begIndex);
                if (endIndex == -1)
                    endIndex = data.length();
            }
            else
            {
                endIndex = begIndex+1;
                while ((endIndex < data.length()) && !isWhiteSpace(data[endIndex]))
                    endIndex++;
            }

            string<CHAR> result = data.substr(begIndex, endIndex-1);
            index = endIndex;

            return result;
        }

        template <typename CHAR>
        void stringStream<CHAR>::write(const string<CHAR>& input)
        {
            data += input;
        }

        template <typename CHAR>
        bool stringStream<CHAR>::empty()
        {
            return (index >= data.length());
        }

        template <typename CHAR>
        void stringStream<CHAR>::seek(Int position)
        {
            if ((position < 0) || (position >= data.length()))
                index = data.length();
            else
                index = position;
        }

        template <typename CHAR>
        Int stringStream<CHAR>::tell()
        {
            return index;
        }
    }
}

#endif // STRINGSTREAM_H_INCLUDED

{'fraction_non_alphanumeric': 0.10785295379773994, 'fraction_numerical': 0.0022886568445143756, 'mean_word_length': 1.2424631173829377, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 79, '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': '4785380', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1710, 'n_words': 407}