<commit_before>// Copyright 2015-2020 <NAME>. All rights reserved.

#ifndef OUZEL_STORAGE_PATH_HPP
#define OUZEL_STORAGE_PATH_HPP

#include <chrono>
#include <cstdint>
#include <stdexcept>
#include <string>

#if defined(_WIN32)
#  pragma push_macro("WIN32_LEAN_AND_MEAN")
#  pragma push_macro("NOMINMAX")
#  ifndef WIN32_LEAN_AND_MEAN
#    define WIN32_LEAN_AND_MEAN
#  endif
#  ifndef NOMINMAX
#    define NOMINMAX
#  endif
#  include <Windows.h>
#  pragma pop_macro("WIN32_LEAN_AND_MEAN")
#  pragma pop_macro("NOMINMAX")
#elif defined(__unix__) || defined(__APPLE__)
#  include <sys/stat.h>
#endif

namespace ouzel
{
    namespace storage
    {
        class Path final
        {
        public:
#if defined(_WIN32)
            static constexpr char directorySeparator = '\\';
            using Char = wchar_t;
            using String = std::wstring;
#elif defined(__unix__) || defined(__APPLE__)
            static constexpr char directorySeparator = '/';
            using Char = char;
            using String = std::string;
#endif

            Path() = default;
            Path(const std::string& p):
                path(convertToNative(p))
            {
            }

            operator std::string() const
            {
                return convertToUniversal(path);
            }

            Path& operator+=(const Path& p)
            {
                path += p.path;
                return *this;
            }

            Path& operator+=(const std::string& p)
            {
                path += convertToNative(p);
                return *this;
            }

            Path operator+(const Path& p)
            {
                Path result = *this;
                result.path += p.path;
                return result;
            }

            Path operator+(const std::string& p)
            {
                Path result = *this;
                result.path += convertToNative(p);
                return result;
            }

            const String& getNative() const noexcept
            {
                return path;
            }

            std::string getExtension() const
            {
                const std::size_t pos = path.find_last_of(Char('.'));

                String result;

                if (pos != std::string::npos)
                    result = path.substr(pos + 1);

                return convertToNative(result);
            }

            std::string getFilename() const
            {
                const std::size_t pos = path.find_last_of(directorySeparator);

                String result;

                if (pos != String::npos)
                    result = path.substr(pos + 1);
                else
                    result = path;

                return convertToNative(result);
            }

            Path getStem() const
            {
                const std::size_t directoryPos = path.find_last_of(directorySeparator);
                const std::size_t startPos = directoryPos == String::npos ? 0 : directoryPos + 1;
                const std::size_t extensionPos = path.find(Char('.'), startPos);
                const std::size_t endPos = extensionPos == String::npos ? path.size() : extensionPos;

                Path result;
                result.path = path.substr(startPos, endPos - startPos);
                return result;
            }

            Path getDirectory() const
            {
                const std::size_t pos = path.find_last_of(directorySeparator);

                Path result;
                if (pos != String::npos)
                    result.path = path.substr(0, pos);

                return result;
            }

            Path getRoot() const
            {
                Path result;
#if defined(_WIN32)<commit_msg>Convert the result to universal<commit_after>// Copyright 2015-2020 <NAME>. All rights reserved.

#ifndef OUZEL_STORAGE_PATH_HPP
#define OUZEL_STORAGE_PATH_HPP

#include <chrono>
#include <cstdint>
#include <stdexcept>
#include <string>

#if defined(_WIN32)
#  pragma push_macro("WIN32_LEAN_AND_MEAN")
#  pragma push_macro("NOMINMAX")
#  ifndef WIN32_LEAN_AND_MEAN
#    define WIN32_LEAN_AND_MEAN
#  endif
#  ifndef NOMINMAX
#    define NOMINMAX
#  endif
#  include <Windows.h>
#  pragma pop_macro("WIN32_LEAN_AND_MEAN")
#  pragma pop_macro("NOMINMAX")
#elif defined(__unix__) || defined(__APPLE__)
#  include <sys/stat.h>
#endif

namespace ouzel
{
    namespace storage
    {
        class Path final
        {
        public:
#if defined(_WIN32)
            static constexpr char directorySeparator = '\\';
            using Char = wchar_t;
            using String = std::wstring;
#elif defined(__unix__) || defined(__APPLE__)
            static constexpr char directorySeparator = '/';
            using Char = char;
            using String = std::string;
#endif

            Path() = default;
            Path(const std::string& p):
                path(convertToNative(p))
            {
            }

            operator std::string() const
            {
                return convertToUniversal(path);
            }

            Path& operator+=(const Path& p)
            {
                path += p.path;
                return *this;
            }

            Path& operator+=(const std::string& p)
            {
                path += convertToNative(p);
                return *this;
            }

            Path operator+(const Path& p)
            {
                Path result = *this;
                result.path += p.path;
                return result;
            }

            Path operator+(const std::string& p)
            {
                Path result = *this;
                result.path += convertToNative(p);
                return result;
            }

            const String& getNative() const noexcept
            {
                return path;
            }

            std::string getExtension() const
            {
                const std::size_t pos = path.find_last_of(Char('.'));

                String result;

                if (pos != std::string::npos)
                    result = path.substr(pos + 1);

                return convertToUniversal(result);
            }

            std::string getFilename() const
            {
                const std::size_t pos = path.find_last_of(directorySeparator);

                String result;

                if (pos != String::npos)
                    result = path.substr(pos + 1);
                else
                    result = path;

                return convertToUniversal(result);
            }

            Path getStem() const
            {
                const std::size_t directoryPos = path.find_last_of(directorySeparator);
                const std::size_t startPos = directoryPos == String::npos ? 0 : directoryPos + 1;
                const std::size_t extensionPos = path.find(Char('.'), startPos);
                const std::size_t endPos = extensionPos == String::npos ? path.size() : extensionPos;

                Path result;
                result.path = path.substr(startPos, endPos - startPos);
                return result;
            }

            Path getDirectory() const
            {
                const std::size_t pos = path.find_last_of(directorySeparator);

                Path result;
                if (pos != String::npos)
                    result.path = path.substr(0, pos);

                return result;
            }

            Path getRoot() const
            {
                Path result;
#if defined(_WIN32)
{'fraction_non_alphanumeric': 0.09588313413014608, 'fraction_numerical': 0.007171314741035857, 'mean_word_length': 1.436428340342931, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '319930', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1955, 'n_words': 469}