This commit is contained in:
yyc12345 2024-04-26 15:37:28 +08:00
parent b6cffd8a97
commit c9152bffa8
13 changed files with 171 additions and 71 deletions

0
src/DialogHelper.cpp Normal file
View File

28
src/DialogHelper.hpp Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include "YYCCInternal.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include <string>
#include <vector>
#include "WinImportPrefix.hpp"
#include <Windows.h>
#include "WinImportSuffix.hpp"
namespace YYCC::DialogHelper {
struct FileDialogFilterEntry {
std::string FileType;
std::string FileExtension;
};
using FileDialogFilter = std::vector<FileDialogFilterEntry>;
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<std::string>& ret);
bool SaveFileDialog(HWND parent, const char* title, const FileDialogFilter& filter, std::string& ret);
bool OpenFolderDialog(HWND parent, std::string& ret);
}
#endif

View File

@ -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

View File

@ -1,25 +1,30 @@
#pragma once
#include <string>
#include "YYCCInternal.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include <string>
#include "WinImportPrefix.hpp"
#include <Windows.h>
#include <fileapi.h>
#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
}

View File

@ -1,17 +1,19 @@
#include "IOHelper.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include "EncodingHelper.hpp"
#include <cstdio>
#include <iostream>
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

View File

@ -1,8 +1,14 @@
#pragma once
#include "YYCCInternal.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include <string>
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

0
src/ParserHelper.cpp Normal file
View File

12
src/ParserHelper.hpp Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <string>
#include <cinttypes>
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);
}

View File

@ -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);
}

View File

@ -1,17 +1,14 @@
#include "TerminalHelper.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include "WinImportPrefix.hpp"
#include <Windows.h>
#include <io.h>
#include <fcntl.h>
#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

View File

@ -1,57 +1,54 @@
#pragma once
#include "YYCCInternal.hpp"
#if YYCC_OS == YYCC_OS_WINDOWS
#include <cstdio>
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

View File

@ -155,8 +155,10 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="DialogHelper.hpp" />
<ClInclude Include="EncodingHelper.hpp" />
<ClInclude Include="IOHelper.hpp" />
<ClInclude Include="ParserHelper.hpp" />
<ClInclude Include="StringHelper.hpp" />
<ClInclude Include="TerminalHelper.hpp" />
<ClInclude Include="WinImportPrefix.hpp" />
@ -165,8 +167,10 @@
<ClInclude Include="YYCCommonplace.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DialogHelper.cpp" />
<ClCompile Include="EncodingHelper.cpp" />
<ClCompile Include="IOHelper.cpp" />
<ClCompile Include="ParserHelper.cpp" />
<ClCompile Include="StringHelper.cpp" />
<ClCompile Include="TerminalHelper.cpp" />
</ItemGroup>

View File

@ -39,6 +39,12 @@
<ClInclude Include="YYCCInternal.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="ParserHelper.hpp">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="DialogHelper.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="StringHelper.cpp">
@ -53,5 +59,11 @@
<ClCompile Include="IOHelper.cpp">
<Filter>Sources</Filter>
</ClCompile>
<ClCompile Include="ParserHelper.cpp">
<Filter>Sources</Filter>
</ClCompile>
<ClCompile Include="DialogHelper.cpp">
<Filter>Sources</Filter>
</ClCompile>
</ItemGroup>
</Project>