• 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
Problem with rangeOfString and Umlauts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with rangeOfString and Umlauts


  • Subject: Problem with rangeOfString and Umlauts
  • From: Gabriel Zachmann via Cocoa-dev <email@hidden>
  • Date: Fri, 11 Mar 2022 18:17:33 +0100

Well, SSIA.
In more detail, I've got two strings:

file_basename = @"Morgendämmerung (1)"
info_item = @"Morgendämmerung"

This code

    NSString * prefix = [ info_item commonPrefixWithString: file_basename
options: NSCaseInsensitiveSearch ];
    unsigned int prefix_len = (unsigned int) [prefix length];

yields prefix_len = 15
as it should.

The problem arises with this line of code:

    NSRange space_in_filename = [file_basename rangeOfString: @" " options:
NSDiacriticInsensitiveSearch|NSCaseInsensitiveSearch|NSWidthInsensitiveSearch];

which yields space_in_filename.location = 16 !

This thwarts the rest of the code, which, in this case, would expect
space_in_filename.location = 15.

Needless to say that with strings that do not contain Umlauts, the call of
rangeOfString:options: works as expected, i.e., in the above example
space_in_filename.location is as expected (i.e., first character has
location=0).

I have also tried localizedStandardRangeOfString, with the same effect.

Any ideas what I can do?


Best regards, Gabriel


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: Problem with rangeOfString and Umlauts
      • From: Mike Abdullah via Cocoa-dev <email@hidden>
    • Re: Problem with rangeOfString and Umlauts
      • From: Jack Brindle via Cocoa-dev <email@hidden>
    • Re: Problem with rangeOfString and Umlauts
      • From: Matt Jacobson via Cocoa-dev <email@hidden>
  • Next by Date: Re: Problem with rangeOfString and Umlauts
  • Next by thread: Re: Problem with rangeOfString and Umlauts
  • Index(es):
    • Date
    • Thread