ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/String-Similarity/Similarity.xs
Revision: 1.2
Committed: Tue Nov 4 15:31:38 2008 UTC (15 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-1_04, HEAD
Changes since 1.1: +4 -4 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include "fstrcmp.h"
6 #include "fstrcmp.c"
7
8 UV *
9 text2UV (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 UV *c1 = text2UV (s1, &l1);
50 UV *c2 = text2UV (s2, &l2);
51 RETVAL = fstrcmp (c1, l1, c2, l2, minimum_similarity);
52 }
53 OUTPUT:
54 RETVAL
55