Thanks Quinn.
if you absolutely want to display a path as a string, my advice nowadays is to display the Posix path.
Right, that's what I was doing. But now I have a case where I want files corresponding to dates (but not times), which is why I'm considering doing the /: swap. This has the additional benefit (?) that the names match what is seen in Finder or the iOS Files app.
when creating a file things get much much worse
:-(
Here's what I'm actually doing:
I have a file format where the user can enter a document name which is stored internally in the file. And maybe the app provides a suggestion based on the date, e.g. "New widgets for 14/10/2026". I store that string verbatim internally in the document, and then I use it as the basis for the document's filename. At this point, I do /-to-: conversion. Maybe I convert : to space, or something. Maybe I remove newlines. And so on. But I don't want to reject names containing : (etc) because those are fine in the internal metadata. Oh, and I have to do something to force uniqueness i.e. '1:2' and '1 2' and '1\n2' would map to the same filename, ugh.
Later I may show a list or tree of available documents. At this point I may or may not have opened the document to read the internal metadata. So I may want to convert the filename back to (approximately) the name that that user entered.
Now that I write this, I do wonder if I should be escaping any :s, rather than converting them to e.g. spaces, since that avoids the uniqueness problem. Hmmm.