Sorry, I got nothing. The only function I found for UTF8 comparisons is foldEQ_utf8, which is supposed to perform case-insensitive string comparisons. Maybe XS mailing list or p5p is the better place to ask?
David On Mon, May 7, 2012 at 11:50 AM, David Oswald <daosw...@gmail.com> wrote: > I'm trying to figure out a sane approach to string comparisons in > extension code. I'm using Inline::C on this one. The simplest > solution turns out to be the hardest: Unpack an SV into a C-String, > and use C's comparison functions. Why is that the hardest? Because > it ignores Unicode. However, Perl's 'cmp', 'le', 'ge', 'lt', 'gt', > and 'eq' know about Unicode. So I wanted to compare the two SV's > using Perl's native operations. I see some documentation in perlapi, > but it's so terse I could benefit from an example. > > So... does anyone know how these would be implemented in C as XS > extension code such that the comparisons invoke Perl's native tools? > > sub compare { > return $_[0] cmp $_[1]; > } > > .... A C stub: > > int compare( SV* left, SV* right ) { > int result; > // Compare the two SV's stringwise. > return result; > } > > > ....and.... > > sub lessthan { > return $_[0] lt $_[1]; > } > > A C stub: > > int lessthan( SV* left, SV* right ) { > int result; > // Less-than compare the two SV's stringwise. > return result; > } > > My goal is to use Inline::C and Inline::C2XS to produce an XS version > of my List::BinarySearch module. It would be named > List::BinarySearch::XS, and I would convert List::BinarySearch to > auto-detect the XS version's presence, substituting the XS versions in > place of the Pure Perl versions if the XS module exists. Not > surprisingly, the documentation on dealing with strings in extension > code is a bit opaque. > > Dave > > > -- > > David Oswald > daosw...@gmail.com > -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan