whitesimilarity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8541649d68a1eb5b9c3a2c6cf124b48bac8208e
4
- data.tar.gz: fbcd07629cc9fa1fabb3e972230aba7a307b823f
3
+ metadata.gz: 989d7bbd270d24ec06fd2c1cc7b7e9ec8490821b
4
+ data.tar.gz: e620c02c583df7e98aa16c10b859ec27e91371a9
5
5
  SHA512:
6
- metadata.gz: 7b476b7d3721dbed81ee2faf7e536362f932d93150f02b5344e2c20ccad4de20cd686f01aedbb8d5372bc747eb3475cb957a628be995872421f8b8a543855696
7
- data.tar.gz: 8a7271acc8e094628483db963ca7c75be8c18c1e03371f0454b2643995b8a8e5742f187ea51588156e91a6dc2ad47be7091d16985d23408369a18051dae05594
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) (strcmp(a, b) == 0)
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 (*(str + i) != '\0') {
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
- for (i = 0; i < l; i++) {
60
- if (will_make_bad_pair(str, i)) {
61
- continue;
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
- // Create and add pair
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;
@@ -1,3 +1,3 @@
1
1
  module WhiteSimilarity
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whitesimilarity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Fairbank