I made a program where people can type in 4 letters and it will give you the corresponding unicode character that it inserts in a textflow element. Now i had a lot of problems with this, but in the end i succeeded with some help. Now the problem came when i typed "dddd" or "ddd1" as a test.
I got the error - "An unpaired Unicode surrogate was encountered in the input."
Now i spend like 2 days testing for that, and there was absolutly no event triggering that made it possible for me to test for the error before it occurred.
The code:
str = "dddd"
num = parseInt(str,16)
res = String.fromCharCode(num)
Acutally when the error occurres res is equal to "?" in the console ... but if you test for it with if(res == "?") it returns false.
MY QUESTION: Now i searched and searched and found abolutly no description on this error in adobes as3 reference, but after 2 days i found this page for javascript: http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter04a
It says that - The code units in the range 0xD800–0xDFFF, serve a special purpose, however. These code units, known as surrogate code units
So now i test with:
if( num > 0 && num < uint(0xD800)) || ( num > uint(0xDFFF) && num < uint(0xFFFF) ){
get unicode character.
}
my question is simply if i understood this correctly, that this will actually prevent the error from occurring? - I'm no unicode specialist and don't know really how to test for it, since there are ten's of thousands characters so i might have missed one and that would mean that the users by accident could get the error and risk crashing the application.