<commit_before>/**
 * @file
 * @author lpraz
 *
 * @section DESCRIPTION
 * Defines methods for the TagFile class.
 */

// Stdlib includes
#include <algorithm>
#include <sstream>

// Include own header
#include "TagFile.hpp"

namespace Tiger {
    // private:
    
    /**
     * Reads the next string found within a pair of double quotation
     * marks (").
     *
     * @param stream The stream to read from.
     * @returns The string that was read.
     */
    std::string TagFile::readQuotedString(std::istream &stream) {
        std::stringstream resultStream;
        char nextChar;
        
        while (stream >> nextChar)
            if (nextChar == '"')
                break;
        
        while (stream >> nextChar) {
            if (nextChar == '"')
                break;
            else
                resultStream << nextChar;
        }
        
        return resultStream.str();
    }
    
    // public:
    
    /**
     * Initializes a TagFile.
     */
    TagFile::TagFile() {
        homeDirectory = getenv("HOME");
        tagFileStream.open(homeDirectory + tagFilePath);
        
        std::string currentLine;
        
        while (!tagFileStream.eof()) {
            getline(tagFileStream, currentLine);
            std::stringstream currentLineStream(currentLine);
            
            readQuotedString(tagFileStream); // into key
            
            while (tagFileStream.peek() != '\n')
                readQuotedString(tagFileStream); // into values
        }
    }
    
    /**
     * Closes a TagFile, and saves any changes to TagFile::tags to disk.
     */
    TagFile::~TagFile() {
        bool firstTag = true;
        
        for (auto tag : tags) {
            if (firstTag)
                firstTag = false;
            else
                tagFileStream << "\n";
            
            tagFileStream << "\"" << tag.first << "\":";
            bool firstFile = true;
            
            for (auto file : tag.second) {
                if (firstFile)
                    firstFile = false;
                else
                    tagFileStream << ", ";
                
                tagFileStream << "\"" << file << "\"";
            }
        }
    }<commit_msg>Completed file input in TagFile's constructor<commit_after>/**
 * @file
 * @author lpraz
 *
 * @section DESCRIPTION
 * Defines methods for the TagFile class.
 */

// Stdlib includes
#include <algorithm>
#include <sstream>

// Include own header
#include "TagFile.hpp"

namespace Tiger {
    // private:
    
    /**
     * Reads the next string found within a pair of double quotation
     * marks (").
     *
     * @param stream The stream to read from.
     * @returns The string that was read.
     */
    std::string TagFile::readQuotedString(std::istream &stream) {
        std::stringstream resultStream;
        char nextChar;
        
        while (stream >> nextChar)
            if (nextChar == '"')
                break;
        
        while (stream >> nextChar) {
            if (nextChar == '"')
                break;
            else
                resultStream << nextChar;
        }
        
        return resultStream.str();
    }
    
    // public:
    
    /**
     * Initializes a TagFile.
     */
    TagFile::TagFile() {
        homeDirectory = getenv("HOME");
        tagFileStream.open(homeDirectory + tagFilePath);
        
        std::string currentLine;
        
        while (!tagFileStream.eof()) {
            std::string tag = readQuotedString(tagFileStream);
            std::vector<std::string> files;
            
            while (tagFileStream.peek() != '\n')
                files.push_back(readQuotedString(tagFileStream));
            
            tags.insert({tag, files});
        }
    }
    
    /**
     * Closes a TagFile, and saves any changes to TagFile::tags to disk.
     */
    TagFile::~TagFile() {
        bool firstTag = true;
        
        for (auto tag : tags) {
            if (firstTag)
                firstTag = false;
            else
                tagFileStream << "\n";
            
            tagFileStream << "\"" << tag.first << "\":";
            bool firstFile = true;
            
            for (auto file : tag.second) {
                if (firstFile)
                    firstFile = false;
                else
                    tagFileStream << ", ";
                
                tagFileStream << "\"" << file << "\"";
            }
        }
    }
{'fraction_non_alphanumeric': 0.1143367574810183, 'fraction_numerical': 0.0, 'mean_word_length': 1.3536521282186023, 'pattern_counts': {'":': 2, '<': 44, '<?xml version=': 0, '>': 16, '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': '2830488', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1180, 'n_words': 291}