ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/String-Similarity/Similarity.xs
Revision: 1.1
Committed: Sat Jun 25 09:55:53 2005 UTC (19 years ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5     #include "fstrcmp.h"
6     #include "fstrcmp.c"
7    
8     CHAR *
9     text2CHAR (SV *sv, STRLEN *lenp)
10     {
11     STRLEN len;
12     char *s = SvPV (sv, len);
13     UV *r = (UV *)SvPVX (sv_2mortal (NEWSV (0, (len + 1) * sizeof (UV))));
14     UV *p = r;
15    
16     if (SvUTF8 (sv))
17     {
18     STRLEN clen;
19     while (len)
20     {
21     *p++ = utf8n_to_uvchr (s, len, &clen, 0);
22    
23     if (clen < 0)
24     croak ("illegal unicode character in string");
25    
26     s += clen;
27     len -= clen;
28     }
29     }
30     else
31     while (len--)
32     *p++ = *(unsigned char *)s++;
33    
34     *lenp = p - r;
35     return r;
36     }
37    
38     MODULE = String::Similarity PACKAGE = String::Similarity
39    
40     double
41     fstrcmp(s1, s2, minimum_similarity = 0)
42     SV * s1
43     SV * s2
44     double minimum_similarity
45     PROTOTYPE: @
46     CODE:
47     {
48     STRLEN l1, l2;
49     CHAR *c1 = text2CHAR (s1, &l1);
50     CHAR *c2 = text2CHAR (s2, &l2);
51     RETVAL = fstrcmp (c1, l1, c2, l2, minimum_similarity);
52     }
53     OUTPUT:
54     RETVAL
55