| 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 |
20 |
| text2UV (SV *sv, STRLEN *lenp) |
| 10 |
|
| { |
| 11 |
|
| STRLEN len; |
| 12 |
20 |
| char *s = SvPV (sv, len); |
| 13 |
20 |
| UV *r = (UV *)SvPVX (sv_2mortal (NEWSV (0, (len + 1) * sizeof (UV)))); |
| 14 |
20 |
| UV *p = r; |
| 15 |
|
| |
| 16 |
20 |
▶ | if (SvUTF8 (sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvUTF8 (sv)) |
4 |
16 |
20 |
|
| 17 |
|
| { |
| 18 |
|
| STRLEN clen; |
| 19 |
8 |
▶ | while (len) |
Branch: 1 branch
| Branch | True | False | Total |
| while (len) |
4 |
4 |
8 |
|
| 20 |
|
| { |
| 21 |
4 |
| *p++ = utf8n_to_uvchr (s, len, &clen, 0); |
| 22 |
|
| |
| 23 |
|
| if (clen < 0) |
| 24 |
|
| croak ("illegal unicode character in string"); |
| 25 |
|
| |
| 26 |
4 |
| s += clen; |
| 27 |
4 |
| len -= clen; |
| 28 |
|
| } |
| 29 |
|
| } |
| 30 |
|
| else |
| 31 |
199 |
▶ | while (len--) |
Branch: 1 branch
| Branch | True | False | Total |
| while (len--) |
183 |
16 |
199 |
|
| 32 |
183 |
| *p++ = *(unsigned char *)s++; |
| 33 |
|
| |
| 34 |
20 |
| *lenp = p - r; |
| 35 |
20 |
| 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 |
10 |
| UV *c1 = text2UV (s1, &l1); |
| 50 |
10 |
| UV *c2 = text2UV (s2, &l2); |
| 51 |
10 |
| RETVAL = fstrcmp (c1, l1, c2, l2, minimum_similarity); |
| 52 |
|
| } |
| 53 |
|
| OUTPUT: |
| 54 |
|
| RETVAL |
| 55 |
|
| |