|
1 | 1 | /* |
2 | | -* ver. 1.7.2 |
| 2 | +* ver. 1.7.3 |
3 | 3 | * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com |
4 | 4 | * Классы для работы со строками |
5 | 5 | * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com |
@@ -373,6 +373,87 @@ class str_algs : public str_src_algs<K, StrRef, Impl, Mutable> { |
373 | 373 | constexpr void as_number(T& t) const { |
374 | 374 | base::as_number(t); |
375 | 375 | } |
| 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 | + } |
376 | 457 | }; |
377 | 458 |
|
378 | 459 | /* |
|
0 commit comments