diff --git a/CMakeLists.txt b/CMakeLists.txt index 67841d8..d5d80b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(FetchContent) project( simstr - VERSION 1.7.2 + VERSION 1.7.3 DESCRIPTION "Yet another modern C++ string library" HOMEPAGE_URL "https://github.com/orefkov/simstr" LANGUAGES CXX @@ -131,6 +131,9 @@ if(SIMSTR_BUILD_TESTS) if(TARGET gtest) target_compile_features(gtest PUBLIC cxx_std_23) target_compile_features(gtest_main PUBLIC cxx_std_23) + if (CLANG_COMPILER) + target_compile_options(gtest PRIVATE -Wno-error=character-conversion) + endif(CLANG_COMPILER) endif() endif() diff --git a/docs/Doxyfile b/docs/Doxyfile index d2157dd..0e4e2c4 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = "simstr" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.7.2 +PROJECT_NUMBER = 1.7.3 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewers a diff --git a/docs/Doxyfile_ru b/docs/Doxyfile_ru index 7610540..04d6600 100644 --- a/docs/Doxyfile_ru +++ b/docs/Doxyfile_ru @@ -48,7 +48,7 @@ PROJECT_NAME = "simstr" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.7.2 +PROJECT_NUMBER = 1.7.3 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewers a diff --git a/include/simstr/simple_unicode.h b/include/simstr/simple_unicode.h index 4216d52..96c8f49 100644 --- a/include/simstr/simple_unicode.h +++ b/include/simstr/simple_unicode.h @@ -1,6 +1,6 @@ /* * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com - * ver. 1.7.2 + * ver. 1.7.3 */ #pragma once diff --git a/include/simstr/sstring.h b/include/simstr/sstring.h index 0da2585..adf2308 100644 --- a/include/simstr/sstring.h +++ b/include/simstr/sstring.h @@ -1,5 +1,5 @@ /* -* ver. 1.7.2 +* ver. 1.7.3 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Классы для работы со строками * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com @@ -373,6 +373,87 @@ public: constexpr void as_number(T& t) const { base::as_number(t); } + /*! + * @ru @brief Получить строку без префикса, если она начинается с него без учёта регистра Unicode символов до 0xFFFF. + * @tparam R - желаемый тип строкового объекта, по умолчанию str_piece. + * @param prefix - искомый префикс. + * @return constexpr std::optional - если строка начинается с указанного префикса без учёта регистра символов до 0xFFFF, + * возвращает часть строки без этого префикса, иначе пустое значение. + * @en @brief Get a string without a prefix if it starts with it, insensitive to Unicode characters up to 0xFFFF. + * @tparam R - the desired type of string object, defaults to str_piece. + * @param prefix - the prefix to search for. + * @return constexpr std::optional - if the string begins with the specified prefix, insensitive to characters up to 0xFFFF, + * returns the part of the string without this prefix, otherwise empty. + */ + template + constexpr std::optional strip_prefix_iu(str_piece prefix) const { + if (starts_with_iu(prefix)) { + return R{operator()(prefix.length())}; + } + return {}; + } + /*! + * @ru @brief Получить строку без суффикса, если она заканчивается им без учёта регистра Unicode символов до 0xFFFF. + * @tparam R - желаемый тип строкового объекта, по умолчанию str_piece. + * @param suffix - искомый суффикс. + * @return constexpr std::optional - если строка заканчивается указанным суффиксом без учёта регистра символов до 0xFFFF, + * возвращает часть строки без него, иначе пустое значение. + * @en @brief Get a string without a suffix if it ends with one in case-insensitive Unicode characters up to 0xFFFF. + * @tparam R - the desired type of string object, defaults to str_piece. + * @param suffix - the suffix you are looking for. + * @return constexpr std::optional - if the string ends with the specified suffix, insensitive to characters up to 0xFFFF, + * returns part of the string without it, otherwise empty. + */ + template + constexpr std::optional strip_suffix_iu(str_piece suffix) const { + if (ends_with_iu(suffix)) { + return R{operator()(0, -suffix.length())}; + } + return {}; + } + /*! + * @ru @brief Возвращает строку, в которой удалено начало строки, если она начинается с указанного префикса без учёта регистра Unicode символов до 0xFFFF. + * @tparam R - желаемый тип строки, по умолчанию str_src. + * @param prefix - искомый префикс. + * @param max_count - до сколько раз можно удалять префикс, 0 - без ограничений. + * @return R - Копию строки, в которой удалено начало, если она начинается с этого префикса без учёта регистра символов до 0xFFFF. + * @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. + * @tparam R - desired string type, default str_src. + * @param prefix - the prefix to search for. + * @param max_count - up to how many times a prefix can be removed, 0 - no restrictions. + * @return R - A copy of the string with the beginning removed if it starts with this prefix, insensitive to 0xFFFF. + */ + template + constexpr R trimmed_prefix_iu(str_piece prefix, size_t max_count = 0) const { + str_piece res = *this; + while(res.starts_with_iu(prefix)) { + res = res(prefix.length()); + if (--max_count == 0) { + break; + } + } + return res; + } + /*! + * @ru @brief Возвращает строку, в которой удалён конец строки, если она заканчивается указанным суффиксом без учёта регистра Unicode символов до 0xFFFF. + * @tparam R - желаемый тип строки, по умолчанию str_src. + * @param suffix - искомый суффикс. + * @param max_count - до сколько раз можно удалять суффикс, 0 - без ограничений. + * @return R - Копию строки, в которой удалён конец, если она заканчивается этим суффиксом без учёта регистра символов до 0xFFFF. + * @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. + * @tparam R - desired string type, default str_src. + * @param suffix - the suffix you are looking for. + * @param max_count - up to how many times a suffix can be removed, 0 - no restrictions. + * @return R - A copy of the string with the end removed if it ends with this suffix, insensitive to 0xFFFF. + */ + template + constexpr R trimmed_suffix_iu(str_piece suffix) const { + str_piece res = *this; + while(res.ends_with_iu(suffix)) { + res = res(0, -suffix.length()); + } + return res; + } }; /* diff --git a/include/simstr/strexpr.h b/include/simstr/strexpr.h index 8d95614..f849959 100644 --- a/include/simstr/strexpr.h +++ b/include/simstr/strexpr.h @@ -1,5 +1,5 @@ /* - * ver. 1.7.2 + * ver. 1.7.3 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * База для строковых конкатенаций через выражения времени компиляции * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com @@ -4355,6 +4355,36 @@ public: constexpr bool starts_with(str_piece prefix) const noexcept { return starts_with(prefix.symbols(), prefix.length()); } + /*! + * @ru @brief Проверить, начинается ли строка с указанной подстроки, за которой следует ней пробельный ASCII символ. + * @param prefix - проверяемая подстрока. + * @en @brief Check if a string begins with the specified substring followed by a whitespace ASCII character. + * @param prefix - substring to be checked. + */ + constexpr bool starts_with_and_ws(str_piece prefix) const noexcept { + return _len() > prefix.length() && + starts_with(prefix) && + trim_operator{}.isTrim(_str()[prefix.length()]); + } + /*! + * @ru @brief Проверить, начинается ли строка с указанной подстроки, за которой следует один из указанных символов. + * @param prefix - проверяемая подстрока. + * @param next_symbol - проверяемые после подстроки символы. + * @en @brief Check if a string begins with the specified substring followed by one of the specified characters. + * @param prefix - substring to be checked. + * @param next_symbol - symbols to be checked after the substring. + */ + constexpr bool starts_with_and_oneof(str_piece prefix, str_piece next_symbol) const noexcept { + return _len() > prefix.length() && + starts_with(prefix) && + trim_operator{next_symbol}.isTrim(_str()[prefix.length()]); + } + template::Count, StrType From> requires is_const_pattern + constexpr bool starts_with_and_oneof(str_piece prefix, T&& next_symbol) const noexcept { + return _len() >= N && + starts_with(prefix) && + trim_operator{next_symbol}.isTrim(_str()[prefix.length()]); + } constexpr bool starts_with_ia(const K* prefix, size_t len) const noexcept { size_t myLen = _len(); @@ -4380,6 +4410,36 @@ public: constexpr bool starts_with_ia(str_piece prefix) const noexcept { return starts_with_ia(prefix.symbols(), prefix.length()); } + /*! + * @ru @brief Проверить, начинается ли строка с указанной подстроки без учета регистра ASCII, за которой следует ней пробельный ASCII символ. + * @param prefix - проверяемая подстрока. + * @en @brief Check if a string begins with the specified case-insensitive ASCII substring followed by a whitespace ASCII character. + * @param prefix - substring to be checked. + */ + constexpr bool starts_with_ia_and_ws(str_piece prefix) const noexcept { + return _len() > prefix.length() && + starts_with_ia(prefix) && + trim_operator{}.isTrim(_str()[prefix.length()]); + } + /*! + * @ru @brief Проверить, начинается ли строка с указанной подстроки без учета регистра ASCII, за которой следует один из указанных символов. + * @param prefix - проверяемая подстрока. + * @param next_symbol - проверяемые после подстроки символы. + * @en @brief Check if a string begins with the specified case-insensitive ASCII substring followed by one of the specified characters. + * @param prefix - substring to be checked. + * @param next_symbol - symbols to be checked after the substring. + */ + constexpr bool starts_with_ia_and_oneof(str_piece prefix, str_piece next_symbol) const noexcept { + return _len() > prefix.length() && + starts_with_ia(prefix) && + trim_operator{next_symbol}.isTrim(_str()[prefix.length()]); + } + template::Count, StrType From> requires is_const_pattern + constexpr bool starts_with_ia_and_oneof(str_piece prefix, T&& next_symbol) const noexcept { + return _len() >= N && + starts_with_ia(prefix) && + trim_operator{next_symbol}.isTrim(_str()[prefix.length()]); + } // Является ли эта строка началом указанной строки // Is this string the beginning of the specified string @@ -4522,6 +4582,82 @@ public: R replaced(str_piece pattern, str_piece repl, size_t offset = 0, size_t maxCount = 0) const { return R::replaced_from(d(), pattern, repl, offset, maxCount); } + /*! + * @ru @brief Получить строку без префикса, если она начинается с него. + * @tparam R - желаемый тип строкового объекта, по умолчанию str_piece. + * @param prefix - искомый префикс. + * @return constexpr std::optional - если строка начинается с указанного префикса, возвращает часть строки без этого префикса, + * иначе пустое значение. + * @en @brief Get a string without a prefix if it starts with one. + * @tparam R - the desired type of string object, defaults to str_piece. + * @param prefix - the prefix to search for. + * @return constexpr std::optional - if the string begins with the specified prefix, returns the part of the string without this prefix, + * otherwise empty value. + */ + template + constexpr std::optional strip_prefix(str_piece prefix) const { + if (starts_with(prefix)) { + return R{operator()(prefix.length())}; + } + return {}; + } + /*! + * @ru @brief Получить строку без префикса, если она начинается с него без учёта регистра ASCII символов. + * @tparam R - желаемый тип строкового объекта, по умолчанию str_piece. + * @param prefix - искомый префикс. + * @return constexpr std::optional - если строка начинается с указанного префикса без учёта регистра ASCII символов, + * возвращает часть строки без этого префикса, иначе пустое значение. + * @en @brief Get a string without a prefix if it starts with it, insensitive to ASCII characters. + * @tparam R - the desired type of string object, defaults to str_piece. + * @param prefix - the prefix to search for. + * @return constexpr std::optional - if the string begins with the specified prefix, insensitive to ASCII characters, + * returns the part of the string without this prefix, otherwise empty. + */ + template + constexpr std::optional strip_prefix_ia(str_piece prefix) const { + if (starts_with_ia(prefix)) { + return R{operator()(prefix.length())}; + } + return {}; + } + /*! + * @ru @brief Получить строку без суффикса, если она заканчивается им. + * @tparam R - желаемый тип строкового объекта, по умолчанию str_piece. + * @param suffix - искомый суффикс. + * @return constexpr std::optional - если строка заканчивается указанным суффиксом, возвращает часть строки без него, + * иначе пустое значение. + * @en @brief Get a string without a suffix if it ends with one. + * @tparam R - the desired type of string object, defaults to str_piece. + * @param suffix - the suffix you are looking for. + * @return constexpr std::optional - if the string ends with the specified suffix, returns the part of the string without it, + * otherwise empty value. + */ + template + constexpr std::optional strip_suffix(str_piece suffix) const { + if (ends_with(suffix)) { + return R{operator()(0, -suffix.length())}; + } + return {}; + } + /*! + * @ru @brief Получить строку без суффикса, если она заканчивается им без учёта регистра ASCII символов. + * @tparam R - желаемый тип строкового объекта, по умолчанию str_piece. + * @param suffix - искомый суффикс. + * @return constexpr std::optional - если строка заканчивается указанным суффиксом без учёта регистра ASCII символов, + * возвращает часть строки без него, иначе пустое значение. + * @en @brief Get a string without a suffix if it ends with one in case-insensitive ASCII characters. + * @tparam R - the desired type of string object, defaults to str_piece. + * @param suffix - the suffix you are looking for. + * @return constexpr std::optional - if the string ends with the specified suffix, insensitive to ASCII characters, + * returns part of the string without it, otherwise empty. + */ + template + constexpr std::optional strip_suffix_ia(str_piece suffix) const { + if (ends_with_ia(suffix)) { + return R{operator()(0, -suffix.length())}; + } + return {}; + } template From> constexpr static my_type make_trim_op(const From& from, const auto& opTrim) { @@ -4568,7 +4704,7 @@ public: * @return R - a string with leading whitespace characters removed. */ template - R trimmed_left() const { + constexpr R trimmed_left() const { return R::template trim_static(d()); } /*! @@ -4580,7 +4716,7 @@ public: * @return R - a string with whitespace characters removed at the end. */ template - R trimmed_right() const { + constexpr R trimmed_right() const { return R::template trim_static(d()); } /*! @@ -4595,7 +4731,7 @@ public: */ template::Count> requires is_const_pattern - R trimmed(T&& pattern) const { + constexpr R trimmed(T&& pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4610,7 +4746,7 @@ public: */ template::Count> requires is_const_pattern - R trimmed_left(T&& pattern) const { + constexpr R trimmed_left(T&& pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4625,7 +4761,7 @@ public: */ template::Count> requires is_const_pattern - R trimmed_right(T&& pattern) const { + constexpr R trimmed_right(T&& pattern) const { return R::template trim_static(d(), pattern); } // Триминг по символам в литерале и пробелам @@ -4647,7 +4783,7 @@ public: */ template::Count> requires is_const_pattern - R trimmed_with_spaces(T&& pattern) const { + constexpr R trimmed_with_spaces(T&& pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4666,7 +4802,7 @@ public: */ template::Count> requires is_const_pattern - R trimmed_left_with_spaces(T&& pattern) const { + constexpr R trimmed_left_with_spaces(T&& pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4685,7 +4821,7 @@ public: */ template::Count> requires is_const_pattern - R trimmed_right_with_spaces(T&& pattern) const { + constexpr R trimmed_right_with_spaces(T&& pattern) const { return R::template trim_static(d(), pattern); } // Триминг по динамическому источнику @@ -4702,7 +4838,7 @@ public: * @return R - a string with the characters contained in the pattern removed at the beginning and at the end. */ template - R trimmed(str_piece pattern) const { + constexpr R trimmed(str_piece pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4716,7 +4852,7 @@ public: * @return R - a string with the characters contained in the pattern removed at the beginning. */ template - R trimmed_left(str_piece pattern) const { + constexpr R trimmed_left(str_piece pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4730,7 +4866,7 @@ public: * @return R - a string with characters contained in the pattern removed at the end. */ template - R trimmed_right(str_piece pattern) const { + constexpr R trimmed_right(str_piece pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4748,7 +4884,7 @@ public: * and whitespace characters. */ template - R trimmed_with_spaces(str_piece pattern) const { + constexpr R trimmed_with_spaces(str_piece pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4766,7 +4902,7 @@ public: * and whitespace characters. */ template - R trimmed_left_with_spaces(str_piece pattern) const { + constexpr R trimmed_left_with_spaces(str_piece pattern) const { return R::template trim_static(d(), pattern); } /*! @@ -4784,10 +4920,95 @@ public: * and whitespace characters. */ template - R trimmed_right_with_spaces(str_piece pattern) const { + constexpr R trimmed_right_with_spaces(str_piece pattern) const { return R::template trim_static(d(), pattern); } - + /*! + * @ru @brief Возвращает строку, в которой удалено начало строки, если она начинается с указанного префикса. + * @tparam R - желаемый тип строки, по умолчанию str_src. + * @param prefix - искомый префикс. + * @param max_count - до сколько раз можно удалять префикс, 0 - без ограничений. + * @return R - Копию строки, в которой удалено начало, если она начинается с этого префикса. + * @en @brief Returns a string with the beginning of the string removed if it begins with the specified prefix. + * @tparam R - desired string type, default str_src. + * @param prefix - the prefix to search for. + * @param max_count - up to how many times a prefix can be removed, 0 - no restrictions. + * @return R - A copy of the string with the beginning removed, if it starts with this prefix. + */ + template + constexpr R trimmed_prefix(str_piece prefix, size_t max_count = 0) const { + str_piece res = *this; + while(res.starts_with(prefix)) { + res = res(prefix.length()); + if (--max_count == 0) { + break; + } + } + return res; + } + /*! + * @ru @brief Возвращает строку, в которой удалено начало строки, если она начинается с указанного префикса без учёта регистра ASCII символов. + * @tparam R - желаемый тип строки, по умолчанию str_src. + * @param prefix - искомый префикс. + * @param max_count - до сколько раз можно удалять префикс, 0 - без ограничений. + * @return R - Копию строки, в которой удалено начало, если она начинается с этого префикса без учёта регистра ASCII символов. + * @en @brief Returns a string with the beginning of the string removed if it begins with the specified prefix, insensitive to ASCII characters. + * @tparam R - desired string type, default str_src. + * @param prefix - the prefix to search for. + * @param max_count - up to how many times a prefix can be removed, 0 - no restrictions. + * @return R - A copy of the string with the beginning removed if it starts with this prefix, insensitive to ASCII characters. + */ + template + constexpr R trimmed_prefix_ia(str_piece prefix, size_t max_count = 0) const { + str_piece res = *this; + while(res.starts_with_ia(prefix)) { + res = res(prefix.length()); + if (--max_count == 0) { + break; + } + } + return res; + } + /*! + * @ru @brief Возвращает строку, в которой удалён конец строки, если она заканчивается указанным суффиксом. + * @tparam R - желаемый тип строки, по умолчанию str_src. + * @param suffix - искомый суффикс. + * @param max_count - до сколько раз можно удалять суффикс, 0 - без ограничений. + * @return R - Копию строки, в которой удалён конец, если она заканчивается этим суффиксом. + * @en @brief Returns a string with the beginning of the string removed if it begins with the specified prefix. + * @tparam R - desired string type, default str_src. + * @param suffix - the prefix to search for. + * @param max_count - up to how many times a suffix can be removed, 0 - no restrictions. + * @return R - A copy of the string with the beginning removed, if it starts with this prefix. + */ + template + constexpr R trimmed_suffix(str_piece suffix) const { + str_piece res = *this; + while(res.ends_with(suffix)) { + res = res(0, -suffix.length()); + } + return res; + } + /*! + * @ru @brief Возвращает строку, в которой удалён конец строки, если она заканчивается указанным суффиксом без учёта регистра ASCII символов. + * @tparam R - желаемый тип строки, по умолчанию str_src. + * @param suffix - искомый суффикс. + * @param max_count - до сколько раз можно удалять суффикс, 0 - без ограничений. + * @return R - Копию строки, в которой удалён конец, если она заканчивается этим суффиксом без учёта регистра ASCII символов. + * @en @brief Returns a string with the end of the string removed if it ends with the specified suffix, insensitive to ASCII characters. + * @tparam R - desired string type, default str_src. + * @param suffix - the suffix you are looking for. + * @param max_count - up to how many times a suffix can be removed, 0 - no restrictions. + * @return R - A copy of the string with the end removed if it ends with this suffix, insensitive to ASCII characters. + */ + template + constexpr R trimmed_suffix_ia(str_piece suffix) const { + str_piece res = *this; + while(res.ends_with_ia(suffix)) { + res = res(0, -suffix.length()); + } + return res; + } /*! * @ru @brief Получить объект `Splitter` по заданному разделителю, который позволяет последовательно * получать подстроки методом `next()`, пока `is_done()` false. diff --git a/readme.md b/readme.md index b21d0e5..0a7842c 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Version 1.7.2. +Version 1.7.3.

Speed up your work with strings by 2-10 times!

@@ -325,8 +325,8 @@ function(add_simstr) simstr GIT_REPOSITORY https://github.com/orefkov/simstr.git GIT_SHALLOW TRUE - GIT_TAG tags/rel1.7.2 # Specify the desired release - FIND_PACKAGE_ARGS NAMES simstr 1.7.2 + GIT_TAG tags/rel1.7.3 # Specify the desired release + FIND_PACKAGE_ARGS NAMES simstr 1.7.3 ) FetchContent_MakeAvailable(simstr) endfunction() diff --git a/readme_ru.md b/readme_ru.md index a2ccdc5..aee2865 100644 --- a/readme_ru.md +++ b/readme_ru.md @@ -3,7 +3,7 @@ [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Версия 1.7.2. +Версия 1.7.3.

Ускорь работу со строками в 2-10 раз!

@@ -326,8 +326,8 @@ function(add_simstr) simstr GIT_REPOSITORY https://github.com/orefkov/simstr.git GIT_SHALLOW TRUE - GIT_TAG tags/rel1.7.2 # Укажите нужный релиз - FIND_PACKAGE_ARGS NAMES simstr 1.7.2 + GIT_TAG tags/rel1.7.3 # Укажите нужный релиз + FIND_PACKAGE_ARGS NAMES simstr 1.7.3 ) FetchContent_MakeAvailable(simstr) endfunction() diff --git a/src/sstring.cpp b/src/sstring.cpp index efeecf7..8da9d13 100644 --- a/src/sstring.cpp +++ b/src/sstring.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.7.2 + * ver. 1.7.3 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Реализация строковых функций * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/tests/test_expr_only.cpp b/tests/test_expr_only.cpp index 6b763d5..b8d3876 100644 --- a/tests/test_expr_only.cpp +++ b/tests/test_expr_only.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.7.2 + * ver. 1.7.3 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Тесты simstr * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com @@ -427,4 +427,29 @@ TEST(StrExpr, ChangeCase) { EXPECT_EQ(ures, u"/teST/"); } +TEST(StrExpr, StripPrefixSuffix) { + const ssa from = "begin--end"; + EXPECT_EQ(*from.strip_prefix("begin"), "--end"); + EXPECT_FALSE(from.strip_prefix("sd").has_value()); + EXPECT_EQ(*from.strip_suffix_ia("End"), "begin--"); + EXPECT_FALSE(from.strip_suffix("sd").has_value()); +} + +TEST(StrExpr, TrimPrefixSuffix) { + const ssa from = "beginbegin--end"; + EXPECT_EQ(from.trimmed_prefix("begin"), "--end"); + EXPECT_EQ(from.trimmed_prefix("begin", 1), "begin--end"); + EXPECT_EQ(from.trimmed_prefix("sd"), from); + EXPECT_EQ(from.trimmed_suffix_ia("End"), "beginbegin--"); + EXPECT_EQ(from.trimmed_suffix("sd"), from); +} + +TEST(StrExpr, StartWithAnd) { + EXPECT_TRUE("begin --end"_ss.starts_with_and_ws("begin")); + EXPECT_FALSE("beginn --end"_ss.starts_with_and_ws("begin")); + EXPECT_TRUE("BegiN\t--end"_ss.starts_with_ia_and_ws("begin"_ss)); + EXPECT_TRUE("begin[ --end"_ss.starts_with_and_oneof("begin", "/*[]")); + EXPECT_TRUE("Begin[ --end"_ss.starts_with_ia_and_oneof("begin", "/*[]"_ss)); +} + } // namespace simstr::tests diff --git a/tests/test_str.cpp b/tests/test_str.cpp index 49e75b8..7a18df0 100644 --- a/tests/test_str.cpp +++ b/tests/test_str.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.7.2 + * ver. 1.7.3 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Тесты simstr * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/tests/test_tostrexpr.cpp b/tests/test_tostrexpr.cpp index 32aa89a..4293063 100644 --- a/tests/test_tostrexpr.cpp +++ b/tests/test_tostrexpr.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.7.2 + * ver. 1.7.3 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Тесты simstr * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com