WCF icon indicating copy to clipboard operation
WCF copied to clipboard

Unify string ordering functions

Open TimWolla opened this issue 3 years ago • 1 comments
trafficstars

we currently have:

  • <=>: https://github.com/WoltLab/WCF/blob/ce4b59bfbf770fb5a88105fd3205f60ea6039181/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php#L174
  • strcmp: https://github.com/WoltLab/WCF/blob/ce4b59bfbf770fb5a88105fd3205f60ea6039181/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php#L267-L270
  • strcasecmp: https://github.com/WoltLab/WCF/blob/ce4b59bfbf770fb5a88105fd3205f60ea6039181/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php#L138-L141

They should all be unified to use <=>. strcmp is a direct replacement. strcasecmp will need to either call strtolower or mb_strtolower depending on whether the strings hold Unicode values or not.

TimWolla avatar Feb 16 '22 14:02 TimWolla

Maybe a helper function should be introduced for the case-insensitive comparison. It could use Collator::compare() when intl is available.

TimWolla avatar Feb 16 '22 14:02 TimWolla

when intl is available.

Intl is always available now and it likely makes sense to use Collator even for case-sensitive comparisons to correctly handle accented characters.

TimWolla avatar Oct 27 '22 14:10 TimWolla