• 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
Relative URLs, and string encodings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Relative URLs, and string encodings


  • Subject: Relative URLs, and string encodings
  • From: Jonathan Taylor <email@hidden>
  • Date: Thu, 1 Jun 2017 15:44:36 +0100

Can anyone help me with the seemingly simple task of creating a relative NSURL for a filesystem object? The catch here (sorry!) is that I really do need backward compatibility to 10.7, which rules out fileURLWithFileSystemRepresentation:isDirectory:relativeToURL: (which I suspect is the “right” way of doing this).

My attempt like:
[NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding] relativeToURL:relativeTo];

This had been working ok for some time, but I have just found it to be broken for filenames containing unusual characters. In particular, it fails when given a filename containing a “smart quote” (not easily created directly with the keyboard, but auto-generated as part of a time machine backup, based on the machine name).

Although I do not recall why I used stringByAddingPercentEscapesUsingEncoding, I think it must have been because it failed on some other filename pattern if I did not do that.

String encodings is something I know basically nothing about, I am afraid. I am speculating that what is happening is that the fancy apostrophe is not ASCII and so my code does not work for that filename. I can change the encoding to NSUnicodeStringEncoding, and things seem ok, but I don’t know whether that will now definitely work for all filenames, or whether I have just stored up an even more obscure problem for the future.

So, finally getting to two actual questions:
1. Will unicode encoding give me a robust solution here?
2. Is there a differnet, better way (pre-10.9) I should be using to create a relative URL?

Thanks for any advice
Jonny.
_______________________________________________

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

  • Follow-Ups:
    • Re: Relative URLs, and string encodings
      • From: Jens Alfke <email@hidden>
  • Next by Date: Re: Relative URLs, and string encodings
  • Next by thread: Re: Relative URLs, and string encodings
  • Index(es):
    • Date
    • Thread