@brief Compares the referenced character sequence values with the given basic_str_view object. @param sv The basic_str_view object to compare with. @return The lexicographical comparison result. The values are same as std::strncmp().
| 2461 | /// @param sv The basic_str_view object to compare with. |
| 2462 | /// @return The lexicographical comparison result. The values are same as std::strncmp(). |
| 2463 | int compare(basic_str_view sv) const noexcept { |
| 2464 | const size_type rlen = std::min(m_len, sv.m_len); |
| 2465 | int ret = traits_type::compare(mp_str, sv.mp_str, rlen); |
| 2466 | |
| 2467 | if (ret == 0) { |
| 2468 | using int_limits = std::numeric_limits<int>; |
| 2469 | const difference_type diff = |
| 2470 | m_len > sv.m_len ? m_len - sv.m_len |
| 2471 | : static_cast<difference_type>(-1) * static_cast<difference_type>(sv.m_len - m_len); |
| 2472 | |
| 2473 | if (diff > int_limits::max()) { |
| 2474 | ret = int_limits::max(); |
| 2475 | } |
| 2476 | else if (diff < int_limits::min()) { |
| 2477 | ret = int_limits::min(); |
| 2478 | } |
| 2479 | else { |
| 2480 | ret = static_cast<int>(diff); |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | return ret; |
| 2485 | } |
| 2486 | |
| 2487 | /// @brief Compares the referenced character sequence values from `pos1` by `n1` characters with `sv`. |
| 2488 | /// @param pos1 The offset of the beginning element. |
no test coverage detected