From 78169021c382aa659a8991f645178b853deeba8c Mon Sep 17 00:00:00 2001 From: Jie Date: Thu, 6 Mar 2025 13:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/main.cpp.DA64C8250A878209.idx | Bin 0 -> 608 bytes .../index/toolkit.h.B9107599F4B246CF.idx | Bin 0 -> 2072 bytes .clangd | 3 + .vscode/c_cpp_properties.json | 15 ++ .vscode/settings.json | 6 + include/ini.h | 0 include/pch.h | 9 ++ include/stringconv.h | 66 +++++++++ include/toolkit.h | 133 +----------------- include/util.h | 60 ++++++++ 10 files changed, 161 insertions(+), 131 deletions(-) create mode 100644 .cache/clangd/index/main.cpp.DA64C8250A878209.idx create mode 100644 .cache/clangd/index/toolkit.h.B9107599F4B246CF.idx create mode 100644 .clangd create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 include/ini.h create mode 100644 include/pch.h create mode 100644 include/stringconv.h create mode 100644 include/util.h diff --git a/.cache/clangd/index/main.cpp.DA64C8250A878209.idx b/.cache/clangd/index/main.cpp.DA64C8250A878209.idx new file mode 100644 index 0000000000000000000000000000000000000000..5ba0978eb2e7eb41f8a076f792a6bf232d5c757d GIT binary patch literal 608 zcmWIYbaRVfVqkDi@vO*AElFfyU|FhMPcKF{d@)VAf#+o~!5Ih@?zh z!u?ud`X$4%n|{{QkAz8=_Q}3cDXHI|l5JL`!Q6OZ^1aKG83YAW(TQzPCGomWnRqWYgelC z?U(GoyHLVp>r{)SyZJIY9!B52wejeed0B-f^6~shyqfXzAL|$ID&BG7=|T$;X|9}| zU3(@4%k?GwocQ9~uh-hsqfGw?hxJW=dGp7jrSCW06`Ar(#qL|<^s%B$j9;FC;IvyHsERd8?05T zpr*L!knXBgTz)ZSk?#Yi?aE$|yG%uwb<2OhO-pb8n9wDny7B(;jmd}4J~CeDYVu*( z@xMZR%L3+ZoVZbS>9MSvxr?*Qt4tf-eKX(Oa>YL3e))}$VvCdJJ63HoN{GF0^uED2 zK6J&*iSisxdY?ky$(_D#*=H>xc3Nj%&FVRZhJBuouJD=%ZAd<*Q`dFAaM80_k!P2h z-e0Jfd8pf*=JT@TIEjdvQbhCOHOnpbQ@epCFiE;ACS3$^!KpTK#X~ zW?6NJhd~VJ0&yL2Q!v56$;`+g!URw z;kr>7B?1)Y=HeEBIT$9*$OZNh%$dtChO9nNyiO9RT1rMr1!nucxy4aRnTuu7gf9l> zPW6MH&P7};HMNqoyJ)tz(DRR45b`bweO4_$cOWTX==GZ z)$-o*{xB=cmsK2iq4A;sD2yDB^_QNku1OIpLKA*#Yx44#j%gWC7}+Ir1FrY`JTE9m zQ@!-wx;eoSo$YACle(KTBtMjO0fmu0AI#~xH#b$FkClf zL-5q3)D&QW%EO~(q-Fu*C7CuKy4Bk~8_n`mk*yVSrN5SO@bK_+@(aPT6%UU9rvMU9 zkW&zeC&Vd)#FLPgfTwpJ9tl$kJA`{A0wtmlJb5K~Z5U7Qw0^<2zq8k)xd-L|VDwmd^~zhxyTKGG*64Vp$t}E$W@NQ>^{h7v>#m{+PpG(UR^xT*I-2mp z-Ktq?e#|$4!pLdn@{t`ff~O?zqY2M2%@6(`e+VRuoT&TV(qy_aXFR|gsBb!_J35th zJp_gxBL^cqLRea_G8@kM{s_&cMSa#S9M7a)quKOf#}O|(wE~bZvUBIT*~BNj&v?hk z!XqavCk6|lz5i{D-WbmM2y~Z*x`qxcE`U4}4NDlWC^aV$lsbxwl8b{u47k%682CYa k2;jMDS8E*XbjF2^mrqDgfS*ACCd0tMhhXv|m_i690LSsE82|tP literal 0 HcmV?d00001 diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..855844d --- /dev/null +++ b/.clangd @@ -0,0 +1,3 @@ +CompileFlags: + Add: [-std=c++23] + diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..555a306 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/clang", + "configurationProvider": "mvector-of-bool.cmake-tools", + "cppStandard": "c++23" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0728772 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.cpp": "cpp", + "type_traits": "cpp" + } +} \ No newline at end of file diff --git a/include/ini.h b/include/ini.h new file mode 100644 index 0000000..e69de29 diff --git a/include/pch.h b/include/pch.h new file mode 100644 index 0000000..f72c596 --- /dev/null +++ b/include/pch.h @@ -0,0 +1,9 @@ +#ifndef PCH_H +#define PCH_H + +#include +#include +#include +#include + +#endif diff --git a/include/stringconv.h b/include/stringconv.h new file mode 100644 index 0000000..b24b9ef --- /dev/null +++ b/include/stringconv.h @@ -0,0 +1,66 @@ +#ifndef STRINGCONV_H +#define STRINGCONV_H +#include +#include +#include +#include +#include +#include +#include + +namespace ranges = std::ranges; +namespace views = std::ranges::views; +constexpr size_t buffer_size = 32; + +namespace string{ + template + requires std::is_same_v || std::is_same_v + inline std::string replace_string(const std::string &str, T d, T e) + { + std::string result = str; + if (d == e) + { + return result; + } + size_t len = 0; + while (true) + { + auto pos = result.find(d); + if (pos == std::string::npos) + { + return result; + } + if constexpr (std::is_same_v) + { + len = std::strlen(d); + } + else + { + len = d.length(); + } + result = result.replace(pos, len, e); + } + } + + template + requires std::is_same_v || + std::is_same_v + inline std::vector split(T str, T d) + { + auto v = views::split(str, d) | views::transform([](auto word) + { return T(word.begin(), word.end()); }); + return std::vector(v.begin(), v.end()); + } + + template + requires std::is_same_v || std::is_same_v + double round(T value, int c){ + auto temp = 1; + for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ranges = std::ranges; -namespace views = std::ranges::views; - -// use for to_chars -constexpr size_t buffer_size = 32; - -template -concept _num_type = requires { - std::is_same_v || - std::is_same_v || - std::is_same_v || - std::is_same_v; -}; - -namespace toolkit -{ - enum class num_type{ - BIN, - HEX, - OCT, - DEC - } - - template - inline std::expected to_string(T value) - { - if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) - { - char buffer[buffer_size]; - auto res = std::to_chars(buffer, buffer + buffer_size, value); - if (res.ec != std::errc()) - { - return std::unexpected(std::make_error_code(res.ec).message()); - } - return std::string(buffer, res.ptr - buffer); - } - else if constexpr (std::is_same_v::type, - char *>) - { - return std::to_string(value); - } - } - - template // requires std::is_same_v - inline std::expected stoi(const std::string &str) - { - T value; - auto res = std::from_chars(str.c_str(), str.c_str() + str.size(), value); - if (res.ec != std::errc()) - { - return std::unexpected(std::make_error_code(res.ec).message()); - } - return value; - } - - template - requires std::is_same_v || std::is_same_v - inline std::string replace_string(const std::string &str, T d, T e) - { - std::string result = str; - if (d == e) - { - return result; - } - size_t len = 0; - while (true) - { - auto pos = result.find(d); - if (pos == std::string::npos) - { - return result; - } - if constexpr (std::is_same_v) - { - len = std::strlen(d); - } - else - { - len = d.length(); - } - result = result.replace(pos, len, e); - } - } - - template - requires std::is_same_v || - std::is_same_v - inline std::vector split(T str, T d) - { - auto v = views::split(str, d) | views::transform([](auto word) - { return T(word.begin(), word.end()); }); - return std::vector(v.begin(), v.end()); - } - - template - requires std::is_same_v || std::is_same_v - double round(T value, int c){ - auto temp = 1; - for(int i=0;i +#include +#include + +namespace util{ + +template +inline std::expected to_string(T value) +{ + if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) + { + char buffer[buffer_size]; + auto res = std::to_chars(buffer, buffer + buffer_size, value); + if (res.ec != std::errc()) + { + return std::unexpected(std::make_error_code(res.ec).message()); + } + return std::string(buffer, res.ptr - buffer); + } + else if constexpr (std::is_same_v::type, + char *>) + { + return std::to_string(value); + } +} + +template // requires std::is_same_v +inline std::expected stoi(const std::string &str) +{ + T value; + auto res = std::from_chars(str.c_str(), str.c_str() + str.size(), value); + if (res.ec != std::errc()) + { + return std::unexpected(std::make_error_code(res.ec).message()); + } + return value; +} + + inline std::string get_time_now(){ + auto time_now = std::chrono::system_clock::now(); + auto now_c = std::chrono::system_clock::to_time_t(time_now); + char buffer[32]; +#if defined(_WIN32) || defined(_WIN64) + auto _ = ctime_s(buffer, 32, &now_c); +#elif defined(__linux__) + auto _ = ctime_r(&now_c, buffer); +#endif + auto result = std::string(buffer); + result = string::replace_string(result, "\n", ""); + return std::move(result); + } + +} + + + +#endif