/*
 * This file was generated automatically by xsubpp version 1.9508 from the
 * contents of Index.xs. Do not edit this file, edit Index.xs instead.
 *
 *	ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "Index.xs"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

#define	SI_NOT	0x01
#define SI_REV	0x02


#line 21 "Index.c"
XS(XS_String__Index_cindex); /* prototype to pass -Wmissing-prototypes */
XS(XS_String__Index_cindex)
{
    dXSARGS;
    dXSI32;
    if (items < 2)
       Perl_croak(aTHX_ "Usage: %s(str, cc, ...)", GvNAME(CvGV(cv)));
    {
	int	RETVAL;
	dXSTARG;
	SV *	str = ST(0);
	SV *	cc = ST(1);
#line 22 "Index.xs"
{
    STRLEN s_len;
    STRLEN c_len;
    char *s = SvPV(str,s_len);
    char *c = SvPV(cc,c_len);
    int seen_null = 0;
    int p = (items == 3 ? (int)SvIV(ST(2)) : 0); 
    int i;

    /* see if there is an INTERNAL null in the char str */
    for (i = 0; i < c_len; ) {
	if (c[i] == '\0' && (seen_null = 1)) c[i] = c[--c_len];
	else ++i;
    }
    c[c_len] = '\0';

    if (ix & SI_REV) {
	s += (p ? p : s_len - 1);
	for (i = p ? p : (s_len - 1); i >= 0; --i, --s)
	    if ((*s ? strchr(c, *s) > 0 : seen_null) != (ix & SI_NOT)) break;
    }
    else {
	s += p;
	for (i = p; i < s_len; ++i, ++s)
	    if ((*s ? strchr(c, *s) > 0 : seen_null) != (ix & SI_NOT)) break;
    }

    RETVAL = (i == ((ix & SI_REV) ? -1 : s_len) ? -1 : i);
}
#line 64 "Index.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS(boot_String__Index); /* prototype to pass -Wmissing-prototypes */
XS(boot_String__Index)
{
    dXSARGS;
    char* file = __FILE__;

    XS_VERSION_BOOTCHECK ;

    {
        CV * cv ;

        cv = newXS("String::Index::crindex", XS_String__Index_cindex, file);
        XSANY.any_i32 = 2 ;
        sv_setpv((SV*)cv, "$$;$") ;
        cv = newXS("String::Index::ncindex", XS_String__Index_cindex, file);
        XSANY.any_i32 = 1 ;
        sv_setpv((SV*)cv, "$$;$") ;
        cv = newXS("String::Index::ncrindex", XS_String__Index_cindex, file);
        XSANY.any_i32 = 3 ;
        sv_setpv((SV*)cv, "$$;$") ;
        cv = newXS("String::Index::cindex", XS_String__Index_cindex, file);
        XSANY.any_i32 = 0 ;
        sv_setpv((SV*)cv, "$$;$") ;
    }
    XSRETURN_YES;
}

