0

I am creating a app which need to retrieve a player info from a XML file. I've basically done the parsing part but encounter this problem right now.

The example of format is:

<P id="4336" f="Luka" s="MODRI&#x106;" d="1985-09-09" h="174" w="65" i="4336.png"/>

(My logic is compare first name and last name from data with user input and pull the data out from the XML file.) I need retrieve the data when user input "Luka Modric" but I know it is hard to compare "MODRIC" with "MODRIĆ" or "MODRI&#x106;" . Are there any better solutions that I can achieve my goal? Thanks.

buzzmind
  • 109
  • 2
  • 10
  • You probably need to understand *both* sides of things - data storage and UI. If what you want is to translate *"Ć"* into a "hard" or accented capital C, then you want it to be *"\u{0106}"* in Swift to display properly. Where things get rough *on your end* is translating all relevant Unicode characters between your app and where the data is stored. Believe me, it makes it so much easier if you have control over both! If you don't you need to write as low-level an interface as needed. Good luck! –  Aug 08 '18 at 23:04
  • Related: https://stackoverflow.com/questions/25607247/how-do-i-decode-html-entities-in-swift – Martin R Aug 09 '18 at 02:03
  • Thank u guys. I decide to design my own xml since it will suit my need much better. Thanks again! – buzzmind Aug 09 '18 at 03:18

1 Answers1

3

Assuming you addressed the html escape sequence (&#x106;) to string conversion, you can transform the diacritics from the player name to latin characters, and compare based on those:

let playerName = "Luka Modrić"
let normalizedPlayerName = playerName.folding(options: .diacriticInsensitive, locale: nil)
let isLukaModric = normalizedPlayerName.caseInsensitiveCompare("luka modric")
print(normalizedPlayerName, isLukaModric.rawValue) 

The above code prints "Luka Modric 0", 0 standing for equal strings.

Cristik
  • 30,989
  • 25
  • 91
  • 127