This is an archive of the discontinued LLVM Phabricator instance.

[libc] add locale free strcoll
ClosedPublic

Authored by michaelrj on Oct 26 2022, 4:15 PM.

Details

Summary

The strcoll function is intended to compare strings based on their
ordering in the current locale. Since the locale facilities have not yet
been added, a simple implementation that is the same as strcmp has been
added as a placeholder.

Diff Detail

Event Timeline

michaelrj created this revision.Oct 26 2022, 4:15 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 26 2022, 4:15 PM
michaelrj requested review of this revision.Oct 26 2022, 4:15 PM
sivachandra accepted this revision.Oct 26 2022, 10:01 PM
sivachandra added inline comments.
libc/src/string/strcoll.cpp
20

I think this is the same implementation as strcmp, but to avoid all type conversion/promotion confusions, we should cast the de-referenced value to int:

int(*reinterpret_cast<const unsigned char *>(left))
libc/test/src/string/strcoll_test.cpp
23

For completeness, you should add ASSERT_GT and ASSERT_LT tests also.

This revision is now accepted and ready to land.Oct 26 2022, 10:01 PM
michaelrj marked an inline comment as done.

address comments

libc/test/src/string/strcoll_test.cpp
23

I'm avoiding adding GT and LT tests because they'll likely be wrong in some locales. Until we have a system for setting the locale per-test, similar to what we have for floating point rounding modes, any inequality comparison is unsafe.

add difference tests before land

This revision was landed with ongoing or failed builds.Oct 28 2022, 11:13 AM
This revision was automatically updated to reflect the committed changes.