#ifndef __util__
#define __util__

#include <string>
#include <sstream>

#include "types.h"


#ifndef CORE_DLL 
    #ifdef CORE_BUILD
	    #define CORE_DLL __declspec(dllexport)
    #else
	    #define CORE_DLL __declspec(dllimport)
        #pragma comment(lib, "Core.lib")
    #endif
#endif



namespace util {

    CORE_DLL const wchar_t* convertAnsiToUtf16(const char* ansi);
    CORE_DLL const wchar_t* convertUtf8ToUtf16(const char* utf8);
    CORE_DLL const char*    convertUtf16ToUtf8(const wchar_t* utf16);


    class CORE_DLL FileStream {
    public:

        errno_t open(const wchar_t* filename, const wchar_t* mode);
        void close();

        //qword read(byte* buffer, qword size);
        //qword write(byte* buffer, qword size);

    protected:
        FILE* _file;
    };

    bool CORE_DLL isOneOf(const wchar_t item, const wchar_t* set);

    std::wstring CORE_DLL reverse(const std::wstring& str);

    std::wstring CORE_DLL trim_left(const std::wstring& str, const wchar_t* trimchars = L" ");
    std::wstring CORE_DLL trim_right(const std::wstring& str, const wchar_t* trimchars = L" ");

    std::wstring CORE_DLL trim(const std::wstring& str, const wchar_t* trimchars = L" ");


    template <class T> std::wstring to_string(const T& arg) {
        std::wstringstream stream;
        stream << arg;
        return stream.str();
    }

    template <class T> T from_string(const wchar_t* arg) {
        T result;
        std::wstringstream stream;

        stream << arg;
        stream >> result;

        return result;
    }

    template <class T> T from_string(const std::wstring& arg) {
        T result;
        std::wstringstream stream;

        stream << arg;
        stream >> result;

        return result;
    }

};

#endif