View source code Display the source code in std/uni.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.uni.sicmp

Does basic case-insensitive comparison of strings str1 and str2. This function uses simpler comparison rule thus achieving better performance than icmp. However keep in mind the warning below.

Prototype

int sicmp(S1, S2)(
  S1 str1,
  S2 str2
)
if (isForwardRange!S1 && is(Unqual!(ElementType!S1) == dchar) && isForwardRange!S2 && is(Unqual!(ElementType!S2) == dchar));

Parameters

NameDescription
str1 a string or a ForwardRange of dchars
str2 a string or a ForwardRange of dchars

Returns

An int that is 0 if the strings match, <0 if str1 is lexicographically "less" than str2, >0 if str1 is lexicographically "greater" than str2

Warning

This function only handles 1:1 mapping and thus is not sufficient for certain alphabets like German, Greek and few others.

Example

assert(sicmp("Август", "авгусТ") == 0);
// Greek also works as long as there is no 1:M mapping in sight
assert(sicmp("ΌΎ", "όύ") == 0);
// things like the following won't get matched as equal
// Greek small letter iota with dialytika and tonos
assert(sicmp("ΐ", "\u03B9\u0308\u0301") != 0);

// while icmp has no problem with that
assert(icmp("ΐ", "\u03B9\u0308\u0301") == 0);
assert(icmp("ΌΎ", "όύ") == 0);

See Also

icmp std.algorithm.comparison.cmp

Authors

Dmitry Olshansky

License

Boost License 1.0.

Comments