add utf8 string size and remove string dep
This commit is contained in:
parent
092dcea16b
commit
b501d98f8a
13
bin/main.cpp
13
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);
|
||||
}
|
||||
}
|
||||
|
39
meson.build
39
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')
|
||||
|
2
props.json
Normal file
2
props.json
Normal file
@ -0,0 +1,2 @@
|
||||
{"version": "0.0.2"}
|
||||
|
15
src/math/max.hpp
Normal file
15
src/math/max.hpp
Normal 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;
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
inc += include_directories('.')
|
||||
|
||||
subdir('string')
|
||||
subdir('logger')
|
||||
|
||||
deps += string_dep
|
||||
deps += logger_dep
|
||||
|
||||
|
@ -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
|
||||
)
|
@ -1,5 +0,0 @@
|
||||
#include "string.hpp"
|
||||
|
||||
namespace hack::string
|
||||
{
|
||||
}
|
@ -5,7 +5,6 @@
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
|
||||
|
||||
namespace hack::string
|
||||
{
|
||||
using v_str = std::vector<std::string>;
|
||||
|
10
src/string/utf8_len.hpp
Normal file
10
src/string/utf8_len.hpp
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user