Changeset a6ca1bc in mainline


Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
509738fd
Parents:
6c089a9
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-11-02 17:38:55)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: fixed some bugs found by the string find tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/string.hpp

    r6c089a9 ra6ca1bc  
    10191019            size_type find(const value_type* str, size_type pos, size_type len) const noexcept
    10201020            {
    1021                 if (empty() || len == 0 || len - pos > size())
     1021                if (empty() || len == 0 || len + pos > size())
    10221022                    return npos;
    10231023
     
    10601060            size_type rfind(const value_type* str, size_type pos, size_type len) const noexcept
    10611061            {
    1062                 if (empty() || len == 0 || len - pos > size())
     1062                if (empty() || len == 0 || len + pos > size())
    10631063                    return npos;
    10641064
     
    10851085                    return npos;
    10861086
    1087                 for (size_type i = min(pos, size_ - 1) + 1; i > 0; --i)
     1087                for (size_type i = min(pos + 1, size_ - 1) + 1; i > 0; --i)
    10881088                {
    10891089                    if (traits_type::eq(c, data_[i - 1]))
     
    11011101            size_type find_first_of(const value_type* str, size_type pos, size_type len) const noexcept
    11021102            {
    1103                 if (empty() || len == 0 || pos + len > size())
     1103                if (empty() || len == 0 || pos >= size())
    11041104                    return npos;
    11051105
     
    11331133            size_type find_last_of(const value_type* str, size_type pos, size_type len) const noexcept
    11341134            {
    1135                 if (empty())
     1135                if (empty() || len == 0)
    11361136                    return npos;
    11371137
     
    11621162            size_type find_first_not_of(const value_type* str, size_type pos, size_type len) const noexcept
    11631163            {
    1164                 if (empty() || len == 0 || pos + len > size())
     1164                if (empty() || pos >= size())
    11651165                    return npos;
    11661166
     
    11791179            size_type find_first_not_of(const value_type* str, size_type pos = 0) const noexcept
    11801180            {
    1181                 return find_first_not_of(str.c_str(), pos, str.size());
     1181                return find_first_not_of(str, pos, traits_type::length(str));
    11821182            }
    11831183
     
    12081208                for (size_type i = min(pos, size_ - 1) + 1; i > 0; --i)
    12091209                {
    1210                     if (!is_one_of_(i - 1, str, len))
     1210                    if (!is_any_of_(i - 1, str, len))
    12111211                        return i - 1;
    12121212                }
     
    13871387            }
    13881388
    1389             bool is_one_of_(size_type idx, const basic_string& str) const
    1390             {
    1391                 auto cstr = str.c_str();
    1392                 for (size_type i = 0; i < str.size(); ++i)
    1393                 {
    1394                     if (traits_type::eq(data_[idx], cstr[i]))
     1389            bool is_any_of_(size_type idx, const value_type* str, size_type len) const
     1390            {
     1391                for (size_type i = 0; i < len; ++i)
     1392                {
     1393                    if (traits_type::eq(data_[idx], str[i]))
    13951394                        return true;
    13961395                }
Note: See TracChangeset for help on using the changeset viewer.