Skip to content

Commit 0861d36

Browse files
committed
1.7.3
- Added several string functions. --- - Добавлено несколько строковых функций.
1 parent 91a2f79 commit 0861d36

12 files changed

Lines changed: 361 additions & 31 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include(FetchContent)
55

66
project(
77
simstr
8-
VERSION 1.7.2
8+
VERSION 1.7.3
99
DESCRIPTION "Yet another modern C++ string library"
1010
HOMEPAGE_URL "https://github.com/orefkov/simstr"
1111
LANGUAGES CXX
@@ -131,6 +131,9 @@ if(SIMSTR_BUILD_TESTS)
131131
if(TARGET gtest)
132132
target_compile_features(gtest PUBLIC cxx_std_23)
133133
target_compile_features(gtest_main PUBLIC cxx_std_23)
134+
if (CLANG_COMPILER)
135+
target_compile_options(gtest PRIVATE -Wno-error=character-conversion)
136+
endif(CLANG_COMPILER)
134137
endif()
135138
endif()
136139

docs/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "simstr"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 1.7.2
51+
PROJECT_NUMBER = 1.7.3
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewers a

docs/Doxyfile_ru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "simstr"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 1.7.2
51+
PROJECT_NUMBER = 1.7.3
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewers a

include/simstr/simple_unicode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
3-
* ver. 1.7.2
3+
* ver. 1.7.3
44
*/
55

66
#pragma once

include/simstr/sstring.h

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* ver. 1.7.2
2+
* ver. 1.7.3
33
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
44
* Классы для работы со строками
55
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com
@@ -373,6 +373,87 @@ class str_algs : public str_src_algs<K, StrRef, Impl, Mutable> {
373373
constexpr void as_number(T& t) const {
374374
base::as_number(t);
375375
}
376+
/*!
377+
* @ru @brief Получить строку без префикса, если она начинается с него без учёта регистра Unicode символов до 0xFFFF.
378+
* @tparam R - желаемый тип строкового объекта, по умолчанию str_piece.
379+
* @param prefix - искомый префикс.
380+
* @return constexpr std::optional<R> - если строка начинается с указанного префикса без учёта регистра символов до 0xFFFF,
381+
* возвращает часть строки без этого префикса, иначе пустое значение.
382+
* @en @brief Get a string without a prefix if it starts with it, insensitive to Unicode characters up to 0xFFFF.
383+
* @tparam R - the desired type of string object, defaults to str_piece.
384+
* @param prefix - the prefix to search for.
385+
* @return constexpr std::optional<R> - if the string begins with the specified prefix, insensitive to characters up to 0xFFFF,
386+
* returns the part of the string without this prefix, otherwise empty.
387+
*/
388+
template<typename R = str_piece>
389+
constexpr std::optional<R> strip_prefix_iu(str_piece prefix) const {
390+
if (starts_with_iu(prefix)) {
391+
return R{operator()(prefix.length())};
392+
}
393+
return {};
394+
}
395+
/*!
396+
* @ru @brief Получить строку без суффикса, если она заканчивается им без учёта регистра Unicode символов до 0xFFFF.
397+
* @tparam R - желаемый тип строкового объекта, по умолчанию str_piece.
398+
* @param suffix - искомый суффикс.
399+
* @return constexpr std::optional<R> - если строка заканчивается указанным суффиксом без учёта регистра символов до 0xFFFF,
400+
* возвращает часть строки без него, иначе пустое значение.
401+
* @en @brief Get a string without a suffix if it ends with one in case-insensitive Unicode characters up to 0xFFFF.
402+
* @tparam R - the desired type of string object, defaults to str_piece.
403+
* @param suffix - the suffix you are looking for.
404+
* @return constexpr std::optional<R> - if the string ends with the specified suffix, insensitive to characters up to 0xFFFF,
405+
* returns part of the string without it, otherwise empty.
406+
*/
407+
template<typename R = str_piece>
408+
constexpr std::optional<R> strip_suffix_iu(str_piece suffix) const {
409+
if (ends_with_iu(suffix)) {
410+
return R{operator()(0, -suffix.length())};
411+
}
412+
return {};
413+
}
414+
/*!
415+
* @ru @brief Возвращает строку, в которой удалено начало строки, если она начинается с указанного префикса без учёта регистра Unicode символов до 0xFFFF.
416+
* @tparam R - желаемый тип строки, по умолчанию str_src.
417+
* @param prefix - искомый префикс.
418+
* @param max_count - до сколько раз можно удалять префикс, 0 - без ограничений.
419+
* @return R - Копию строки, в которой удалено начало, если она начинается с этого префикса без учёта регистра символов до 0xFFFF.
420+
* @en @brief Returns a string with the beginning of the string removed if it begins with the specified prefix, case-insensitive Unicode characters up to 0xFFFF.
421+
* @tparam R - desired string type, default str_src.
422+
* @param prefix - the prefix to search for.
423+
* @param max_count - up to how many times a prefix can be removed, 0 - no restrictions.
424+
* @return R - A copy of the string with the beginning removed if it starts with this prefix, insensitive to 0xFFFF.
425+
*/
426+
template<typename R = str_piece>
427+
constexpr R trimmed_prefix_iu(str_piece prefix, size_t max_count = 0) const {
428+
str_piece res = *this;
429+
while(res.starts_with_iu(prefix)) {
430+
res = res(prefix.length());
431+
if (--max_count == 0) {
432+
break;
433+
}
434+
}
435+
return res;
436+
}
437+
/*!
438+
* @ru @brief Возвращает строку, в которой удалён конец строки, если она заканчивается указанным суффиксом без учёта регистра Unicode символов до 0xFFFF.
439+
* @tparam R - желаемый тип строки, по умолчанию str_src.
440+
* @param suffix - искомый суффикс.
441+
* @param max_count - до сколько раз можно удалять суффикс, 0 - без ограничений.
442+
* @return R - Копию строки, в которой удалён конец, если она заканчивается этим суффиксом без учёта регистра символов до 0xFFFF.
443+
* @en @brief Returns a string with the end of the string removed if it ends with the specified suffix of case-insensitive Unicode characters up to 0xFFFF.
444+
* @tparam R - desired string type, default str_src.
445+
* @param suffix - the suffix you are looking for.
446+
* @param max_count - up to how many times a suffix can be removed, 0 - no restrictions.
447+
* @return R - A copy of the string with the end removed if it ends with this suffix, insensitive to 0xFFFF.
448+
*/
449+
template<typename R = str_piece>
450+
constexpr R trimmed_suffix_iu(str_piece suffix) const {
451+
str_piece res = *this;
452+
while(res.ends_with_iu(suffix)) {
453+
res = res(0, -suffix.length());
454+
}
455+
return res;
456+
}
376457
};
377458

378459
/*

0 commit comments

Comments
 (0)