mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
Merge pull request #5161 from alalek:fix_string
This commit is contained in:
commit
c1778f1199
@ -896,6 +896,7 @@ size_t String::find_first_of(const String& str, size_t pos) const
|
||||
inline
|
||||
size_t String::find_first_of(const char* s, size_t pos) const
|
||||
{
|
||||
if (len_ == 0) return npos;
|
||||
if (pos >= len_ || !s[0]) return npos;
|
||||
const char* lmax = cstr_ + len_;
|
||||
for (const char* i = cstr_ + pos; i < lmax; ++i)
|
||||
@ -910,6 +911,7 @@ size_t String::find_first_of(const char* s, size_t pos) const
|
||||
inline
|
||||
size_t String::find_last_of(const char* s, size_t pos, size_t n) const
|
||||
{
|
||||
if (len_ == 0) return npos;
|
||||
if (pos >= len_) pos = len_ - 1;
|
||||
for (const char* i = cstr_ + pos; i >= cstr_; --i)
|
||||
{
|
||||
@ -935,6 +937,7 @@ size_t String::find_last_of(const String& str, size_t pos) const
|
||||
inline
|
||||
size_t String::find_last_of(const char* s, size_t pos) const
|
||||
{
|
||||
if (len_ == 0) return npos;
|
||||
if (pos >= len_) pos = len_ - 1;
|
||||
for (const char* i = cstr_ + pos; i >= cstr_; --i)
|
||||
{
|
||||
|
@ -129,3 +129,12 @@ TEST(Core_OutputArrayAssign, _Matxf_UMatd)
|
||||
|
||||
EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON);
|
||||
}
|
||||
|
||||
|
||||
TEST(Core_String, find_last_of__with__empty_string)
|
||||
{
|
||||
cv::String s;
|
||||
size_t p = s.find_last_of("q", 0);
|
||||
// npos is not exported: EXPECT_EQ(cv::String::npos, p);
|
||||
EXPECT_EQ(std::string::npos, p);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user