xtd 0.2.0
Loading...
Searching...
No Matches

◆ compare() [1/13]

template<typename char_t , typename traits_t , typename allocator_t >
int32 xtd::basic_string< char_t, traits_t, allocator_t >::compare ( const basic_string< char_t, traits_t, allocator_t > &  str) const
inline

Compares two character sequences.

Parameters
strThe other string to compare to.
Returns
  • Negative value if *this appears before the character sequence specified by the arguments, in lexicographical order.
  • Zero if both character sequences compare equivalent.
  • Positive value if *this appears after the character sequence specified by the arguments, in lexicographical order.
Remarks
Compares this string to str.
A character sequence consisting of count1 characters starting at data1 is compared to a character sequence consisting of count2 characters starting at data2 as follows:
  • First, calculate the number of characters to compare, as if by size_type rlen = std::min(count1, count2).
  • Then compare the sequences by calling traits_t::compare(data1, data2, rlen). For standard strings this function performs character-by-character lexicographical comparison. If the result is zero (the character sequences are equal so far), then their sizes are compared as follows:
Condition Result Return value
traits_t::compare(data1, data2, rlen) < 0 data1 is less than data2 < 0
 traits_t::compare(data1, data2, rlen) == 0 and size1 < size2 data1 is less than data2 < 0
 traits_t::compare(data1, data2, rlen) == 0 and size1 == size2 data1 is equal to data2 0
 traits_t::compare(data1, data2, rlen) == 0 and size1 > size2 data1 is greater than data2 > 0
traits_t::compare(data1, data2, rlen) > 0 data1 is greater than data2 > 0