<commit_before>#pragma once

#include "string.h"
#include "../bx/platform.h"

#if !BX_PLATFORM_WINDOWS
#  include <sys/types.h>
#  include <sys/stat.h>
#else
#  define WIN32_LEAN_AND_MEAN
#  include <Windows.h>
#endif

namespace bx
{
    enum class PathType
    {
        Invalid = 0,
        Directory,
        File
    };

    class Path : public String256
    {
    public:
        Path() : String256() {}
        explicit Path(const char* text) : String256(text) {}

        Path& operator=(const Path& str)
        {
            return (Path&)String256::operator=((const String256&)str);
        }

        Path& operator=(const char* str)
        {
            return (Path&)String256::operator=(str);
        }

        Path getDirectory() const;
        Path getFilename() const;
        Path getFileExt() const;
        Path getFilenameFull() const;

        Path& goUp();
        Path& toUnix();
        Path& toWindows();

        Path& normalizeSelf();
        Path& join(const char* path);
        PathType getType();        
    };

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // Path
    inline Path Path::getDirectory() const
    {
        Path p;

        // Path with '/' or '\\' at the End
        const char* r = strrchr((const char*)this->text, '/');
        if (!r)
            r = strrchr((const char*)this->text, '\\');
        if (r)     {
            size_t o = (size_t)(r - this->text);
            strncpy(p.text, this->text, o);
            p.text[o] = 0;
        }   else    {
            strcpy(p.text, this->text);
        }

        return p;
    }

    inline Path Path::getFilename() const
    {
        Path p;

        const char* ri = strrchr((const char*)this->text, '/');
        if (!ri)
            ri = strrchr((const char*)this->text, '\\');

        if (ri)
            strcpy(p.text, ri + 1);
        else
            strcpy(p.text, this->text);

        // Name only
        char* r = strrchr(p.text, '.');
        if (r)
            *r = 0;
        return p;
    }

    inline Path Path::getFileExt() const
    {
        Path p;

        const char* r = strrchr((const char*)this->text, '.');
        const char* r2 = strchr((const char*)this->text, '/');
        if (r > r2)
            strcpy(p.text, r + 1);
        return p;
    }

    inline  Path Path::getFilenameFull() const
    {
        Path p;

        const char* r = strrchr((const char*)this->text, '/');
        if (!r)
            r = strrchr((const char*)this->text, '\\');
        if (r)
            strcpy(p.text, r + 1);
        else
            strcpy(p.text, this->text);

        return p;
    }

    inline Path& Path::goUp()
    {
        int s = getLength();

        if (this->text[s-1] == '/' || this->text[s-1] == '\\')
            this->text[s-1] = 0;

        // handle case when the path is like 'my/path/./'
        if (s>3 && this->text[s-2] == '.' && (this->text[s-3] == '/' || this->text[s-3] == '\\'))
            this->text[s-3] = 0;
        // handle case when the path is like 'my/path/.'
        if (s>2 && this->text[s-1] == '.' && (this->text[s-2] == '/' || this->text[s-2] == '\\'))
            this->text[s-2] = 0;

        char* up = strrchr(this->text, '/');
        if (!up)
            up = strrchr(this->text, '\\');

        if (!up)
            *up = 0;

        return *this;
    }

    inline Path& Path::toUnix()
    {
        return (Path&)replace('\\', '/');
    }
<commit_msg>font loading, font library<commit_after>#pragma once

#include "string.h"
#include "../bx/platform.h"

#if !BX_PLATFORM_WINDOWS
#  include <sys/types.h>
#  include <sys/stat.h>
#else
#  define WIN32_LEAN_AND_MEAN
#  include <Windows.h>
#endif

namespace bx
{
    enum class PathType
    {
        Invalid = 0,
        Directory,
        File
    };

    class Path : public String256
    {
    public:
        Path() : String256() {}
        explicit Path(const char* text) : String256(text) {}

        Path& operator=(const Path& str)
        {
            return (Path&)String256::operator=((const String256&)str);
        }

        Path& operator=(const char* str)
        {
            return (Path&)String256::operator=(str);
        }

        Path getDirectory() const;
        Path getFilename() const;
        Path getFileExt() const;
        Path getFilenameFull() const;

        Path& goUp();
        Path& toUnix();
        Path& toWindows();

        Path& normalizeSelf();
        Path& join(const char* path);
        PathType getType();        
    };

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // Path
    inline Path Path::getDirectory() const
    {
        Path p;

        // Path with '/' or '\\' at the End
        const char* r = strrchr((const char*)this->text, '/');
        if (!r)
            r = strrchr((const char*)this->text, '\\');
        if (r)     {
            size_t o = (size_t)(r - this->text);
            strncpy(p.text, this->text, o);
            p.text[o] = 0;
        }   else    {
            strcpy(p.text, this->text);
        }

        return p;
    }

    inline Path Path::getFilename() const
    {
        Path p;

        const char* ri = strrchr((const char*)this->text, '/');
        if (!ri)
            ri = strrchr((const char*)this->text, '\\');

        if (ri)
            strcpy(p.text, ri + 1);
        else
            strcpy(p.text, this->text);

        // Name only
        char* r = strrchr(p.text, '.');
        if (r)
            *r = 0;
        return p;
    }

    inline Path Path::getFileExt() const
    {
        Path p;

        const char* r = strrchr((const char*)this->text, '.');
        const char* r2 = strchr((const char*)this->text, '/');
        if (r > r2)
            strcpy(p.text, r + 1);
        return p;
    }

    inline  Path Path::getFilenameFull() const
    {
        Path p;

        const char* r = strrchr((const char*)this->text, '/');
        if (!r)
            r = strrchr((const char*)this->text, '\\');
        if (r)
            strcpy(p.text, r + 1);
        else
            strcpy(p.text, this->text);

        return p;
    }

    inline Path& Path::goUp()
    {
        int s = getLength();

        if (this->text[s-1] == '/' || this->text[s-1] == '\\')
            this->text[s-1] = 0;

        // handle case when the path is like 'my/path/./'
        if (s>3 && this->text[s-2] == '.' && (this->text[s-3] == '/' || this->text[s-3] == '\\'))
            this->text[s-3] = 0;
        // handle case when the path is like 'my/path/.'
        if (s>2 && this->text[s-1] == '.' && (this->text[s-2] == '/' || this->text[s-2] == '\\'))
            this->text[s-2] = 0;

        char* up = strrchr(this->text, '/');
        if (!up)
            up = strrchr(this->text, '\\');

        if (up)
            *up = 0;

        return *this;
    }

    inline Path& Path::toUnix()
    {
        return (Path&)replace('\\', '/');
    }

{'fraction_non_alphanumeric': 0.19925777904653155, 'fraction_numerical': 0.01284613188695404, 'mean_word_length': 1.416206896551724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 67, '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': '7615123', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2258, 'n_words': 525}