From b6cffd8a973f8e49a87c216b35aee7b6d0f9c457 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 25 Apr 2024 10:38:13 +0800 Subject: [PATCH] first commit --- .gitignore | 375 ++++++++++++++++++++++++++++ README.md | 9 + YYCCommonplace.sln | 44 ++++ src/EncodingHelper.cpp | 49 ++++ src/EncodingHelper.hpp | 25 ++ src/IOHelper.cpp | 27 ++ src/IOHelper.hpp | 8 + src/StringHelper.cpp | 67 +++++ src/StringHelper.hpp | 13 + src/TerminalHelper.cpp | 39 +++ src/TerminalHelper.hpp | 57 +++++ src/WinImportPrefix.hpp | 14 ++ src/WinImportSuffix.hpp | 11 + src/YYCCInternal.hpp | 11 + src/YYCCommonplace.hpp | 6 + src/YYCCommonplace.vcxproj | 176 +++++++++++++ src/YYCCommonplace.vcxproj.filters | 57 +++++ testbench/Testbench.vcxproj | 171 +++++++++++++ testbench/Testbench.vcxproj.filters | 22 ++ testbench/main.cpp | 0 20 files changed, 1181 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 YYCCommonplace.sln create mode 100644 src/EncodingHelper.cpp create mode 100644 src/EncodingHelper.hpp create mode 100644 src/IOHelper.cpp create mode 100644 src/IOHelper.hpp create mode 100644 src/StringHelper.cpp create mode 100644 src/StringHelper.hpp create mode 100644 src/TerminalHelper.cpp create mode 100644 src/TerminalHelper.hpp create mode 100644 src/WinImportPrefix.hpp create mode 100644 src/WinImportSuffix.hpp create mode 100644 src/YYCCInternal.hpp create mode 100644 src/YYCCommonplace.hpp create mode 100644 src/YYCCommonplace.vcxproj create mode 100644 src/YYCCommonplace.vcxproj.filters create mode 100644 testbench/Testbench.vcxproj create mode 100644 testbench/Testbench.vcxproj.filters create mode 100644 testbench/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c64b424 --- /dev/null +++ b/.gitignore @@ -0,0 +1,375 @@ +# -------------------- VSCode -------------------- +.vscode/ + +# -------------------- CMake -------------------- +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# -------------------- Visual Studio -------------------- +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ +Temp/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..95654e0 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# YYC Commonplace + +During the development of a few projects, I gradually understand how Windows make the compromise with the code written by its old developers, and what is developer wanted in contemporary C++ standard library under Windows environment. So I create this static library for all of my C++ project, After this, I do not need to write these duplicated code in each project. I can use a clear and easy way to manage these codes. I can easily fix issues found in project using this library by updating a single project, rather than fixing these duplicated code in each project one by one because all of them share the same implementations. + +This project mainly is served for my personal use. But I would be honored if you would like to use this in your project. Almost of my projects, except some critical projects (they will copy this project implementations into their own project scope to eliminate non-common library dependency), will gradually adapt to this project and drop their own individual implementations. + +This project includes Visual Studio project file and CMake support at the same time. So that at least I can use one of them freely. + +**WIP. Do not use it now.** diff --git a/YYCCommonplace.sln b/YYCCommonplace.sln new file mode 100644 index 0000000..35a752f --- /dev/null +++ b/YYCCommonplace.sln @@ -0,0 +1,44 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33529.622 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "YYCCommonplace", "src\YYCCommonplace.vcxproj", "{FA5E5834-54DF-4CA1-8F49-9533BE13467A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Testbench", "testbench\Testbench.vcxproj", "{3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}" + ProjectSection(ProjectDependencies) = postProject + {FA5E5834-54DF-4CA1-8F49-9533BE13467A} = {FA5E5834-54DF-4CA1-8F49-9533BE13467A} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Debug|x64.ActiveCfg = Debug|x64 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Debug|x64.Build.0 = Debug|x64 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Debug|x86.ActiveCfg = Debug|Win32 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Debug|x86.Build.0 = Debug|Win32 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Release|x64.ActiveCfg = Release|x64 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Release|x64.Build.0 = Release|x64 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Release|x86.ActiveCfg = Release|Win32 + {FA5E5834-54DF-4CA1-8F49-9533BE13467A}.Release|x86.Build.0 = Release|Win32 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Debug|x64.ActiveCfg = Debug|x64 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Debug|x64.Build.0 = Debug|x64 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Debug|x86.ActiveCfg = Debug|Win32 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Debug|x86.Build.0 = Debug|Win32 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Release|x64.ActiveCfg = Release|x64 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Release|x64.Build.0 = Release|x64 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Release|x86.ActiveCfg = Release|Win32 + {3A6F9D19-5DF0-4EB9-A227-DCC9A7B25A31}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A05D6B8D-5374-41E9-9010-8ACB16391AE2} + EndGlobalSection +EndGlobal diff --git a/src/EncodingHelper.cpp b/src/EncodingHelper.cpp new file mode 100644 index 0000000..d677ece --- /dev/null +++ b/src/EncodingHelper.cpp @@ -0,0 +1,49 @@ +#include "EncodingHelper.hpp" + +namespace YYCC::EncodingHelper { + + bool WcharToChar(const wchar_t* src, std::string& dest, const UINT codepage) { + int count, write_result; + + //converter to CHAR + count = WideCharToMultiByte(codepage, 0, src, -1, NULL, 0, NULL, NULL); + if (count <= 0) return false; + + dest.resize(count - 1); + write_result = WideCharToMultiByte(codepage, 0, src, -1, dest.data(), count, NULL, NULL); + if (write_result <= 0) return false; + + return true; + } + bool WcharToChar(const std::wstring& src, std::string& dest, const UINT codepage) { + return WcharToChar(src.c_str(), dest, codepage); + } + + bool CharToWchar(const char* src, std::wstring& dest, const UINT codepage) { + int wcount, write_result; + + // convert to WCHAR + wcount = MultiByteToWideChar(codepage, 0, src, -1, NULL, 0); + if (wcount <= 0) return false; + + dest.resize(wcount - 1); + write_result = MultiByteToWideChar(codepage, 0, src, -1, dest.data(), wcount); + if (write_result <= 0) return false; + + return true; + } + bool CharToWchar(const std::string& src, std::wstring& dest, const UINT codepage) { + return CharToWchar(src.c_str(), dest, codepage); + } + + bool CharToChar(const char* src, std::string& dest, const UINT src_codepage, const 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) { + return CharToChar(src.c_str(), dest, src_codepage, dest_codepage); + } + +} diff --git a/src/EncodingHelper.hpp b/src/EncodingHelper.hpp new file mode 100644 index 0000000..444e369 --- /dev/null +++ b/src/EncodingHelper.hpp @@ -0,0 +1,25 @@ +#pragma once +#include + +#include "YYCCInternal.hpp" +#if YYCC_OS == YYCC_OS_WINDOWS +#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 CharToWchar(const char* src, std::wstring& dest, const UINT codepage); + bool CharToWchar(const std::string& src, std::wstring& dest, const 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); + +#endif +} diff --git a/src/IOHelper.cpp b/src/IOHelper.cpp new file mode 100644 index 0000000..f73c353 --- /dev/null +++ b/src/IOHelper.cpp @@ -0,0 +1,27 @@ +#include "IOHelper.hpp" +#include "EncodingHelper.hpp" +#include +#include + +namespace YYCC::IOHelper { + + void GetCmdLine(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) { + std::wstring wmode, wpath; + bool suc = YYCC::EncodingHelper::CharToWchar(u8_mode, wmode, CP_UTF8); + suc = suc && YYCC::EncodingHelper::CharToWchar(u8_filepath, wpath, CP_UTF8); + + if (suc) { + return _wfopen(wpath.c_str(), wmode.c_str()); + } else { + // fallback + return std::fopen(u8_filepath, u8_mode); + } + } + +} diff --git a/src/IOHelper.hpp b/src/IOHelper.hpp new file mode 100644 index 0000000..23f8dd0 --- /dev/null +++ b/src/IOHelper.hpp @@ -0,0 +1,8 @@ +#pragma once +#include + +namespace YYCC::IOHelper { + + void GetCmdLine(std::string&); + FILE* UTF8FOpen(const char* u8_filepath, const char* u8_mode); +} diff --git a/src/StringHelper.cpp b/src/StringHelper.cpp new file mode 100644 index 0000000..7b2fa7d --- /dev/null +++ b/src/StringHelper.cpp @@ -0,0 +1,67 @@ +#include "StringHelper.hpp" + +namespace YYCC::StringHelper { + + bool Printf(std::string& strl, const char* format, ...) { + va_list argptr; + va_start(argptr, format); + bool ret = VPrintf(strl, format, argptr); + va_end(argptr); + return ret; + } + + bool VPrintf(std::string& strl, const char* format, va_list argptr) { + va_list args1; + va_copy(args1, argptr); + va_list args2; + va_copy(args2, argptr); + + // the return value is desired char count without NULL terminal. + // minus number means error + int count = std::vsnprintf(nullptr, 0, format, args1); + if (count < 0) { + // invalid length returned by vsnprintf. + return false; + } + va_end(args1); + + // resize std::string to desired count. + // and pass its length + 1 to std::vsnprintf, + // because std::vsnprintf only can write "buf_size - 1" chars with a trailing NULL. + // however std::vsnprintf already have a trailing NULL, so we plus 1 for it. + strl.resize(count); + int write_result = std::vsnprintf(strl.data(), strl.size() + 1, format, args2); + va_end(args2); + + if (write_result < 0 || write_result > count) { + // invalid write result in vsnprintf. + return false; + } + + return true; + } + + + std::string Printf(const char* format, ...) { + std::string ret; + + va_list argptr; + va_start(argptr, format); + VPrintf(ret, format, argptr); + va_end(argptr); + + return ret; + } + + std::string VPrintf(const char* format, va_list argptr) { + std::string ret; + + va_list argcpy; + va_copy(argcpy, argptr); + VPrintf(ret, format, argcpy); + va_end(argcpy); + + return ret; + } + +} diff --git a/src/StringHelper.hpp b/src/StringHelper.hpp new file mode 100644 index 0000000..1243642 --- /dev/null +++ b/src/StringHelper.hpp @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +namespace YYCC::StringHelper { + + bool Printf(std::string& strl, const char* format, ...); + bool VPrintf(std::string& strl, const char* format, va_list argptr); + + std::string Printf(const char* format, ...); + std::string VPrintf(const char* format, va_list argptr); + +} diff --git a/src/TerminalHelper.cpp b/src/TerminalHelper.cpp new file mode 100644 index 0000000..bb2afa4 --- /dev/null +++ b/src/TerminalHelper.cpp @@ -0,0 +1,39 @@ +#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; + + HANDLE h_output; + DWORD dw_mode; + + h_output = (HANDLE)_get_osfhandle(_fileno(fs)); + if (!GetConsoleMode(h_output, &dw_mode)) return false; + if (!SetConsoleMode(h_output, dw_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) return false; + + return true; + } + + bool UTF8Terminal(FILE* fs) { + if (!SetConsoleCP(CP_UTF8)) return false; + if (!SetConsoleOutputCP(CP_UTF8)) return false; + + /*_setmode(_fileno(stdout), _O_U8TEXT);*/ + _setmode(_fileno(fs), _O_U16TEXT); + return true; + } + +#endif + +} diff --git a/src/TerminalHelper.hpp b/src/TerminalHelper.hpp new file mode 100644 index 0000000..6f2d269 --- /dev/null +++ b/src/TerminalHelper.hpp @@ -0,0 +1,57 @@ +#pragma once +#include "YYCCInternal.hpp" +#include + +namespace YYCC::TerminalHelper { + +#define UNVIRT_REMOVE_PARENS_IMPL(...) __VA_ARGS__ +#define UNVIRT_REMOVE_PARENS(T) UNVIRT_REMOVE_PARENS_IMPL T + + +#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 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 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 + +} diff --git a/src/WinImportPrefix.hpp b/src/WinImportPrefix.hpp new file mode 100644 index 0000000..71d76f1 --- /dev/null +++ b/src/WinImportPrefix.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "YYCCInternal.hpp" + +#if YYCC_OS == YYCC_OS_WINDOWS + +// Windows also will generate following macros +// which may cause the function sign is different in Windows and other platforms. +// So we simply remove them. +#undef GetObject +#undef GetClassName +#undef LoadImage +#undef GetTempPath + +#endif \ No newline at end of file diff --git a/src/WinImportSuffix.hpp b/src/WinImportSuffix.hpp new file mode 100644 index 0000000..3dab6b0 --- /dev/null +++ b/src/WinImportSuffix.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "YYCCInternal.hpp" + +#if YYCC_OS == YYCC_OS_WINDOWS + +// Define 2 macros to disallow Windows generate MIN and MAX macros +// which cause std::min and std::max can not function as normal. +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX + +#endif \ No newline at end of file diff --git a/src/YYCCInternal.hpp b/src/YYCCInternal.hpp new file mode 100644 index 0000000..9d8e270 --- /dev/null +++ b/src/YYCCInternal.hpp @@ -0,0 +1,11 @@ +#pragma once + +// Define operating system macros +#define YYCC_OS_WINDOWS 2 +#define YYCC_OS_LINUX 3 +// Check current operating system. +#if defined(_WIN32) +#define YYCC_OS YYCC_OS_WINDOWS +#else +#define YYCC_OS YYCC_OS_LINUX +#endif diff --git a/src/YYCCommonplace.hpp b/src/YYCCommonplace.hpp new file mode 100644 index 0000000..aab2732 --- /dev/null +++ b/src/YYCCommonplace.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include "YYCCInternal.hpp" + +#include "StringHelper.hpp" +#include "EncodingHelper.hpp" diff --git a/src/YYCCommonplace.vcxproj b/src/YYCCommonplace.vcxproj new file mode 100644 index 0000000..5eaed3f --- /dev/null +++ b/src/YYCCommonplace.vcxproj @@ -0,0 +1,176 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {fa5e5834-54df-4ca1-8f49-9533be13467a} + YYCCommonplace + 10.0 + + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + true + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/YYCCommonplace.vcxproj.filters b/src/YYCCommonplace.vcxproj.filters new file mode 100644 index 0000000..c9bd31b --- /dev/null +++ b/src/YYCCommonplace.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + Headers + + + + + Sources + + + Sources + + + Sources + + + Sources + + + \ No newline at end of file diff --git a/testbench/Testbench.vcxproj b/testbench/Testbench.vcxproj new file mode 100644 index 0000000..1d337c8 --- /dev/null +++ b/testbench/Testbench.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {3a6f9d19-5df0-4eb9-a227-dcc9a7b25a31} + Testbench + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + true + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + false + $(ProjectDir)bin\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\ + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + $(SolutionDir)src\bin\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories) + YYCCommonplace.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + true + true + $(SolutionDir)src\bin\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories) + YYCCommonplace.lib;%(AdditionalDependencies) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + $(SolutionDir)src\bin\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories) + YYCCommonplace.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + /utf-8 %(AdditionalOptions) + + + Console + true + true + true + $(SolutionDir)src\bin\$(Platform)\$(Configuration)\;%(AdditionalLibraryDirectories) + YYCCommonplace.lib;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/testbench/Testbench.vcxproj.filters b/testbench/Testbench.vcxproj.filters new file mode 100644 index 0000000..efff4b3 --- /dev/null +++ b/testbench/Testbench.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Sources + + + \ No newline at end of file diff --git a/testbench/main.cpp b/testbench/main.cpp new file mode 100644 index 0000000..e69de29