add utf8 string size and remove string dep

This commit is contained in:
chatlanin 2023-04-04 10:53:36 +03:00
parent 092dcea16b
commit b501d98f8a
9 changed files with 65 additions and 35 deletions

View File

@ -20,6 +20,7 @@
#include "security/uuid.hpp" #include "security/uuid.hpp"
#include "security/is_string.hpp" #include "security/is_string.hpp"
#include "security/is_link.hpp" #include "security/is_link.hpp"
#include "string/utf8_len.hpp"
// for example // for example
int f(int a) int f(int a)
@ -318,4 +319,16 @@ int main(int argc, char *argv[])
if (!hack::security::is_link(link)) if (!hack::security::is_link(link))
hack::error()("no 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);
}
} }

View File

@ -1,31 +1,42 @@
project( project(
'hack', 'hack',
'cpp', 'cpp',
version : '0.0.1', version : run_command('jq', '-r', '.version', join_paths(meson.source_root(), 'props.json'), check: true).stdout().strip(),
default_options : ['cpp_std=c++20'] default_options : [
) 'warning_level=1',
'optimization=3',
'default_library=static',
'cpp_std=c++20',
])
add_project_arguments ( add_project_arguments (
'-Wpedantic', '-Wpedantic',
'-Wshadow', '-Wno-shadow',
'-Wno-unused-but-set-variable',
'-Wno-comment', '-Wno-comment',
'-Wno-gnu-zero-variadic-macro-arguments', '-Wno-unused-parameter',
'-Wunused-but-set-variable', '-Wno-unused-value',
'-Wno-missing-field-initializers',
'-Wno-narrowing',
'-Wno-deprecated-enum-enum-conversion',
'-Wno-volatile',
language: 'cpp' language: 'cpp'
) )
############################################################# #############################################################
deps = [] deps = [
args = [] dependency('boost'),
dependency('uuid'),
subproject('nlohmann_json').get_variable('nlohmann_json_dep')
]
args = [
'-luuid'
]
inc = [] inc = []
deps += dependency('boost')
deps += dependency('uuid')
deps += subproject('nlohmann_json').get_variable('nlohmann_json_dep')
args += '-luuid'
############################################################# #############################################################
subdir('src') subdir('src')

2
props.json Normal file
View File

@ -0,0 +1,2 @@
{"version": "0.0.2"}

15
src/math/max.hpp Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <type_traits>
namespace hack
{
// std::common_type_t - делает сравнение по правилу тенарного оператора
// и выводит низводящий возвращающий тип. Т.е. если в качестве одного из
// параметров передалась ссылка, то произойдет низведление до типа ссылки
template<typename T, typename U, typename RT = std::common_type_t<T, U>>
inline RT max(T a, U b)
{
return a > b ? a : b;
}
}

View File

@ -1,8 +1,6 @@
inc += include_directories('.') inc += include_directories('.')
subdir('string')
subdir('logger') subdir('logger')
deps += string_dep
deps += logger_dep deps += logger_dep

View File

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

View File

@ -1,5 +0,0 @@
#include "string.hpp"
namespace hack::string
{
}

View File

@ -5,7 +5,6 @@
#include <iostream> #include <iostream>
#include <tuple> #include <tuple>
namespace hack::string namespace hack::string
{ {
using v_str = std::vector<std::string>; using v_str = std::vector<std::string>;

10
src/string/utf8_len.hpp Normal file
View File

@ -0,0 +1,10 @@
#include <locale>
#include <codecvt>
namespace hack::string
{
inline std::size_t utf8_len(const std::string& utf8)
{
return std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>{}.from_bytes(utf8).size();
}
}