From c9152bffa843308228cdc2aed6b86093e58a6308 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Fri, 26 Apr 2024 15:37:28 +0800 Subject: [PATCH] add shit --- src/DialogHelper.cpp | 0 src/DialogHelper.hpp | 28 +++++++++++ src/EncodingHelper.cpp | 47 ++++++++++++++--- src/EncodingHelper.hpp | 29 ++++++----- src/IOHelper.cpp | 8 ++- src/IOHelper.hpp | 10 +++- src/ParserHelper.cpp | 0 src/ParserHelper.hpp | 12 +++++ src/StringHelper.hpp | 2 + src/TerminalHelper.cpp | 9 ++-- src/TerminalHelper.hpp | 81 ++++++++++++++---------------- src/YYCCommonplace.vcxproj | 4 ++ src/YYCCommonplace.vcxproj.filters | 12 +++++ 13 files changed, 171 insertions(+), 71 deletions(-) create mode 100644 src/DialogHelper.cpp create mode 100644 src/DialogHelper.hpp create mode 100644 src/ParserHelper.cpp create mode 100644 src/ParserHelper.hpp diff --git a/src/DialogHelper.cpp b/src/DialogHelper.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/DialogHelper.hpp b/src/DialogHelper.hpp new file mode 100644 index 0000000..3543663 --- /dev/null +++ b/src/DialogHelper.hpp @@ -0,0 +1,28 @@ +#pragma once +#include "YYCCInternal.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS + +#include +#include + +#include "WinImportPrefix.hpp" +#include +#include "WinImportSuffix.hpp" + +namespace YYCC::DialogHelper { + + struct FileDialogFilterEntry { + std::string FileType; + std::string FileExtension; + }; + using FileDialogFilter = std::vector; + + bool OpenFileDialog(HWND parent, const char* title, const FileDialogFilter& filter, std::string& ret); + bool OpenMultipleFileDialog(HWND parent, const char* title, const FileDialogFilter& filter, std::vector& ret); + bool SaveFileDialog(HWND parent, const char* title, const FileDialogFilter& filter, std::string& ret); + + bool OpenFolderDialog(HWND parent, std::string& ret); + +} + +#endif diff --git a/src/EncodingHelper.cpp b/src/EncodingHelper.cpp index d677ece..b87ede6 100644 --- a/src/EncodingHelper.cpp +++ b/src/EncodingHelper.cpp @@ -1,8 +1,9 @@ #include "EncodingHelper.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS namespace YYCC::EncodingHelper { - - bool WcharToChar(const wchar_t* src, std::string& dest, const UINT codepage) { + + bool WcharToChar(const wchar_t* src, std::string& dest, UINT codepage) { int count, write_result; //converter to CHAR @@ -15,11 +16,21 @@ namespace YYCC::EncodingHelper { return true; } - bool WcharToChar(const std::wstring& src, std::string& dest, const UINT codepage) { + bool WcharToChar(const std::wstring& src, std::string& dest, UINT codepage) { return WcharToChar(src.c_str(), dest, codepage); } + std::string WcharToChar(const wchar_t* src, UINT codepage) { + std::string ret; + if (!WcharToChar(src, ret, codepage)) ret.clear(); + return ret; + } + std::string WcharToChar(const std::wstring& src, UINT codepage) { + std::string ret; + if (!WcharToChar(src.c_str(), ret, codepage)) ret.clear(); + return ret; + } - bool CharToWchar(const char* src, std::wstring& dest, const UINT codepage) { + bool CharToWchar(const char* src, std::wstring& dest, UINT codepage) { int wcount, write_result; // convert to WCHAR @@ -32,18 +43,40 @@ namespace YYCC::EncodingHelper { return true; } - bool CharToWchar(const std::string& src, std::wstring& dest, const UINT codepage) { + bool CharToWchar(const std::string& src, std::wstring& dest, UINT codepage) { return CharToWchar(src.c_str(), dest, codepage); } + std::wstring CharToWchar(const char* src, UINT codepage) { + std::wstring ret; + if (!CharToWchar(src, ret, codepage)) ret.clear(); + return ret; + } + std::wstring CharToWchar(const std::string& src, UINT codepage) { + std::wstring ret; + if (!CharToWchar(src.c_str(), ret, codepage)) ret.clear(); + return ret; + } - bool CharToChar(const char* src, std::string& dest, const UINT src_codepage, const UINT dest_codepage) { + bool CharToChar(const char* src, std::string& dest, UINT src_codepage, UINT dest_codepage) { std::wstring intermediary; if (!CharToWchar(src, intermediary, src_codepage)) return false; if (!WcharToChar(intermediary, dest, dest_codepage)) return false; return true; } - bool CharToChar(const std::string& src, std::string& dest, const UINT src_codepage, const UINT dest_codepage) { + bool CharToChar(const std::string& src, std::string& dest, UINT src_codepage, UINT dest_codepage) { return CharToChar(src.c_str(), dest, src_codepage, dest_codepage); } + std::string CharToChar(const char* src, UINT src_codepage, UINT dest_codepage) { + std::string ret; + if (!CharToChar(src, ret, src_codepage, dest_codepage)) ret.clear(); + return ret; + } + std::string CharToChar(const std::string& src, UINT src_codepage, UINT dest_codepage) { + std::string ret; + if (!CharToChar(src.c_str(), ret, src_codepage, dest_codepage)) ret.clear(); + return ret; + } } + +#endif diff --git a/src/EncodingHelper.hpp b/src/EncodingHelper.hpp index 444e369..82dcadf 100644 --- a/src/EncodingHelper.hpp +++ b/src/EncodingHelper.hpp @@ -1,25 +1,30 @@ #pragma once -#include - #include "YYCCInternal.hpp" #if YYCC_OS == YYCC_OS_WINDOWS + +#include + #include "WinImportPrefix.hpp" #include -#include #include "WinImportSuffix.hpp" -#endif namespace YYCC::EncodingHelper { -#if YYCC_OS == YYCC_OS_WINDOWS - bool WcharToChar(const wchar_t* src, std::string& dest, const UINT codepage); - bool WcharToChar(const std::wstring& src, std::string& dest, const UINT codepage); + bool WcharToChar(const wchar_t* src, std::string& dest, UINT codepage); + bool WcharToChar(const std::wstring& src, std::string& dest, UINT codepage); + std::string WcharToChar(const wchar_t* src, UINT codepage); + std::string WcharToChar(const std::wstring& src, UINT codepage); - bool CharToWchar(const char* src, std::wstring& dest, const UINT codepage); - bool CharToWchar(const std::string& src, std::wstring& dest, const UINT codepage); + bool CharToWchar(const char* src, std::wstring& dest, UINT codepage); + bool CharToWchar(const std::string& src, std::wstring& dest, UINT codepage); + std::wstring CharToWchar(const char* src, UINT codepage); + std::wstring CharToWchar(const std::string& src, UINT codepage); - bool CharToChar(const char* src, std::string& dest, const UINT src_codepage, const UINT dest_codepage); - bool CharToChar(const std::string& src, std::string& dest, const UINT src_codepage, const UINT dest_codepage); + bool CharToChar(const char* src, std::string& dest, UINT src_codepage, UINT dest_codepage); + bool CharToChar(const std::string& src, std::string& dest, UINT src_codepage, UINT dest_codepage); + std::string CharToChar(const char* src, UINT src_codepage, UINT dest_codepage); + std::string CharToChar(const std::string& src, UINT src_codepage, UINT dest_codepage); -#endif } + +#endif \ No newline at end of file diff --git a/src/IOHelper.cpp b/src/IOHelper.cpp index f73c353..ef9d4d0 100644 --- a/src/IOHelper.cpp +++ b/src/IOHelper.cpp @@ -1,17 +1,19 @@ #include "IOHelper.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS + #include "EncodingHelper.hpp" #include #include namespace YYCC::IOHelper { - void GetCmdLine(std::string& u8cmd) { + void Gets(std::string& u8cmd) { std::wstring wcmd; std::getline(std::wcin, wcmd); YYCC::EncodingHelper::WcharToChar(wcmd, u8cmd, CP_UTF8); } - FILE* UTF8FOpen(const char* u8_filepath, const char* u8_mode) { + FILE* FOpen(const char* u8_filepath, const char* u8_mode) { std::wstring wmode, wpath; bool suc = YYCC::EncodingHelper::CharToWchar(u8_mode, wmode, CP_UTF8); suc = suc && YYCC::EncodingHelper::CharToWchar(u8_filepath, wpath, CP_UTF8); @@ -25,3 +27,5 @@ namespace YYCC::IOHelper { } } + +#endif diff --git a/src/IOHelper.hpp b/src/IOHelper.hpp index 23f8dd0..d68c34f 100644 --- a/src/IOHelper.hpp +++ b/src/IOHelper.hpp @@ -1,8 +1,14 @@ #pragma once +#include "YYCCInternal.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS + #include namespace YYCC::IOHelper { - void GetCmdLine(std::string&); - FILE* UTF8FOpen(const char* u8_filepath, const char* u8_mode); + void Gets(std::string& u8cmd); + FILE* FOpen(const char* u8_filepath, const char* u8_mode); + } + +#endif diff --git a/src/ParserHelper.cpp b/src/ParserHelper.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/ParserHelper.hpp b/src/ParserHelper.hpp new file mode 100644 index 0000000..90b3e83 --- /dev/null +++ b/src/ParserHelper.hpp @@ -0,0 +1,12 @@ +#pragma once +#include +#include + +namespace YYCC::ParserHelper { + + bool Parse(const std::string& strl, int& ret, int base = 10); + int Parse(const std::string& strl, int base = 10); + bool ToString(int val, std::string& ret, int base = 10); + std::string ToString(int val, int base = 10); + +} diff --git a/src/StringHelper.hpp b/src/StringHelper.hpp index 1243642..c3cc019 100644 --- a/src/StringHelper.hpp +++ b/src/StringHelper.hpp @@ -10,4 +10,6 @@ namespace YYCC::StringHelper { std::string Printf(const char* format, ...); std::string VPrintf(const char* format, va_list argptr); + std::string Join(const char* decilmer); + } diff --git a/src/TerminalHelper.cpp b/src/TerminalHelper.cpp index bb2afa4..7e82b90 100644 --- a/src/TerminalHelper.cpp +++ b/src/TerminalHelper.cpp @@ -1,17 +1,14 @@ #include "TerminalHelper.hpp" - #if YYCC_OS == YYCC_OS_WINDOWS + #include "WinImportPrefix.hpp" #include #include #include #include "WinImportSuffix.hpp" -#endif namespace YYCC::TerminalHelper { -#if YYCC_OS == YYCC_OS_WINDOWS - bool ColorfulTerminal(FILE* fs) { if (!_isatty(_fileno(fs))) return false; @@ -34,6 +31,6 @@ namespace YYCC::TerminalHelper { return true; } -#endif - } + +#endif diff --git a/src/TerminalHelper.hpp b/src/TerminalHelper.hpp index 6f2d269..a988cfb 100644 --- a/src/TerminalHelper.hpp +++ b/src/TerminalHelper.hpp @@ -1,57 +1,54 @@ #pragma once #include "YYCCInternal.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS + #include namespace YYCC::TerminalHelper { -#define UNVIRT_REMOVE_PARENS_IMPL(...) __VA_ARGS__ -#define UNVIRT_REMOVE_PARENS(T) UNVIRT_REMOVE_PARENS_IMPL T +#define YYCC_TERMCOLHDR_BLACK "\033[30m" +#define YYCC_TERMCOLHDR_RED "\033[31m" +#define YYCC_TERMCOLHDR_GREEN "\033[32m" +#define YYCC_TERMCOLHDR_YELLOW "\033[33m" +#define YYCC_TERMCOLHDR_BLUE "\033[34m" +#define YYCC_TERMCOLHDR_MAGENTA "\033[35m" +#define YYCC_TERMCOLHDR_CYAN "\033[36m" +#define YYCC_TERMCOLHDR_WHITE "\033[37m" + +#define YYCC_TERMCOLHDR_LIGHT_BLACK "\033[90m" +#define YYCC_TERMCOLHDR_LIGHT_RED "\033[91m" +#define YYCC_TERMCOLHDR_LIGHT_GREEN "\033[92m" +#define YYCC_TERMCOLHDR_LIGHT_YELLOW "\033[93m" +#define YYCC_TERMCOLHDR_LIGHT_BLUE "\033[94m" +#define YYCC_TERMCOLHDR_LIGHT_MAGENTA "\033[95m" +#define YYCC_TERMCOLHDR_LIGHT_CYAN "\033[96m" +#define YYCC_TERMCOLHDR_LIGHT_WHITE "\033[97m" + +#define YYCC_TERMCOLTAIL "\033[0m" -#define UNVIRT_TERMCOLHDR_BLACK "\033[30m" -#define UNVIRT_TERMCOLHDR_RED "\033[31m" -#define UNVIRT_TERMCOLHDR_GREEN "\033[32m" -#define UNVIRT_TERMCOLHDR_YELLOW "\033[33m" -#define UNVIRT_TERMCOLHDR_BLUE "\033[34m" -#define UNVIRT_TERMCOLHDR_MAGENTA "\033[35m" -#define UNVIRT_TERMCOLHDR_CYAN "\033[36m" -#define UNVIRT_TERMCOLHDR_WHITE "\033[37m" +#define YYCC_TERMCOL_BLACK(T) "\033[30m" T "\033[0m" +#define YYCC_TERMCOL_RED(T) "\033[31m" T "\033[0m" +#define YYCC_TERMCOL_GREEN(T) "\033[32m" T "\033[0m" +#define YYCC_TERMCOL_YELLOW(T) "\033[33m" T "\033[0m" +#define YYCC_TERMCOL_BLUE(T) "\033[34m" T "\033[0m" +#define YYCC_TERMCOL_MAGENTA(T) "\033[35m" T "\033[0m" +#define YYCC_TERMCOL_CYAN(T) "\033[36m" T "\033[0m" +#define YYCC_TERMCOL_WHITE(T) "\033[37m" T "\033[0m" -#define UNVIRT_TERMCOLHDR_LIGHT_BLACK "\033[90m" -#define UNVIRT_TERMCOLHDR_LIGHT_RED "\033[91m" -#define UNVIRT_TERMCOLHDR_LIGHT_GREEN "\033[92m" -#define UNVIRT_TERMCOLHDR_LIGHT_YELLOW "\033[93m" -#define UNVIRT_TERMCOLHDR_LIGHT_BLUE "\033[94m" -#define UNVIRT_TERMCOLHDR_LIGHT_MAGENTA "\033[95m" -#define UNVIRT_TERMCOLHDR_LIGHT_CYAN "\033[96m" -#define UNVIRT_TERMCOLHDR_LIGHT_WHITE "\033[97m" +#define YYCC_TERMCOL_LIGHT_BLACK(T) "\033[90m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_RED(T) "\033[91m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_GREEN(T) "\033[92m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_YELLOW(T) "\033[93m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_BLUE(T) "\033[94m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_MAGENTA(T) "\033[95m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_CYAN(T) "\033[96m" T "\033[0m" +#define YYCC_TERMCOL_LIGHT_WHITE(T) "\033[97m" T "\033[0m" -#define UNVIRT_TERMCOLTAIL "\033[0m" - - -#define UNVIRT_TERMCOL_BLACK(T) "\033[30m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_RED(T) "\033[31m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_GREEN(T) "\033[32m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_YELLOW(T) "\033[33m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_BLUE(T) "\033[34m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_MAGENTA(T) "\033[35m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_CYAN(T) "\033[36m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_WHITE(T) "\033[37m" UNVIRT_REMOVE_PARENS(T) "\033[0m" - -#define UNVIRT_TERMCOL_LIGHT_BLACK(T) "\033[90m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_RED(T) "\033[91m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_GREEN(T) "\033[92m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_YELLOW(T) "\033[93m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_BLUE(T) "\033[94m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_MAGENTA(T) "\033[95m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_CYAN(T) "\033[96m" UNVIRT_REMOVE_PARENS(T) "\033[0m" -#define UNVIRT_TERMCOL_LIGHT_WHITE(T) "\033[97m" UNVIRT_REMOVE_PARENS(T) "\033[0m" - -#if YYCC_OS == YYCC_OS_WINDOWS bool ColorfulTerminal(FILE* fs); bool UTF8Terminal(FILE* fs); -#endif - } + +#endif \ No newline at end of file diff --git a/src/YYCCommonplace.vcxproj b/src/YYCCommonplace.vcxproj index 5eaed3f..1014c67 100644 --- a/src/YYCCommonplace.vcxproj +++ b/src/YYCCommonplace.vcxproj @@ -155,8 +155,10 @@ + + @@ -165,8 +167,10 @@ + + diff --git a/src/YYCCommonplace.vcxproj.filters b/src/YYCCommonplace.vcxproj.filters index c9bd31b..6046061 100644 --- a/src/YYCCommonplace.vcxproj.filters +++ b/src/YYCCommonplace.vcxproj.filters @@ -39,6 +39,12 @@ Headers + + Headers + + + Headers + @@ -53,5 +59,11 @@ Sources + + Sources + + + Sources + \ No newline at end of file