Menu

#4 wrong compare of empty strings

1.0
closed
nobody
None
2017-12-27
2017-12-27
Grynca
No

Hello i have encountered problem with comparing empty strings (well one is null and one empty with only char '\0')

    utf8_string str1 = "";
    utf8_string str2;

    std::cout << (str1 == str2) << std::endl;     // prints out "0"
    return 0;
 ~~~
In my codebase i resolved it with following change:

inline bool utf8_string::equals( const char str ) const
{
const char
it1 = this->buffer;

if (!it1) {
    return (!str || !*str);
}
else if (!str) {
    return (!it1 || !*it1);
}

while( *it1 && *str ){
    if( *it1 != *str )
        return false;
    it1++;
    str++;
}
return *it1 == *str;

}
~~~
Also considering your lack of time, could you move the project to github so other users can contribute?

Discussion

  • Grynca

    Grynca - 2017-12-27

    well sorry for the formating ...

     
  • DuffsDevice

    DuffsDevice - 2017-12-27

    Fixed on Github :)

     
  • DuffsDevice

    DuffsDevice - 2017-12-27
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB