• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Normalising file names on macOS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Normalising file names on macOS


  • Subject: Re: Normalising file names on macOS
  • From: John Brownie <email@hidden>
  • Date: Thu, 22 Sep 2016 15:15:13 +0300

Thanks, that sounds like a couple of good options. I'll try some options with the second one, and fall back on the first if necessary.

Alastair Houghton wrote:
My recommendation would be as follows:

1. If possible, don’t base the filename on the user’s input.  Instead, generate your own filename (one option might be to use a UUID) and then store a dictionary mapping the user’s input to the filename somewhere in your bundle.  This avoids any problems with filename encoding completely.  You will still have to worry about normalising the user’s input, but that’s then just a matter of choosing a normalisation.

2. If you must base the filename on user input, do so by stripping out non-ASCII characters and replacing them with e.g. ‘_’s.  You’ll also need to make sure that the result is unique, otherwise a user might specify two names that both map to the same ASCIIfied name.  You’ll still want to store the dictionary mapping the user’s input.

The benefit of the second approach is that your bundle is more easily understood by a human being.  The downside is that it’s more complicated to implement.

Both will work, whatever the filesystem is, as they don’t rely on filesystem encoding behaviour.

(You might also then ponder whether you want things to be case-sensitive or not; the above will be.  Making it not case-sensitive is a little tricky in that just converting to upper or lower case doesn’t*quite*  work; the correct approach would be to use CFStringFold() to case-fold the string,*after*  normalising, before using it as a dictionary key.)
John
--
John Brownie
In Finland on furlough from SIL Papua New Guinea
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Normalising file names on macOS (From: John Brownie <email@hidden>)
 >Re: Normalising file names on macOS (From: Alastair Houghton <email@hidden>)
 >Re: Normalising file names on macOS (From: John Brownie <email@hidden>)
 >Re: Normalising file names on macOS (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: Normalising file names on macOS
  • Next by Date: Re: How to update UI from a background thread
  • Previous by thread: Re: Normalising file names on macOS
  • Next by thread: Re: Normalising file names on macOS
  • Index(es):
    • Date
    • Thread