I have a method in Java, that takes a Hebrew string, and adjusts its end to a form appropriate to Hebrew. In one of the lines I used in a property Character.getDirectionality(char).
Now, I want to "translate" it to JavaScript. The problem is that I can't find appropriate way to get this property. Yes, there is an option to search in the UnicodeData.txt, but this is 1) can have some problems with the copyright; and 2) it is seems hard. Maybe, there is an Unicode library for JS, or a built-in solution.
Here is my code in Java (I did some corrections in it, but it donesn't matter so much):
public static String endingPointed(String s) {
int i=s.length()-1; //max. length of the while loop
StringBuffer sb=new StringBuffer(s); //mutable String I will change during the method
while(i>=0) { //the loop
//i.e. vocalization checking
if(Character.getDirectionality(s.charAt(i))==Character.DIRECTIONALITY_NONSPACING_MARK){
i--;
if(sofiyot.contains(s.charAt(i)+"")) { //next letters: כמנפצ; they have ending form
sb.replace(i, i+1, (char) (s.charAt(i)-1)+""); //replacement to the ending form
if(s.endsWith("כ")||s.endsWith("כּ"))
sb.append("ְ"); //if a pointed word ends with 'ך', the letter accepts schva ('ְ'). Ex. "אֵיךְ" (ekh), means 'how'
return sb.toString();
}
if(patach.contains(s.charAt(i)+"")) { //in the pointed writing, the letters החע accept patach ('ַ'). Ex. "תַּפּוּחַ" (tapuakh), means 'apple'
if(!s.endsWith("ָ"+s.charAt(i))&!s.endsWith("ַ"+s.charAt(i))) //except when the letters are dotted with patach ('ַ') or kamatz ('ָ')
sb.append("ַ");
return sb.toString();
}
else
return sb.toString();
}
return sb.toString();
}
Thank you very much for help!