12 char *restrict dst,
const ptrdiff_t dst_max,
size_t *dst_offset,
13 const char *restrict src,
const ptrdiff_t src_max,
size_t *src_offset,
16 const size_t d = dst_offset ? *dst_offset : 0;
17 const size_t s = src_offset ? *src_offset : 0;
20 for (i = 0; (ptrdiff_t)(i + s) < src_max && src[i + s] && src[i + s] != delim; i++)
21 if ((ptrdiff_t)(i + d) < dst_max) dst[i + d] = src[i + s];
23 if (dst_offset) *dst_offset = d + i;
24 if (src_offset) *src_offset = s + i;
33 char filename[REGION_FILENAME_MAX + 1],
34 const char prefix[PREFIX_MAX],
35 const char *extension,
36 const int64_t *pos,
const uint8_t dims
38 assert(dims <= CLOD_REGION_DIMENSIONS_MAX);
39 memset(filename, 0, REGION_FILENAME_MAX + 1);
42 str_copy(filename, REGION_FILENAME_MAX, &offset, prefix, CLOD_REGION_PREFIX_MAX,
nullptr,
'.');
43 str_copy(filename, REGION_FILENAME_MAX, &offset,
".", 1,
nullptr, 0);
45 for (
int i = 0; i < dims; i++) {
46 const size_t max_len = offset > REGION_FILENAME_MAX ? 0 : REGION_FILENAME_MAX - offset;
47 char *cursor = offset > REGION_FILENAME_MAX ? filename + REGION_FILENAME_MAX : filename + offset;
48 offset += (size_t)snprintf(cursor, max_len,
"%"PRId64
".", pos[i]);
51 str_copy(filename, REGION_FILENAME_MAX, &offset, extension, EXTENSION_MAX,
nullptr, 0);
52 assert(offset <= REGION_FILENAME_MAX);
60bool filename_parse_pos(
const char filename[REGION_FILENAME_MAX + 1],
61 const char prefix[PREFIX_MAX],
62 const char *extension,
63 int64_t *pos,
const uint8_t dims
66 while (offset < PREFIX_MAX && prefix[offset]) {
67 if (prefix[offset] != filename[offset])
return false;
71 if (filename[offset] !=
'.')
return false;
74 for (uint8_t i = 0; i < dims; i++) {
76 pos[i] = strtoll(&filename[offset], &end, 10);
77 if (end == filename + offset)
return false;
78 offset += (size_t)(end - filename) + 1;
81 size_t extension_offset = 0;
82 while (extension_offset < EXTENSION_MAX && extension[extension_offset]) {
83 if (extension[extension_offset] != filename[offset])
return false;
88 if (filename[offset])
return false;