path_js.odin 857 B

123456789101112131415161718192021222324252627282930313233343536
  1. package filepath
  2. import "base:runtime"
  3. import "core:strings"
  4. SEPARATOR :: '/'
  5. SEPARATOR_STRING :: `/`
  6. LIST_SEPARATOR :: ':'
  7. is_reserved_name :: proc(path: string) -> bool {
  8. return false
  9. }
  10. is_abs :: proc(path: string) -> bool {
  11. return strings.has_prefix(path, "/")
  12. }
  13. abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
  14. if is_abs(path) {
  15. return strings.clone(string(path), allocator), true
  16. }
  17. return path, false
  18. }
  19. join :: proc(elems: []string, allocator := context.allocator) -> (joined: string, err: runtime.Allocator_Error) #optional_allocator_error {
  20. for e, i in elems {
  21. if e != "" {
  22. runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator)
  23. p := strings.join(elems[i:], SEPARATOR_STRING, context.temp_allocator) or_return
  24. return clean(p, allocator)
  25. }
  26. }
  27. return "", nil
  28. }