Can anyone point me to an example of XS code using Perl's native tools
for stringwise relational comparisons?

Sounds like an XY problem?

The 'X':

I want to compare the strings held in two SV's.  I need 'cmp', 'lt',
'gt', and 'eq' functionality.

The 'Y':

I gather that dealing with all the ins and outs of Unicode is more
work than necessary, if Perl can handle that detail for me by letting
me call its native operators on two SV's.  If I can invoke Perl's
operators I can let them worry about whether the string is Unicode or
not.  The underlying code is not string intensive, but does need to do
a couple of comparisons.  Unpacking the SV's to C-Strings and using
C's library tools to do the comparisons exposes me to all the nitty
gritty of unraveling and handling encodings.  Suddenly code that is
not string intensive begins looking like exactly that.

What I'm hoping to find is a simple example of this Perl code,
implemented in C (I'll be writing in Inline::C and letting
Inline::C2XS handle the XS conversion for me):

sub compare {
    return $_[0] cmp $_[1];
}

A C starting point:

int compare ( SV* left, SV* right ) {
    int result;
    // stringwise comparison of left and right.
    return result;
}


...and a boolean relational test too:

sub lessthan {
    return $_[0] lt $_[1];
}


A C starting point:

int lessthan ( SV* left, SV* right ) {
    int result;
    // stringwise less than operation.
    return result;
}

I've tried looking to find a module that does this right so that I can
look at its code, but just can't seem to find one.

(A variation on this message has been crossposted to inl...@perl.org)

Dave
-- 

David Oswald
daosw...@gmail.com
dav...@cpan.org

Reply via email to