MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / compare

Method compare

src/String.cpp:1662–1710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1660
1661
1662int String::compare(const ::String &inRHS) const
1663{
1664 if (!__s)
1665 return inRHS.__s ? -1 : 0;
1666 if (!inRHS.__s)
1667 return 1;
1668
1669 int cmp = 0;
1670 int minLen = length<inRHS.length ? length : inRHS.length;
1671
1672 if (minLen>0)
1673 {
1674 bool s0IsWide = isUTF16Encoded();
1675 bool s1IsWide = inRHS.isUTF16Encoded();
1676
1677 if (s0IsWide==s1IsWide)
1678 {
1679 if (!s0IsWide)
1680 {
1681 cmp = memcmp(__s,inRHS.__s,minLen);
1682 }
1683 else
1684 {
1685 for(int i=0;i<minLen;i++)
1686 {
1687 if (__w[i]!=inRHS.__w[i])
1688 {
1689 cmp = __w[i] - inRHS.__w[i];
1690 break;
1691 }
1692 }
1693 }
1694 }
1695 else
1696 {
1697 const unsigned char *s = (const unsigned char *)( s0IsWide ? inRHS.__s : __s );
1698 const char16_t *w = s0IsWide ? __w : inRHS.__w;
1699 for(int i=0;i<minLen;i++)
1700 if (s[i]!=w[i])
1701 {
1702 cmp = s[i]<w[i] ? -1 : 1;
1703 if (s0IsWide)
1704 cmp = - cmp;
1705 break;
1706 }
1707 }
1708 }
1709 return cmp ? cmp : length - inRHS.length;
1710}
1711#endif
1712
1713

Callers 1

__CompareMethod · 0.45

Calls 2

isUTF16EncodedFunction · 0.85
memcmpFunction · 0.50

Tested by

no test coverage detected