Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find and Highlight Arabic with diacritics Text in UIWebView

I'm viewing an Arabic with diacritics (tashkel) text in a UIWebView. I also have a Search View.

I want to give the UIWebView a keyword and UIWebView finds and highlights it, but the search should ignore the diacritics.

The main text should remain with the diacritics.

example : if the text is " الَلَهُم صَلِ عَلى مُحَمّد و آل مُحمد " and I tell the UIWebView to search for " محمد " it should highlight "مُحَمّد " and " مُحمد " regardless of all the diacritics.

I think of two approaches : 1- I do the find and highlight by Javascript after the UIWebView load. 2- I edit the text by Objective-C before loading the UIWebView.

like image 697
AbdullahEgh Avatar asked Aug 25 '12 03:08

AbdullahEgh


2 Answers

You have to first strip all the diacritics from the string, then you can compare without any diacritics. Use regular expression to remove the characters you don't want. Check out this fiddle i did, inside the strip() function you need to add all the diacritics you need to take out.

hope this helps.

like image 168
KDaker Avatar answered Oct 13 '22 10:10

KDaker


The version below does not remove sukoon.

I have converted the eight diacritics (fatha, kasrah, damma, shaddah, sukoon and tanween) into their Unicode equivalent. It is much easier to manipulate Arabic converted into Latin characters in any text editor :

<html>
 <head><meta charset="UTF-8"></head>
<body>
<script>document.write("حَرْفٌ".replace(/(\u0652)|(\u0650)|(\u064C)|(\u064E)|(\u064B)|(\u064F)|(\u064D)|(\u0651)/g,""));</script>
</body>
</html>

Resources used:
Arabic Keyboard with diacritics
Unicode Code Converter

like image 45
Omar Elfada Avatar answered Oct 13 '22 10:10

Omar Elfada