whitesimilarity 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/whitesimilarity/white_similarity.c +14 -23
- data/lib/whitesimilarity/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 989d7bbd270d24ec06fd2c1cc7b7e9ec8490821b
|
4
|
+
data.tar.gz: e620c02c583df7e98aa16c10b859ec27e91371a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f7b6b822ff5a4c2b9899eeea22141079328b94910da171479dd6206c1b7daeb46594b8f7d8d2856c9f33965f85037e3077463a765d55e709e790f828f4874a2
|
7
|
+
data.tar.gz: f9f2d8022bbc8ca05361780ac9e8894d71b83ea840d02a1df19404e31c04154657235e354208272935fe5841c15786172cc188d9443de90f19cde22126911d4b
|
@@ -1,6 +1,5 @@
|
|
1
1
|
#include <ctype.h>
|
2
2
|
#include <stdlib.h>
|
3
|
-
#include <string.h>
|
4
3
|
#include <stdio.h>
|
5
4
|
#include "white_similarity.h"
|
6
5
|
|
@@ -9,14 +8,8 @@
|
|
9
8
|
#define will_make_bad_pair(str, i) \
|
10
9
|
(_empty_char(*(str + i)) || _empty_char(*(str + i + 1)) || _null_char(*(str + i + 1)))
|
11
10
|
|
12
|
-
#define pairs_equal(a, b) (
|
13
|
-
|
14
|
-
// Free up a pair
|
15
|
-
void destroy_pair(char *pair) {
|
16
|
-
if (pair != NULL) {
|
17
|
-
free(pair);
|
18
|
-
}
|
19
|
-
}
|
11
|
+
#define pairs_equal(a, b) (a[0] == b[0] && a[1] == b[1])
|
12
|
+
#define destroy_pair(p) if (p != NULL) free(p)
|
20
13
|
|
21
14
|
// Remove a pair struct from a pairs struct at the index p
|
22
15
|
void remove_pair_at(int num_pairs, char **pairs, int p) {
|
@@ -37,7 +30,7 @@ int get_num_pairs(char *str) {
|
|
37
30
|
int i = 0;
|
38
31
|
int num_pairs = 0;
|
39
32
|
|
40
|
-
while (
|
33
|
+
while (str[i] != '\0') {
|
41
34
|
if (!will_make_bad_pair(str, i)) {
|
42
35
|
num_pairs++;
|
43
36
|
}
|
@@ -51,25 +44,23 @@ int get_num_pairs(char *str) {
|
|
51
44
|
// Create the pairs from the string
|
52
45
|
char **letter_pairs(int num_pairs, char *str) {
|
53
46
|
int i = 0;
|
54
|
-
int l = strlen(str);
|
55
47
|
int counter = 0;
|
56
48
|
char **pairs = calloc(num_pairs, sizeof(char *));
|
57
49
|
char *pair = NULL;
|
58
50
|
|
59
|
-
|
60
|
-
if (will_make_bad_pair(str, i)) {
|
61
|
-
|
51
|
+
while (str[i] != '\0') {
|
52
|
+
if (!will_make_bad_pair(str, i)) {
|
53
|
+
// Create and add pair
|
54
|
+
pair = calloc(2, sizeof(char));
|
55
|
+
pair[0] = toupper(str[i]);
|
56
|
+
pair[1] = toupper(str[i + 1]);
|
57
|
+
pairs[counter] = pair;
|
58
|
+
|
59
|
+
// Increment the counter for adding the pair to the pairs struct
|
60
|
+
counter++;
|
62
61
|
}
|
63
62
|
|
64
|
-
|
65
|
-
pair = calloc(3, sizeof(char));
|
66
|
-
strncpy(pair, str + i, 2);
|
67
|
-
pair[0] = toupper(pair[0]);
|
68
|
-
pair[1] = toupper(pair[1]);
|
69
|
-
pairs[counter] = pair;
|
70
|
-
|
71
|
-
// Increment the counter for adding the pair to the pairs struct
|
72
|
-
counter++;
|
63
|
+
i++;
|
73
64
|
}
|
74
65
|
|
75
66
|
return pairs;
|