diff --git a/bin/main.cpp b/bin/main.cpp index 52bd8ac..eb8e1a4 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -20,6 +20,7 @@ #include "security/uuid.hpp" #include "security/is_string.hpp" #include "security/is_link.hpp" +#include "string/utf8_len.hpp" // for example int f(int a) @@ -318,4 +319,16 @@ int main(int argc, char *argv[]) if (!hack::security::is_link(link)) hack::error()("no link"); } + + hack::log()("============================================================"); + hack::log()("string::utf8_size"); + + {// ex: utf8_size + std::string str = "hi hi"; + auto s = hack::string::utf8_len(str); + hack::log()(s); + + s = hack::string::utf8_len("asdf"); + hack::log()(s); + } } diff --git a/meson.build b/meson.build index 25a8b3a..338f415 100644 --- a/meson.build +++ b/meson.build @@ -1,31 +1,42 @@ project( 'hack', 'cpp', - version : '0.0.1', - default_options : ['cpp_std=c++20'] -) + version : run_command('jq', '-r', '.version', join_paths(meson.source_root(), 'props.json'), check: true).stdout().strip(), + default_options : [ + 'warning_level=1', + 'optimization=3', + 'default_library=static', + 'cpp_std=c++20', +]) add_project_arguments ( '-Wpedantic', - '-Wshadow', + '-Wno-shadow', + '-Wno-unused-but-set-variable', '-Wno-comment', - '-Wno-gnu-zero-variadic-macro-arguments', - '-Wunused-but-set-variable', + '-Wno-unused-parameter', + '-Wno-unused-value', + '-Wno-missing-field-initializers', + '-Wno-narrowing', + '-Wno-deprecated-enum-enum-conversion', + '-Wno-volatile', language: 'cpp' ) ############################################################# -deps = [] -args = [] +deps = [ + dependency('boost'), + dependency('uuid'), + subproject('nlohmann_json').get_variable('nlohmann_json_dep') +] + +args = [ + '-luuid' +] + inc = [] -deps += dependency('boost') -deps += dependency('uuid') -deps += subproject('nlohmann_json').get_variable('nlohmann_json_dep') - -args += '-luuid' - ############################################################# subdir('src') diff --git a/props.json b/props.json new file mode 100644 index 0000000..b960323 --- /dev/null +++ b/props.json @@ -0,0 +1,2 @@ +{"version": "0.0.2"} + diff --git a/src/math/max.hpp b/src/math/max.hpp new file mode 100644 index 0000000..54ab845 --- /dev/null +++ b/src/math/max.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace hack +{ + // std::common_type_t - делает сравнение по правилу тенарного оператора + // и выводит низводящий возвращающий тип. Т.е. если в качестве одного из + // параметров передалась ссылка, то произойдет низведление до типа ссылки + template> + inline RT max(T a, U b) + { + return a > b ? a : b; + } +} diff --git a/src/meson.build b/src/meson.build index 01581b5..3b2ab4f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,8 +1,6 @@ inc += include_directories('.') -subdir('string') subdir('logger') -deps += string_dep deps += logger_dep diff --git a/src/string/meson.build b/src/string/meson.build deleted file mode 100644 index f246a94..0000000 --- a/src/string/meson.build +++ /dev/null @@ -1,13 +0,0 @@ -headers = ['string.hpp', 'string_concat_helper.hpp'] -sources = ['string.cpp'] - -lib = library( - 'string', - include_directories : inc, - sources: [headers, sources] -) - -string_dep = declare_dependency( - include_directories: inc, - link_with: lib -) diff --git a/src/string/string.cpp b/src/string/string.cpp deleted file mode 100644 index 33fd61f..0000000 --- a/src/string/string.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "string.hpp" - -namespace hack::string -{ -} diff --git a/src/string/string.hpp b/src/string/string.hpp index eb5d93d..00ae825 100644 --- a/src/string/string.hpp +++ b/src/string/string.hpp @@ -5,7 +5,6 @@ #include #include - namespace hack::string { using v_str = std::vector; diff --git a/src/string/utf8_len.hpp b/src/string/utf8_len.hpp new file mode 100644 index 0000000..86cb195 --- /dev/null +++ b/src/string/utf8_len.hpp @@ -0,0 +1,10 @@ +#include +#include + +namespace hack::string +{ + inline std::size_t utf8_len(const std::string& utf8) + { + return std::wstring_convert, char32_t>{}.from_bytes(utf8).size(); + } +}