<commit_before>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iostream>

#include <glraw/RawFile.h>

namespace
{

template<typename T>
T read(std::ifstream & stream)
{
    T value;
    stream.read(reinterpret_cast<char*>(&value), sizeof(value));
    return value;
}

std::string readString(std::ifstream & stream)
{
    std::stringstream ss;
    char c;

    while (stream.good())
    {
        stream.get(c);
        if (c == '\0')
            break;

        ss << c;
    }

    return ss.str();
}

}

namespace glraw
{


uint16_t RawFile::s_magicNumber = 0xC6F5;


RawFile::RawFile(const std::string & filePath, bool parseProperties)
: m_filePath(filePath)
, m_valid(false)
{
    m_valid = readFile(parseProperties);
}


RawFile::~RawFile()
{
}


bool RawFile::isValid() const
{
    return m_valid;
}


const char * RawFile::data() const
{
    return m_data.data();
}


const size_t RawFile::size() const
{
    return m_data.size();
}


const std::string & RawFile::stringProperty(const std::string & key) const
{
    return m_stringProperties.at(key);
}


int32_t RawFile::intProperty(const std::string & key) const
{
    return m_intProperties.at(key);
}


double RawFile::doubleProperty(const std::string & key) const
{
    return m_doubleProperties.at(key);
}


bool RawFile::hasStringProperty(const std::string & key) const
{
    return m_stringProperties.find(key) == m_stringProperties.end();
}


bool RawFile::hasIntProperty(const std::string & key) const
{
    return m_intProperties.find(key) == m_intProperties.end();
}


bool RawFile::hasDoubleProperty(const std::string & key) const
{
    return m_doubleProperties.find(key) == m_doubleProperties.end();
}


bool RawFile::readFile(bool parseProperties)
{
    std::ifstream ifs(m_filePath, std::ios::in | std::ios::binary);

    if (!ifs)
    {
        std::cerr << "Reading from file \"" << m_filePath << "\" failed." << std::endl;
        return false;
    }
    
    uint64_t offset = 0;

    if (read<uint16_t>(ifs) == s_magicNumber)
    {
        offset = read<uint64_t>(ifs);

        if (parseProperties)
        {
            readProperties(ifs, offset);
        }
    }
    else
    {
        ifs.seekg(0);
    }
    
    readRawData(ifs, offset);<commit_msg>fix has***Property functions<commit_after>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iostream>

#include <glraw/RawFile.h>

namespace
{

template<typename T>
T read(std::ifstream & stream)
{
    T value;
    stream.read(reinterpret_cast<char*>(&value), sizeof(value));
    return value;
}

std::string readString(std::ifstream & stream)
{
    std::stringstream ss;
    char c;

    while (stream.good())
    {
        stream.get(c);
        if (c == '\0')
            break;

        ss << c;
    }

    return ss.str();
}

}

namespace glraw
{


uint16_t RawFile::s_magicNumber = 0xC6F5;


RawFile::RawFile(const std::string & filePath, bool parseProperties)
: m_filePath(filePath)
, m_valid(false)
{
    m_valid = readFile(parseProperties);
}


RawFile::~RawFile()
{
}


bool RawFile::isValid() const
{
    return m_valid;
}


const char * RawFile::data() const
{
    return m_data.data();
}


const size_t RawFile::size() const
{
    return m_data.size();
}


const std::string & RawFile::stringProperty(const std::string & key) const
{
    return m_stringProperties.at(key);
}


int32_t RawFile::intProperty(const std::string & key) const
{
    return m_intProperties.at(key);
}


double RawFile::doubleProperty(const std::string & key) const
{
    return m_doubleProperties.at(key);
}


bool RawFile::hasStringProperty(const std::string & key) const
{
    return m_stringProperties.find(key) != m_stringProperties.end();
}


bool RawFile::hasIntProperty(const std::string & key) const
{
    return m_intProperties.find(key) != m_intProperties.end();
}


bool RawFile::hasDoubleProperty(const std::string & key) const
{
    return m_doubleProperties.find(key) != m_doubleProperties.end();
}


bool RawFile::readFile(bool parseProperties)
{
    std::ifstream ifs(m_filePath, std::ios::in | std::ios::binary);

    if (!ifs)
    {
        std::cerr << "Reading from file \"" << m_filePath << "\" failed." << std::endl;
        return false;
    }
    
    uint64_t offset = 0;

    if (read<uint16_t>(ifs) == s_magicNumber)
    {
        offset = read<uint64_t>(ifs);

        if (parseProperties)
        {
            readProperties(ifs, offset);
        }
    }
    else
    {
        ifs.seekg(0);
    }
    
    readRawData(ifs, offset);
{'fraction_non_alphanumeric': 0.1442456372873868, 'fraction_numerical': 0.007068698917605479, 'mean_word_length': 3.3413231064237774, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 21, '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': '6685210', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1548, 'n_words': 307}