summaryrefslogtreecommitdiff
path: root/lib/hitomezashi_utils.c
blob: 93ec850d1aab5cf77ca70e2d8caea2b8f30f09e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "hitomezashi_utils.h"

#include <stddef.h>
#include <stdlib.h>

char *hitomezashi_ascii_binary_str_to_ints(const char *ascii_str, size_t len) {
  char *res = malloc(len);
  for (int i = 0; i < len; ++i) {
    switch (ascii_str[i]) {
    case '0':;
      res[i] = 0;
      break;
    case '1':;
      res[i] = 1;
      break;
    default:;
      free(res);
      return NULL;
    }
  }
  return res;
}