nim-lang / RFCs

A repository for your Nim proposals.
136 stars 26 forks source link

rebasePath #256

Closed timotheecour closed 8 months ago

timotheecour commented 3 years ago

proposal

add this to std/os

proc rebasePath*(path, oldBase, newBase: string, check = true): string =
  if path.isRelativeTo(oldBase):
    result = newBase / path.relativePath(oldBase)
  else:
    doAssert not check, $(path, oldBase, newBase)
    result = path
Araq commented 3 years ago
  1. You could add some use cases.
  2. The check = true seems a bit problematic to me because you turn the check failure into an untracked AssertionError exception. However, it is better than a hypothetical proc rebasePath*(path, oldBase, newBase: string, check = true): string {.raises: ValueError.} solution which then cannot really fail when you pass check = false. But maybe that's an indication that we want two procs rather than one.
timotheecour commented 3 years ago

=> see https://github.com/nim-lang/Nim/pull/15514

github-actions[bot] commented 9 months ago

This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 30 days.