| 1 |
|
| /* |
| 2 |
|
| * ExtractWords.xs |
| 3 |
|
| * Last Modification: Mon Oct 13 14:12:37 WEST 2003 |
| 4 |
|
| * |
| 5 |
|
| * Copyright (c) 2003 Henrique Dias <hdias@aesbuc.pt>. All rights reserved. |
| 6 |
|
| * This module is free software; you can redistribute it and/or modify |
| 7 |
|
| * it under the same terms as Perl itself. |
| 8 |
|
| * |
| 9 |
|
| */ |
| 10 |
|
| |
| 11 |
|
| #ifdef OP_PROTOTYPE |
| 12 |
|
| #undef OP_PROTOTYPE |
| 13 |
|
| #endif |
| 14 |
|
| |
| 15 |
|
| #include "EXTERN.h" |
| 16 |
|
| #include "perl.h" |
| 17 |
|
| #include "XSUB.h" |
| 18 |
|
| #include <locale.h> |
| 19 |
|
| #include <string.h> |
| 20 |
|
| |
| 21 |
|
| #define PERL_POLLUTE |
| 22 |
|
| |
| 23 |
|
| #define MINLENWORD 1 |
| 24 |
|
| #define MAXLENWORD 32 |
| 25 |
|
| #define MINLENMULTIWORD 6 |
| 26 |
|
| #define MINSPACELETTERS 2 |
| 27 |
|
| |
| 28 |
|
| char delimiters[] = "\xAB\xB4\xBB !?,;:|\\/@\t\b\f\n\r&=\"()<>{}[]+*~^`"; |
| 29 |
|
| char chrsep[] = " _#.*-&/"; |
| 30 |
|
| char chrend[] = " ,;.:\x0A\x0D\x09\"'?!+-*/()[]"; |
| 31 |
|
| |
| 32 |
|
| struct def_entity { |
| 33 |
|
| unsigned char entity[9]; |
| 34 |
|
| unsigned int length; |
| 35 |
|
| unsigned char character; |
| 36 |
|
| }; |
| 37 |
|
| |
| 38 |
|
| static struct def_entity entities[28] = { |
| 39 |
|
| {"à", 8, 0xE0}, {"á", 8, 0xE1}, |
| 40 |
|
| {"â", 7, 0xE2}, {"ã", 8, 0xE3}, |
| 41 |
|
| {"ä", 6, 0xE4}, {"å", 7, 0xE5}, |
| 42 |
|
| {"æ", 7, 0xE6}, {"ç", 8, 0xE7}, |
| 43 |
|
| {"è", 8, 0xE8}, {"é", 8, 0xE9}, |
| 44 |
|
| {"êe;", 8, 0xEA}, {"ë", 6, 0xEB}, |
| 45 |
|
| {"ì", 8, 0xEC}, {"í", 8, 0xED}, |
| 46 |
|
| {"î", 7, 0xEE}, {"ï", 6, 0xEF}, |
| 47 |
|
| {"ñ", 8, 0xF1}, {"ò", 8, 0xF2}, |
| 48 |
|
| {"ó", 8, 0xF3}, {"ô", 7, 0xF4}, |
| 49 |
|
| {"õ", 8, 0xF5}, {"ö", 6, 0xF6}, |
| 50 |
|
| {"ù", 8, 0xF9}, {"ú", 8, 0xFA}, |
| 51 |
|
| {"û", 7, 0xFB}, {"ü", 6, 0xFC}, |
| 52 |
|
| {"ý", 8, 0xFD}, {"ÿ", 6, 0xFF} |
| 53 |
|
| }; |
| 54 |
|
| |
| 55 |
|
| #ifdef HAVE_LOCALE_H |
| 56 |
|
| void set_locale(unsigned char *locale) { |
| 57 |
|
| setlocale(LC_CTYPE, locale); |
| 58 |
|
| setlocale(LC_COLLATE, locale); |
| 59 |
|
| setlocale(LC_MESSAGES, ""); |
| 60 |
|
| } |
| 61 |
|
| #endif |
| 62 |
|
| |
| 63 |
2 |
| void unescape_str(unsigned char *s) { |
| 64 |
|
| register int x,y; |
| 65 |
59 |
▶ | for(x=0, y=0; s[y]; ++x, ++y) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(x=0, y=0; s[y]; ++x, ++y) { |
57 |
2 |
59 |
|
| 66 |
57 |
▶ | if((s[x] = s[y]) == '%') { |
Branch: 1 branch
| Branch | True | False | Total |
| if((s[x] = s[y]) == '%') { |
0 |
57 |
57 |
|
| 67 |
|
| int hex; |
| 68 |
0 |
▶ | if(isxdigit(s[y+1]) && |
Branch: 1 branch
| Branch | True | False | Total |
| if(isxdigit(s[y+1]) && |
0 |
0 |
0 |
|
| 69 |
0 |
▶ | isxdigit(s[y+2]) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(s[y+2]) && |
0 |
0 |
0 |
|
| 70 |
0 |
▶ | sscanf(&s[y+1], "%02X", &hex)) { |
Branch: 1 branch
| Branch | True | False | Total |
| sscanf(&s[y+1], "%02X", &hex)) { |
0 |
0 |
0 |
|
| 71 |
0 |
| s[x] = hex; |
| 72 |
0 |
| y+=2; |
| 73 |
0 |
▶ | } else if(x > 0 && isDIGIT(s[y-1]) && strchr(chrend, s[y+1])) { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if(x > 0 && isDIGIT(s[y-1]) && strchr(chrend, s[y+1])) { |
0 |
0 |
0 |
| } else if(x > 0 && isDIGIT(s[y-1]) && strchr(chrend, s[y+1])) { |
0 |
0 |
0 |
| } else if(x > 0 && isDIGIT(s[y-1]) && strchr(chrend, s[y+1])) { |
0 |
0 |
0 |
|
| 74 |
0 |
| int j = 2; |
| 75 |
0 |
▶ | while(isDIGIT(s[x-j])) j++; |
Branch: 1 branch
| Branch | True | False | Total |
| while(isDIGIT(s[x-j])) j++; |
0 |
0 |
0 |
|
| 76 |
0 |
▶ | if(!strchr(chrend, s[x-j])) s[x] = ' '; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strchr(chrend, s[x-j])) s[x] = ' '; |
0 |
0 |
0 |
|
| 77 |
0 |
| } else s[x] = ' '; |
| 78 |
|
| } |
| 79 |
|
| } |
| 80 |
2 |
| s[x] = '\0'; |
| 81 |
2 |
| } |
| 82 |
|
| |
| 83 |
0 |
| bool entity2char(unsigned char **s, unsigned char *cstr, |
| 84 |
|
| unsigned int len, unsigned char c) { |
| 85 |
0 |
▶ | if(strncmp(*s, cstr, len) == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(strncmp(*s, cstr, len) == 0) { |
0 |
0 |
0 |
|
| 86 |
0 |
| *s = *s+len-1; |
| 87 |
0 |
| **s = c; |
| 88 |
0 |
| return TRUE; |
| 89 |
|
| } |
| 90 |
0 |
| return FALSE; |
| 91 |
|
| } |
| 92 |
|
| |
| 93 |
2 |
| void str2lower(unsigned char *s) { |
| 94 |
59 |
▶ | while(*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*s) { |
57 |
2 |
59 |
|
| 95 |
57 |
▶ | if(isalpha(*s)) *s = tolower(*s); |
Branch: 1 branch
| Branch | True | False | Total |
| if(isalpha(*s)) *s = tolower(*s); |
49 |
8 |
57 |
|
| 96 |
57 |
| s++; |
| 97 |
|
| } |
| 98 |
2 |
| } |
| 99 |
|
| |
| 100 |
2 |
| void clean_repeated_chars(unsigned char *s) { |
| 101 |
2 |
| unsigned char *p = s; |
| 102 |
59 |
▶ | while(*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*s) { |
57 |
2 |
59 |
|
| 103 |
57 |
▶ | if(*s == '#' && isxdigit(*(s+1))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(*s == '#' && isxdigit(*(s+1))) { |
0 |
57 |
57 |
| if(*s == '#' && isxdigit(*(s+1))) { |
0 |
0 |
0 |
|
| 104 |
0 |
▶ | while(*s == '#' || isxdigit(*s)) { |
Branch: 2 branches
| Branch | True | False | Total |
| while(*s == '#' || isxdigit(*s)) { |
0 |
0 |
0 |
| while(*s == '#' || isxdigit(*s)) { |
0 |
0 |
0 |
|
| 105 |
0 |
| *p = *s; |
| 106 |
0 |
| s++; |
| 107 |
0 |
| p++; |
| 108 |
|
| } |
| 109 |
|
| } |
| 110 |
57 |
▶ | if(isalpha(*s) && *s == *(s+1) && *s == *(s+2)) |
Branch: 3 branches
| Branch | True | False | Total |
| if(isalpha(*s) && *s == *(s+1) && *s == *(s+2)) |
49 |
8 |
57 |
| if(isalpha(*s) && *s == *(s+1) && *s == *(s+2)) |
0 |
49 |
49 |
| if(isalpha(*s) && *s == *(s+1) && *s == *(s+2)) |
0 |
0 |
0 |
|
| 111 |
0 |
▶ | while(*s == *(s+1)) s++; |
Branch: 1 branch
| Branch | True | False | Total |
| while(*s == *(s+1)) s++; |
0 |
0 |
0 |
|
| 112 |
57 |
| *p = *s; |
| 113 |
57 |
| s++; |
| 114 |
57 |
| p++; |
| 115 |
|
| } |
| 116 |
2 |
| *p = '\0'; |
| 117 |
2 |
| } |
| 118 |
|
| |
| 119 |
0 |
| bool extension(unsigned char *s, unsigned char *extension, int len) { |
| 120 |
0 |
▶ | return((!strncmp(s, extension, len) && !isalpha(*(s+len+1))) ? TRUE : FALSE); |
Branch: 2 branches
| Branch | True | False | Total |
| return((!strncmp(s, extension, len) && !isalpha(*(s+len+1))) ? TRUE : FALSE); |
0 |
0 |
0 |
| return((!strncmp(s, extension, len) && !isalpha(*(s+len+1))) ? TRUE : FALSE); |
0 |
0 |
0 |
|
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
0 |
| bool check_extension(unsigned char *s) { |
| 124 |
0 |
| return( extension(s, "asp", 3) ? TRUE : |
| 125 |
0 |
▶ | extension(s, "html", 4) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "html", 4) ? TRUE : |
0 |
0 |
0 |
|
| 126 |
0 |
▶ | extension(s, "htm", 3) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "htm", 3) ? TRUE : |
0 |
0 |
0 |
|
| 127 |
0 |
▶ | extension(s, "gif", 3) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "gif", 3) ? TRUE : |
0 |
0 |
0 |
|
| 128 |
0 |
▶ | extension(s, "png", 3) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "png", 3) ? TRUE : |
0 |
0 |
0 |
|
| 129 |
0 |
▶ | extension(s, "jpeg", 4) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "jpeg", 4) ? TRUE : |
0 |
0 |
0 |
|
| 130 |
0 |
▶ | extension(s, "jpg", 3) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "jpg", 3) ? TRUE : |
0 |
0 |
0 |
|
| 131 |
0 |
▶ | extension(s, "js", 2) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "js", 2) ? TRUE : |
0 |
0 |
0 |
|
| 132 |
0 |
▶ | extension(s, "swf", 3) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "swf", 3) ? TRUE : |
0 |
0 |
0 |
|
| 133 |
0 |
▶ | extension(s, "pl", 2) ? TRUE : |
Branch: 1 branch
| Branch | True | False | Total |
| extension(s, "pl", 2) ? TRUE : |
0 |
0 |
0 |
|
| 134 |
0 |
| extension(s, "php", 3) ? TRUE : FALSE); |
| 135 |
|
| } |
| 136 |
|
| |
| 137 |
|
| |
| 138 |
8 |
| bool space_words(unsigned char *s, unsigned char c) { |
| 139 |
8 |
| unsigned char *p = s; |
| 140 |
8 |
| int space = 1; |
| 141 |
8 |
| int letter = 0; |
| 142 |
8 |
| p++; |
| 143 |
61 |
▶ | while(*p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*p) { |
59 |
2 |
61 |
|
| 144 |
59 |
▶ | if(*p == c) space++; |
Branch: 1 branch
| Branch | True | False | Total |
| if(*p == c) space++; |
2 |
57 |
59 |
|
| 145 |
57 |
▶ | else if(isalpha(*p)) letter++; |
Branch: 1 branch
| Branch | True | False | Total |
| else if(isalpha(*p)) letter++; |
51 |
6 |
57 |
|
| 146 |
6 |
| else break; |
| 147 |
53 |
| p++; |
| 148 |
|
| } |
| 149 |
8 |
▶ | return((space > MINSPACELETTERS && space == letter) ? TRUE : FALSE); |
Branch: 2 branches
| Branch | True | False | Total |
| return((space > MINSPACELETTERS && space == letter) ? TRUE : FALSE); |
0 |
8 |
8 |
| return((space > MINSPACELETTERS && space == letter) ? TRUE : FALSE); |
0 |
0 |
0 |
|
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
0 |
| bool hex_dec(unsigned char *s) { |
| 153 |
0 |
| return((strchr(" \":", *(s-1)) && |
| 154 |
0 |
▶ | isxdigit(*(s+1)) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(*(s+1)) && |
0 |
0 |
0 |
|
| 155 |
0 |
▶ | isxdigit(*(s+2)) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(*(s+2)) && |
0 |
0 |
0 |
|
| 156 |
0 |
▶ | isxdigit(*(s+3)) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(*(s+3)) && |
0 |
0 |
0 |
|
| 157 |
0 |
▶ | isxdigit(*(s+4)) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(*(s+4)) && |
0 |
0 |
0 |
|
| 158 |
0 |
▶ | isxdigit(*(s+5)) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(*(s+5)) && |
0 |
0 |
0 |
|
| 159 |
0 |
▶ | isxdigit(*(s+6)) && |
Branch: 1 branch
| Branch | True | False | Total |
| isxdigit(*(s+6)) && |
0 |
0 |
0 |
|
| 160 |
0 |
▶ | !isalnum(*(s+7))) ? TRUE : FALSE); |
Branch: 2 branches
| Branch | True | False | Total |
| !isalnum(*(s+7))) ? TRUE : FALSE); |
0 |
0 |
0 |
| !isalnum(*(s+7))) ? TRUE : FALSE); |
0 |
0 |
0 |
|
| 161 |
|
| } |
| 162 |
|
| |
| 163 |
0 |
| bool multiword(unsigned char *s) { |
| 164 |
0 |
| unsigned char *p = s; |
| 165 |
0 |
| int c = 0; |
| 166 |
0 |
| p--; |
| 167 |
0 |
▶ | while(*p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*p) { |
0 |
0 |
0 |
|
| 168 |
0 |
▶ | if(isalnum(*p)) c++; |
Branch: 1 branch
| Branch | True | False | Total |
| if(isalnum(*p)) c++; |
0 |
0 |
0 |
|
| 169 |
0 |
| else break; |
| 170 |
0 |
| p--; |
| 171 |
|
| } |
| 172 |
0 |
▶ | if(c <= MINLENMULTIWORD) return FALSE; |
Branch: 1 branch
| Branch | True | False | Total |
| if(c <= MINLENMULTIWORD) return FALSE; |
0 |
0 |
0 |
|
| 173 |
0 |
| c = 0; |
| 174 |
0 |
| s++; |
| 175 |
0 |
▶ | while(*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*s) { |
0 |
0 |
0 |
|
| 176 |
0 |
▶ | if(isalnum(*s)) c++; |
Branch: 1 branch
| Branch | True | False | Total |
| if(isalnum(*s)) c++; |
0 |
0 |
0 |
|
| 177 |
0 |
| else break; |
| 178 |
0 |
| s++; |
| 179 |
|
| } |
| 180 |
0 |
| return((c > MINLENMULTIWORD) ? TRUE : FALSE); |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
2 |
| void str_normalize(unsigned char *s) { |
| 184 |
2 |
| unsigned char *p = s; |
| 185 |
|
| |
| 186 |
2 |
▶ | while(*s && !isalnum(*s) && *s != '&' && *s != '(') s++; |
Branch: 4 branches
| Branch | True | False | Total |
| while(*s && !isalnum(*s) && *s != '&' && *s != '(') s++; |
2 |
0 |
2 |
| while(*s && !isalnum(*s) && *s != '&' && *s != '(') s++; |
0 |
2 |
2 |
| while(*s && !isalnum(*s) && *s != '&' && *s != '(') s++; |
0 |
0 |
0 |
| while(*s && !isalnum(*s) && *s != '&' && *s != '(') s++; |
0 |
0 |
0 |
|
| 187 |
2 |
| str2lower(s); |
| 188 |
59 |
▶ | while(*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*s) { |
57 |
2 |
59 |
|
| 189 |
57 |
▶ | if(*s == '&') { |
Branch: 1 branch
| Branch | True | False | Total |
| if(*s == '&') { |
0 |
57 |
57 |
|
| 190 |
|
| register int i; |
| 191 |
0 |
▶ | for(i=0; i<28; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<28; i++) |
0 |
0 |
0 |
|
| 192 |
0 |
▶ | if(entity2char(&s, entities[i].entity, entities[i].length, entities[i].character)) |
Branch: 1 branch
| Branch | True | False | Total |
| if(entity2char(&s, entities[i].entity, entities[i].length, entities[i].character)) |
0 |
0 |
0 |
|
| 193 |
0 |
| break; |
| 194 |
|
| } |
| 195 |
57 |
▶ | if(isalpha(*(s-1)) && strchr(chrsep, *s) && isalpha(*(s+1))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if(isalpha(*(s-1)) && strchr(chrsep, *s) && isalpha(*(s+1))) { |
47 |
10 |
57 |
| if(isalpha(*(s-1)) && strchr(chrsep, *s) && isalpha(*(s+1))) { |
8 |
39 |
47 |
| if(isalpha(*(s-1)) && strchr(chrsep, *s) && isalpha(*(s+1))) { |
8 |
0 |
8 |
|
| 196 |
8 |
▶ | if(space_words(s, *s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(space_words(s, *s)) { |
0 |
8 |
8 |
|
| 197 |
0 |
| char c = *s; |
| 198 |
0 |
▶ | while(*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| while(*s) { |
0 |
0 |
0 |
|
| 199 |
0 |
▶ | if(*s == c) s++; |
Branch: 1 branch
| Branch | True | False | Total |
| if(*s == c) s++; |
0 |
0 |
0 |
|
| 200 |
0 |
▶ | else if(!isalpha(*s)) break; |
Branch: 1 branch
| Branch | True | False | Total |
| else if(!isalpha(*s)) break; |
0 |
0 |
0 |
|
| 201 |
0 |
| *p = *s; |
| 202 |
0 |
| s++; |
| 203 |
0 |
| p++; |
| 204 |
|
| } |
| 205 |
|
| } |
| 206 |
|
| } |
| 207 |
57 |
▶ | if((*s == '_' || *s == '-' || *s == '\'') && (!isalnum(*(s+1)) || !isalnum(*(s-1)))) |
Branch: 5 branches
| Branch | True | False | Total |
| if((*s == '_' || *s == '-' || *s == '\'') && (!isalnum(*(s+1)) || !isalnum(*(s-1)))) |
55 |
2 |
57 |
| if((*s == '_' || *s == '-' || *s == '\'') && (!isalnum(*(s+1)) || !isalnum(*(s-1)))) |
55 |
0 |
55 |
| if((*s == '_' || *s == '-' || *s == '\'') && (!isalnum(*(s+1)) || !isalnum(*(s-1)))) |
0 |
55 |
55 |
| if((*s == '_' || *s == '-' || *s == '\'') && (!isalnum(*(s+1)) || !isalnum(*(s-1)))) |
2 |
0 |
2 |
| if((*s == '_' || *s == '-' || *s == '\'') && (!isalnum(*(s+1)) || !isalnum(*(s-1)))) |
0 |
2 |
2 |
|
| 208 |
0 |
| *s = ' '; |
| 209 |
57 |
▶ | else if(*s == '0' && isalpha(*(s+1)) && isalpha(*(s-1))) |
Branch: 3 branches
| Branch | True | False | Total |
| else if(*s == '0' && isalpha(*(s+1)) && isalpha(*(s-1))) |
0 |
57 |
57 |
| else if(*s == '0' && isalpha(*(s+1)) && isalpha(*(s-1))) |
0 |
0 |
0 |
| else if(*s == '0' && isalpha(*(s+1)) && isalpha(*(s-1))) |
0 |
0 |
0 |
|
| 210 |
0 |
| *s = 'o'; |
| 211 |
57 |
▶ | else if(*s == '(' && *(s+1) == ')' && isalpha(*(s+2)) && isalpha(*(s-1))) { |
Branch: 4 branches
| Branch | True | False | Total |
| else if(*s == '(' && *(s+1) == ')' && isalpha(*(s+2)) && isalpha(*(s-1))) { |
0 |
57 |
57 |
| else if(*s == '(' && *(s+1) == ')' && isalpha(*(s+2)) && isalpha(*(s-1))) { |
0 |
0 |
0 |
| else if(*s == '(' && *(s+1) == ')' && isalpha(*(s+2)) && isalpha(*(s-1))) { |
0 |
0 |
0 |
| else if(*s == '(' && *(s+1) == ')' && isalpha(*(s+2)) && isalpha(*(s-1))) { |
0 |
0 |
0 |
|
| 212 |
0 |
| *(s+1) = 'o'; |
| 213 |
0 |
| s++; |
| 214 |
57 |
▶ | } else if(*s == '.') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(*s == '.') { |
0 |
57 |
57 |
|
| 215 |
0 |
▶ | if(!((isdigit(*(s-1)) && isdigit(*(s+1))) || check_extension(s+1))) |
Branch: 3 branches
| Branch | True | False | Total |
| if(!((isdigit(*(s-1)) && isdigit(*(s+1))) || check_extension(s+1))) |
0 |
0 |
0 |
| if(!((isdigit(*(s-1)) && isdigit(*(s+1))) || check_extension(s+1))) |
0 |
0 |
0 |
| if(!((isdigit(*(s-1)) && isdigit(*(s+1))) || check_extension(s+1))) |
0 |
0 |
0 |
|
| 216 |
0 |
| *s = ' '; |
| 217 |
57 |
▶ | } else if(*s == '-') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(*s == '-') { |
0 |
57 |
57 |
|
| 218 |
0 |
▶ | if(multiword(s)) *s = ' '; |
Branch: 1 branch
| Branch | True | False | Total |
| if(multiword(s)) *s = ' '; |
0 |
0 |
0 |
|
| 219 |
57 |
▶ | } else if(*s == '#') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(*s == '#') { |
0 |
57 |
57 |
|
| 220 |
0 |
▶ | if(hex_dec(s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hex_dec(s)) { |
0 |
0 |
0 |
|
| 221 |
0 |
▶ | while(*s == '#' || isxdigit(*s)) { |
Branch: 2 branches
| Branch | True | False | Total |
| while(*s == '#' || isxdigit(*s)) { |
0 |
0 |
0 |
| while(*s == '#' || isxdigit(*s)) { |
0 |
0 |
0 |
|
| 222 |
0 |
| *p = *s; |
| 223 |
0 |
| s++; |
| 224 |
0 |
| p++; |
| 225 |
|
| } |
| 226 |
|
| } else |
| 227 |
0 |
| *s = ' '; |
| 228 |
57 |
▶ | } else if(*s == '@' && |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(*s == '@' && |
0 |
57 |
57 |
|
| 229 |
0 |
▶ | *(s-1) != 'a' && *(s-1) != 'A' && isalpha(*(s-1)) && |
Branch: 3 branches
| Branch | True | False | Total |
| *(s-1) != 'a' && *(s-1) != 'A' && isalpha(*(s-1)) && |
0 |
0 |
0 |
| *(s-1) != 'a' && *(s-1) != 'A' && isalpha(*(s-1)) && |
0 |
0 |
0 |
| *(s-1) != 'a' && *(s-1) != 'A' && isalpha(*(s-1)) && |
0 |
0 |
0 |
|
| 230 |
0 |
▶ | *(s+1) != 'a' && *(s+1) != 'A' && isalpha(*(s+1))) { |
Branch: 3 branches
| Branch | True | False | Total |
| *(s+1) != 'a' && *(s+1) != 'A' && isalpha(*(s+1))) { |
0 |
0 |
0 |
| *(s+1) != 'a' && *(s+1) != 'A' && isalpha(*(s+1))) { |
0 |
0 |
0 |
| *(s+1) != 'a' && *(s+1) != 'A' && isalpha(*(s+1))) { |
0 |
0 |
0 |
|
| 231 |
0 |
| unsigned int i = 2; |
| 232 |
0 |
▶ | while(*(s+i) && isalpha(*(s+i))) i++; |
Branch: 2 branches
| Branch | True | False | Total |
| while(*(s+i) && isalpha(*(s+i))) i++; |
0 |
0 |
0 |
| while(*(s+i) && isalpha(*(s+i))) i++; |
0 |
0 |
0 |
|
| 233 |
0 |
▶ | if(!(*(s+i) == '.' && isalpha(*(s+i+1)))) *s = 'a'; |
Branch: 2 branches
| Branch | True | False | Total |
| if(!(*(s+i) == '.' && isalpha(*(s+i+1)))) *s = 'a'; |
0 |
0 |
0 |
| if(!(*(s+i) == '.' && isalpha(*(s+i+1)))) *s = 'a'; |
0 |
0 |
0 |
|
| 234 |
|
| } |
| 235 |
57 |
| *p = *s; |
| 236 |
57 |
| s++; |
| 237 |
57 |
| p++; |
| 238 |
|
| } |
| 239 |
2 |
| *p = '\0'; |
| 240 |
2 |
| } |
| 241 |
|
| |
| 242 |
|
| MODULE = Text::ExtractWords PACKAGE = Text::ExtractWords PREFIX = ew_ |
| 243 |
|
| |
| 244 |
|
| PROTOTYPES: DISABLE |
| 245 |
|
| |
| 246 |
|
| void |
| 247 |
|
| ew_words_list(aref, source, ...) |
| 248 |
|
| SV *aref; |
| 249 |
|
| char *source; |
| 250 |
|
| PREINIT: |
| 251 |
1 |
| char *locale = NULL; |
| 252 |
1 |
| char *t = NULL; |
| 253 |
1 |
| I32 n = 0; |
| 254 |
1 |
| I32 minlenword = MINLENWORD; |
| 255 |
1 |
| I32 maxlenword = MAXLENWORD; |
| 256 |
|
| PPCODE: |
| 257 |
1 |
▶ | if(items == 3) {SV *hconf = ST(2); |
Branch: 1 branch
| Branch | True | False | Total |
| if(items == 3) {SV *hconf = ST(2); |
0 |
1 |
1 |
|
| 258 |
0 |
▶ | if(SvROK(hconf) && SvTYPE(SvRV(hconf)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvROK(hconf) && SvTYPE(SvRV(hconf)) == SVt_PVHV) { |
0 |
0 |
0 |
| if(SvROK(hconf) && SvTYPE(SvRV(hconf)) == SVt_PVHV) { |
0 |
0 |
0 |
|
| 259 |
0 |
| HV *hv = (HV *)SvRV(hconf); |
| 260 |
0 |
▶ | if(hv_exists(hv, "minlen", 6)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, "minlen", 6)) { |
0 |
0 |
0 |
|
| 261 |
0 |
| SV **svalue = hv_fetch(hv, "minlen", 6, 0); |
| 262 |
0 |
| minlenword = SvIV(*svalue); |
| 263 |
|
| } |
| 264 |
0 |
▶ | if(hv_exists(hv, "maxlen", 6)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, "maxlen", 6)) { |
0 |
0 |
0 |
|
| 265 |
0 |
| SV **svalue = hv_fetch(hv, "maxlen", 6, 0); |
| 266 |
0 |
| maxlenword = SvIV(*svalue); |
| 267 |
|
| } |
| 268 |
0 |
▶ | if(hv_exists(hv, "locale", 6)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, "locale", 6)) { |
0 |
0 |
0 |
|
| 269 |
0 |
| SV **svalue = hv_fetch(hv, "locale", 6, 0); |
| 270 |
0 |
| locale = SvPV(*svalue, PL_na); |
| 271 |
|
| } |
| 272 |
|
| } else |
| 273 |
0 |
| croak("not hash ref passed to Text::ExtractWords::words_list"); |
| 274 |
|
| } |
| 275 |
|
| #ifdef HAVE_LOCALE_H |
| 276 |
|
| if(locale) set_locale(locale); |
| 277 |
|
| #endif |
| 278 |
2 |
▶ | if(SvROK(aref) && SvTYPE(SvRV(aref)) == SVt_PVAV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvROK(aref) && SvTYPE(SvRV(aref)) == SVt_PVAV) { |
1 |
0 |
1 |
| if(SvROK(aref) && SvTYPE(SvRV(aref)) == SVt_PVAV) { |
1 |
0 |
1 |
|
| 279 |
|
| unsigned long ls; |
| 280 |
1 |
▶ | if(ls = strlen(source)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(ls = strlen(source)) { |
1 |
0 |
1 |
|
| 281 |
1 |
| AV *av = (AV *)SvRV(aref); |
| 282 |
1 |
| unescape_str(source); |
| 283 |
1 |
| str_normalize(source); |
| 284 |
|
| //fprintf(stdout, "-->%s<--\n", source); |
| 285 |
1 |
| clean_repeated_chars(source); |
| 286 |
5 |
▶ | for(t = strtok(source, delimiters); t != NULL; t = strtok(NULL, delimiters)) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(t = strtok(source, delimiters); t != NULL; t = strtok(NULL, delimiters)) { |
4 |
1 |
5 |
|
| 287 |
4 |
| n = strlen(t); |
| 288 |
4 |
▶ | if(n >= minlenword && n <= maxlenword) |
Branch: 2 branches
| Branch | True | False | Total |
| if(n >= minlenword && n <= maxlenword) |
4 |
0 |
4 |
| if(n >= minlenword && n <= maxlenword) |
4 |
0 |
4 |
|
| 289 |
4 |
| av_push(av, newSVpv(t, n)); |
| 290 |
|
| } |
| 291 |
|
| } |
| 292 |
|
| } else |
| 293 |
0 |
| croak("not array ref passed to Text::ExtractWords::words_list"); |
| 294 |
|
| |
| 295 |
|
| |
| 296 |
|
| |
| 297 |
|
| void |
| 298 |
|
| ew_words_count(href, source, ...) |
| 299 |
|
| SV *href; |
| 300 |
|
| char *source; |
| 301 |
|
| PREINIT: |
| 302 |
1 |
| char *locale = NULL; |
| 303 |
1 |
| char *t = NULL; |
| 304 |
1 |
| I32 n = 0; |
| 305 |
1 |
| I32 minlenword = MINLENWORD; |
| 306 |
1 |
| I32 maxlenword = MAXLENWORD; |
| 307 |
|
| unsigned long count; |
| 308 |
|
| PPCODE: |
| 309 |
1 |
▶ | if(items == 3) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(items == 3) { |
0 |
1 |
1 |
|
| 310 |
0 |
| SV *hconf = ST(2); |
| 311 |
0 |
▶ | if(SvROK(hconf) && SvTYPE(SvRV(hconf)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvROK(hconf) && SvTYPE(SvRV(hconf)) == SVt_PVHV) { |
0 |
0 |
0 |
| if(SvROK(hconf) && SvTYPE(SvRV(hconf)) == SVt_PVHV) { |
0 |
0 |
0 |
|
| 312 |
0 |
| HV *hv = (HV *)SvRV(hconf); |
| 313 |
0 |
▶ | if(hv_exists(hv, "minlen", 6)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, "minlen", 6)) { |
0 |
0 |
0 |
|
| 314 |
0 |
| SV **svalue = hv_fetch(hv, "minlen", 6, 0); |
| 315 |
0 |
| minlenword = SvIV(*svalue); |
| 316 |
|
| } |
| 317 |
0 |
▶ | if(hv_exists(hv, "maxlen", 6)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, "maxlen", 6)) { |
0 |
0 |
0 |
|
| 318 |
0 |
| SV **svalue = hv_fetch(hv, "maxlen", 6, 0); |
| 319 |
0 |
| maxlenword = SvIV(*svalue); |
| 320 |
|
| } |
| 321 |
0 |
▶ | if(hv_exists(hv, "locale", 6)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, "locale", 6)) { |
0 |
0 |
0 |
|
| 322 |
0 |
| SV **svalue = hv_fetch(hv, "locale", 6, 0); |
| 323 |
0 |
| locale = SvPV(*svalue, PL_na); |
| 324 |
|
| } |
| 325 |
|
| } else |
| 326 |
0 |
| croak("not hash ref passed to Text::ExtractWords::words_count"); |
| 327 |
|
| } |
| 328 |
|
| #ifdef HAVE_LOCALE_H |
| 329 |
|
| if(locale) set_locale(locale); |
| 330 |
|
| #endif |
| 331 |
2 |
▶ | if(SvROK(href) && SvTYPE(SvRV(href)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvROK(href) && SvTYPE(SvRV(href)) == SVt_PVHV) { |
1 |
0 |
1 |
| if(SvROK(href) && SvTYPE(SvRV(href)) == SVt_PVHV) { |
1 |
0 |
1 |
|
| 332 |
|
| unsigned long ls; |
| 333 |
1 |
▶ | if(ls = strlen(source)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(ls = strlen(source)) { |
1 |
0 |
1 |
|
| 334 |
1 |
| HV *hv = (HV *)SvRV(href); |
| 335 |
1 |
| unescape_str(source); |
| 336 |
1 |
| str_normalize(source); |
| 337 |
|
| //fprintf(stdout, "-->%s<--\n", source); |
| 338 |
1 |
| clean_repeated_chars(source); |
| 339 |
5 |
▶ | for(t = strtok(source, delimiters); t != NULL; t = strtok(NULL, delimiters)) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(t = strtok(source, delimiters); t != NULL; t = strtok(NULL, delimiters)) { |
4 |
1 |
5 |
|
| 340 |
4 |
| n = strlen(t); |
| 341 |
4 |
▶ | if(n >= minlenword && n <= maxlenword) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(n >= minlenword && n <= maxlenword) { |
4 |
0 |
4 |
| if(n >= minlenword && n <= maxlenword) { |
4 |
0 |
4 |
|
| 342 |
4 |
| count = 1; |
| 343 |
4 |
▶ | if(hv_exists(hv, t, n)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(hv_exists(hv, t, n)) { |
0 |
4 |
4 |
|
| 344 |
0 |
| SV **svalue = hv_fetch(hv, t, n, 0); |
| 345 |
0 |
| count = SvIV(*svalue) + 1; |
| 346 |
|
| } |
| 347 |
4 |
| hv_store(hv, t, n, newSViv(count), 0); |
| 348 |
|
| } |
| 349 |
|
| } |
| 350 |
|
| } |
| 351 |
|
| } else |
| 352 |
0 |
| croak("not hash ref passed to Text::ExtractWords::words_count"); |