IoSeq *IoSeq_newFromFilePath_(void *state, const char *path) { IoSeq *self = IoSeq_new(state); UArray p = UArray_stackAllocedWithCString_((char *)path); UArray_readFromFilePath_(DATA(self), &p); return self; }
void UArray_removeLastPathComponent(UArray *self) { UArray seps = UArray_stackAllocedWithCString_(IO_PATH_SEPARATORS); long pos = UArray_findLastPathComponent(self); if (pos) pos --; UArray_setSize_(self, pos); }
long UArray_findLastPathComponent(const UArray *self) { if (self->size) { UArray seps = UArray_stackAllocedWithCString_(IO_PATH_SEPARATORS); UArray s = UArray_stackRange(self, 0, self->size); long pos = 0; while (s.size && (pos = UArray_rFindAnyValue_(&s, &seps)) == s.size - 1) { s.size = pos; } if (pos == -1) { pos = 0; } else { pos ++; } return pos; } return 0; }
void UArray_appendPath_(UArray *self, const UArray *path) { const UArray sep = UArray_stackAllocedWithCString_(IO_PATH_SEPARATOR); int selfEndsWithSep = IS_PATH_SEPERATOR(UArray_lastLong(self)); int pathStartsWithSep = IS_PATH_SEPERATOR(UArray_firstLong(path)); if (!selfEndsWithSep && !pathStartsWithSep) { if(self->size != 0) UArray_append_(self, &sep); UArray_append_(self, path); } else if (selfEndsWithSep && pathStartsWithSep) { const UArray pathPart = UArray_stackRange(path, 1, path->size - 1); UArray_append_(self, &pathPart); } else { UArray_append_(self, path); } }
BASEKIT_API void UArray_replaceCString_withCString_(UArray *self, const char *s1, const char *s2) { UArray a1 = UArray_stackAllocedWithCString_((char *)s1); UArray a2 = UArray_stackAllocedWithCString_((char *)s2); UArray_replace_with_(self, &a1, &a2); }
long UArray_findPathExtension(UArray *self) { UArray dot = UArray_stackAllocedWithCString_(IO_PATH_SEPARATOR_DOT); return UArray_rFind_(self, &dot); }