Пример #1
0
void
test_valid_chars() {
  test_start("valid_chars");

  int error;

  error = semver_is_valid("1");
  assert(error == 1);

  error = semver_is_valid("159");
  assert(error == 1);

  error = semver_is_valid("1b3");
  assert(error == 1);

  error = semver_is_valid("3 0 1");
  assert(error == 0);

  error = semver_is_valid("&3@(");
  assert(error == 0);

  test_end();
}
Пример #2
0
int
semver_parse (const char *str, semver_t *ver) {
  int valid, res;
  size_t len;
  char *buf;
  valid = semver_is_valid(str);
  if (!valid) return -1;

  len = strlen(str);
  buf = calloc(len + 1, sizeof(*buf));
  if (buf == NULL) return -1;
  strcpy(buf, str);

  ver->metadata = parse_slice(buf, MT_DELIMITER[0]);
  ver->prerelease = parse_slice(buf, PR_DELIMITER[0]);

  res = semver_parse_version(buf, ver);
  free(buf);
#if DEBUG > 0
  printf("[debug] semver.c %s = %d.%d.%d, %s %s\n", str, ver->major, ver->minor, ver->patch, ver->prerelease, ver->metadata);
#endif
  return res;
}