source: Dev/trunk/src/client/dojox/string/BidiEngine.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 52.8 KB
Line 
1define(["dojo/_base/lang", "dojo/_base/declare"],
2  function(lang,declare){
3lang.getObject("string", true, dojox);
4
5var BidiEngine = declare("dojox.string.BidiEngine", null, {
6        // summary:
7        //              This class provides a bidi transformation engine, i.e.
8        //              functions for reordering and shaping bidi text.
9        // description:
10        //              Bidi stands for support for languages with a bidirectional script.
11        //
12        //              Usually Unicode Bidi Algorithm used by OS platform (and web browsers) is capable of properly transforming
13        //              Bidi text and as a result it is adequately displayed on the screen. However, in some situations,
14        //              Unicode Bidi Algorithm is not invoked or is not properly applied. This may occur in situation in which software
15        //              responsible for rendering the text is not leveraging Unicode Bidi Algorithm implemented by OS (e.g. dojox.GFX renderers).
16        //
17        //              Bidi engine provided in this class implements Unicode Bidi Algorithm as specified at
18        //              http://www.unicode.org/reports/tr9/.
19        //
20        //              For more information on basic Bidi concepts please read
21        //              "Bidirectional script support - A primer" available from
22        //              http://www.ibm.com/developerworks/websphere/library/techarticles/bidi/bidigen.html.
23        //
24        //              As of February 2011, Bidi engine has following limitations:
25        //
26        //              1. No support for following numeric shaping options:
27        //                  - H - Hindi,
28        //                  - C - Contextual,
29        //                  - N - Nominal.
30        //              2. No support for following shaping options:
31        //                  - I - Initial shaping,
32        //                  - M - Middle shaping,
33        //                  - F - Final shaping,
34        //                  - B - Isolated shaping.
35        //              3. No support for source-to-target or/and target-to-source maps.
36        //              4. No support for LRE/RLE/LRO/RLO/PDF (they are handled like neutrals).
37        //              5. No support for Windows compatibility.
38        //              6. No support for  insert/remove marks.
39        //              7. No support for code pages (currently only UTF-8 is supported. Ideally we should convert from any code page to UTF-8).
40       
41        bidiTransform: function (/*String*/text, /*String*/formatIn, /*String*/formatOut){
42                // summary:
43                //              Central public API for Bidi engine. Transforms the text according to formatIn, formatOut parameters.
44                //              If formatIn or formatOut parametrs are not valid throws an exception.
45                // inputText:
46                //              Input text subject to application of Bidi transformation.
47                // formatIn:
48                //              Input Bidi layout in which inputText is passed to the function.
49                // formatOut:
50                //              Output Bidi layout to which inputText should be transformed.
51                // description:
52                //              Both formatIn and formatOut parameters are 5 letters long strings.
53                //              For example - "ILYNN". Each letter is associated with specific attribute of Bidi layout.
54                //              Possible and default values for each one of the letters are provided below:
55                //
56                //              First letter:
57                //
58                //              - Letter position/index:
59                //                      1
60                //              - Letter meaning:
61                //                      Ordering Schema.
62                //              - Possible values:
63                //                      - I - Implicit (Logical).
64                //                      - V - Visual.
65                //              - Default value:
66                //                      I
67                //
68                //              Second letter:
69                //
70                //              - Letter position/index:
71                //                      2
72                //              - Letter meaning:
73                //                      Orientation.
74                //              - Possible values:
75                //                      - L - Left To Right.
76                //                      - R - Right To Left.
77                //                      - C - Contextual Left to Right.
78                //                      - D - Contextual Right to Left.
79                //              - Default value:
80                //                      L               
81                //
82                //              Third letter:
83                //
84                //              - Letter position/index:
85                //                      3
86                //              - Letter meaning:
87                //                      Symmetric Swapping.
88                //              - Possible values:
89                //                      - Y - Symmetric swapping is on.
90                //                      - N - Symmetric swapping is off.
91                //              - Default value:
92                //                      Y               
93                //
94                //              Fourth letter:
95                //
96                //              - Letter position/index:
97                //                      4
98                //              - Letter meaning:
99                //                      Shaping.
100                //              - Possible values:
101                //                      - S - Text is shaped.
102                //                      - N - Text is not shaped.
103                //              - Default value:
104                //                      N                               
105                //
106                //              Fifth letter:
107                //
108                //              - Letter position/index:
109                //                      5
110                //              - Letter meaning:
111                //                      Numeric Shaping.
112                //              - Possible values:
113                //                      - N - Nominal.
114                //              - Default value:
115                //                      N                               
116                //
117                //              The output of this function is original text (passed via first argument) transformed from input Bidi layout (second argument)
118                //              to output Bidi layout (last argument).
119                //
120                //              Sample call:
121                //      |       mytext = bidiTransform("HELLO WORLD", "ILYNN", "VLYNN");
122                //              In this case, "HELLO WORLD" text is transformed from Logical - LTR to Visual - LTR Bidi layout with
123                //              default values for symmetric swapping (Yes), shaping (Not shaped) and numeric shaping (Nominal).
124                // returns: String
125                //              Original text transformed from input Bidi layout (second argument)
126                //              to output Bidi layout (last argument).
127                //              Throws an exception if the bidi layout strings are not valid.
128                // tags:
129                //              public
130               
131                if(!text){
132                        return '';
133                }
134                if(!formatIn && !formatOut){
135                        return text;
136                }
137
138                // regex for format validation
139                // Allowed values for format string are:
140                // 1st letter- I, V
141                // 2nd letter- L, R, C, D
142                // 3rd letter- Y, N
143                // 4th letter- S, N
144                // 5th letter- N
145                var validFormat = /^[(I|V)][(L|R|C|D)][(Y|N)][(S|N)][N]$/;
146                if(!validFormat.test(formatIn) || !validFormat.test(formatOut)){
147                        throw new Error("dojox.string.BidiEngine: the bidi layout string is wrong!");
148                }
149
150                if(formatIn == formatOut){
151                        return text;
152                }
153
154                var orientIn = getOrientation(formatIn.charAt(1))
155                        , orientOut = getOrientation(formatOut.charAt(1))
156                        , os_in = (formatIn.charAt(0) == 'I') ? 'L' : formatIn.charAt(0)
157                        , os_out = (formatOut.charAt(0) == 'I') ? 'L' : formatOut.charAt(0)
158                        , inFormat = os_in + orientIn
159                        , outFormat = os_out + orientOut
160                        , swap = formatIn.charAt(2) + formatOut.charAt(2)
161                        ;
162
163                if(inFormat){
164                        bdx.defInFormat = inFormat;
165                }
166                if(outFormat){
167                        bdx.defOutFormat = outFormat;
168                }
169                if(swap){
170                        bdx.defSwap = swap;
171                }
172               
173                var stage1_text = doBidiReorder(text, os_in + orientIn, os_out + orientOut, formatIn.charAt(2) + formatOut.charAt(2))
174                        , isRtl = false;
175
176                if(formatOut.charAt(1) == 'R'){
177                        isRtl = true;
178                }else if(formatOut.charAt(1) == 'C' || formatOut.charAt(1) == 'D'){
179                        isRtl = this.checkContextual(stage1_text);
180                }
181                if(formatIn.charAt(3) == formatOut.charAt(3)){
182                        return stage1_text;
183                }else if(formatOut.charAt(3) == 'S'){
184                        return shape(isRtl, stage1_text, true);
185                }
186                if(formatOut.charAt(3) == 'N'){
187                        return deshape(stage1_text, isRtl, true);
188                }
189        },
190        checkContextual: function(/*String*/text){
191                // summary:
192                //              Determine the base direction of a bidi text according
193                //              to its first strong directional character.
194                // text:
195                //              The text to check.
196                // returns: /*String*/
197                //              "ltr" or "rtl" according to the first strong character.
198                //              If there is no strong character, returns the value of the
199                //              document dir property.
200                // tags:
201                //              public         
202                var dir = firstStrongDir(text);
203                if(dir != "ltr" && dir != "rtl"){
204                        dir = document.dir.toLowerCase();
205                        if(dir != "ltr" && dir != "rtl"){dir = "ltr";}
206                }
207                return dir;
208        },
209        hasBidiChar: function(/*String*/text){
210                // summary:
211                //              Return true if text contains RTL directed character.
212                // text:
213                //              The source string.
214                // description:
215                //              Iterates over the text string, letter by letter starting from its beginning,
216                //              searching for RTL directed character.
217                //              Return true if found else false. Needed for vml transformation.
218                // returns: /*Boolean*/
219                //              true - if text has a RTL directed character.
220                //              false - otherwise.
221                // tags:
222                //              public
223
224                var type = null, uc = null,     hi = null;
225                for(var i = 0; i < text.length; i++){
226                        uc = text.charAt(i).charCodeAt(0);
227                        hi = MasterTable[uc >> 8];
228                        type = hi < TBBASE ? hi : UnicodeTable[hi - TBBASE][uc & 0xFF];
229                        if(type == UBAT_R || type == UBAT_AL){
230                                return true;
231                        }
232                        if(type == UBAT_B){
233                                break;
234                        }
235                }
236                return false;
237        }       
238
239});
240
241
242function doBidiReorder(/*String*/text, /*String*/inFormat,
243                                                /*String*/outFormat, /*String*/swap){
244        // summary:
245        //              Reorder the source text according to the bidi attributes
246        //              of source and result.
247        // text:
248        //              The text to reorder.
249        // inFormat:
250        //              Ordering scheme and base direction of the source text.
251        //              Can be "LLTR", "LRTL", "LCLR", "LCRL", "VLTR", "VRTL",
252        //              "VCLR", "VCRL".
253        //              The first letter is "L" for logical ordering scheme,
254        //              "V" for visual ordering scheme.
255        //              The other letters specify the base direction.
256        //              "CLR" means contextual direction defaulting to LTR if
257        //              there is no strong letter.
258        //              "CRL" means contextual direction defaulting to RTL if
259        //              there is no strong letter.
260        //              The initial value is "LLTR", if none, the initial value is used.
261        // outFormat:
262        //              Required ordering scheme and base direction of the
263        //              result. Has the same format as inFormat.
264        //              If none, the initial value "VLTR" is used.
265        // swap:
266        //              Symmetric swapping attributes of source and result.
267        //              The allowed values can be "YN", "NY", "YY" and "NN".
268        //              The first letter reflects the symmetric swapping attribute
269        //              of the source, the second letter that of the result.   
270        // returns:
271        //              Text reordered according to source and result attributes.
272
273        if(inFormat == undefined){
274                inFormat = bdx.defInFormat;
275        }
276        if(outFormat == undefined){
277                outFormat = bdx.defOutFormat;
278        }
279        if(swap == undefined){
280                swap = bdx.defSwap;
281        }
282        if(inFormat == outFormat){
283                return text;
284        }
285        var dir, inOrdering = inFormat.substring(0,1)
286                , inOrientation = inFormat.substring(1,4)
287                , outOrdering = outFormat.substring(0,1)
288                , outOrientation = outFormat.substring(1,4)
289                ;
290        if(inOrientation.charAt(0) == "C"){
291                dir = firstStrongDir(text);
292                if(dir == "ltr" || dir == "rtl"){
293                        inOrientation = dir.toUpperCase();
294                }else{
295                        inOrientation = inFormat.charAt(2) == "L" ? "LTR" : "RTL";
296                }
297                inFormat = inOrdering + inOrientation;
298        }
299        if(outOrientation.charAt(0) == "C"){
300                dir = firstStrongDir(text);
301                if(dir == "rtl"){
302                        outOrientation = "RTL";
303                }else if(dir == "ltr"){
304                        dir = lastStrongDir(text);
305                        outOrientation = dir.toUpperCase();
306                }else{
307                        outOrientation = outFormat.charAt(2) == "L" ? "LTR" : "RTL";
308                }
309                outFormat = outOrdering + outOrientation;
310        }
311        if(inFormat == outFormat){
312                return text;
313        }
314        bdx.inFormat = inFormat;
315        bdx.outFormat = outFormat;
316        bdx.swap = swap;
317        if((inOrdering == "L") && (outFormat == "VLTR")){ //core cases
318                //cases: LLTR->VLTR, LRTL->VLTR
319                if(inOrientation == "LTR"){
320                        bdx.dir = LTR;
321                        return doReorder(text);
322                }
323                if(inOrientation == "RTL"){
324                        bdx.dir = RTL;
325                        return doReorder(text);
326                }
327        }
328        if((inOrdering == "V") && (outOrdering == "V")){
329                //inOrientation != outOrientation
330                //cases: VRTL->VLTR, VLTR->VRTL
331                return invertStr(text);
332        }
333        if((inOrdering == "L") && (outFormat == "VRTL")){
334                //cases: LLTR->VRTL, LRTL->VRTL
335                if(inOrientation == "LTR"){
336                        bdx.dir = LTR;
337                        text = doReorder(text);
338                }else{
339                        //inOrientation == RTL
340                        bdx.dir = RTL;
341                        text = doReorder(text);
342                }
343                return invertStr(text);
344        }
345        if((inFormat == "VLTR") && (outFormat == "LLTR")){
346                //case: VLTR->LLTR
347                bdx.dir = LTR;
348                return doReorder(text);
349        }
350        if((inOrdering == "V") && (outOrdering == "L") && (inOrientation != outOrientation)){
351                //cases: VLTR->LRTL, VRTL->LLTR
352                text = invertStr(text);
353
354                return (inOrientation == "RTL") ? doBidiReorder(text, "LLTR","VLTR", swap) : doBidiReorder(text, "LRTL","VRTL", swap);
355        }
356        if((inFormat == "VRTL") && (outFormat == "LRTL")){
357                //case VRTL->LRTL
358                return doBidiReorder(text, "LRTL","VRTL", swap);
359        }
360        if((inOrdering == "L") && (outOrdering == "L")){
361                //inOrientation != outOrientation
362                //cases: LRTL->LLTR, LLTR->LRTL
363                var saveSwap = bdx.swap;
364                bdx.swap = saveSwap.substr(0, 1) + "N";
365                if(inOrientation == "RTL"){
366                        //LRTL->LLTR
367                        bdx.dir = RTL;
368                        text = doReorder(text);
369                        bdx.swap = "N" + saveSwap.substr(1, 2);
370                        bdx.dir = LTR;
371                        text = doReorder(text);
372                }else{ //LLTR->LRTL
373                        bdx.dir = LTR;
374                        text = doReorder(text);
375                        bdx.swap = "N" + saveSwap.substr(1, 2);
376                        text = doBidiReorder(text, "VLTR","LRTL", bdx.swap);
377                }
378                return text;
379        }
380
381}
382
383function shape(/*boolean*/rtl, /*String*/text, /*boolean*/compress){
384        // summary:
385        //              Shape the source text.
386        // rtl:
387        //              Flag indicating if the text is in RTL direction (logical
388        //              direction for Arabic words).
389        // text:
390        //              The text to shape.
391        // compress:
392        //              A flag indicates to insert extra space after the lam alef compression
393        //              to preserve the buffer size or not insert an extra space which will lead
394        //              to decrease the buffer size. This option can be:
395        //
396        //              - true (default) to not insert extra space after compressing Lam+Alef into one character Lamalef
397        //              - false to insert an extra space after compressed Lamalef to preserve the buffer size
398        // returns:
399        //              text shaped.
400        // tags:
401        //              private.
402       
403        if(text.length == 0){
404                return;
405        }
406        if(rtl == undefined){
407                rtl = true;
408        }
409        if(compress == undefined){
410                compress = true;
411        }
412        text = new String(text);
413       
414        var str06 = text.split("")
415                , Ix = 0
416                , step = +1
417                , nIEnd = str06.length
418                ;
419        if(!rtl){
420                Ix = str06.length - 1;
421                step = -1;
422                nIEnd = 1;
423        }
424        var previousCursive = 0, compressArray = [], compressArrayIndx = 0;
425        for(var index = Ix; index * step < nIEnd; index = index + step){
426                if(isArabicAlefbet(str06[index]) || isArabicDiacritics(str06[index])){
427                        // Arabic letter Lam
428                        if(str06[index] == '\u0644'){
429                                if(isNextAlef(str06, (index + step), step, nIEnd)){
430                                        str06[index] = (previousCursive == 0) ? getLamAlefFE(str06[index + step], LamAlefInialTableFE) : getLamAlefFE(str06[index + step], LamAlefMedialTableFE);
431                                        index += step;
432                                        setAlefToSpace(str06, index, step, nIEnd);
433                                        if(compress){
434                                                compressArray[compressArrayIndx] = index;
435                                                compressArrayIndx++;
436                                        }
437                                        previousCursive = 0;
438                                        continue;
439                                }
440                        }
441                        var currentChr = str06[index];
442                        if(previousCursive == 1){
443                                // if next is Arabic
444                                //Character is in medial form
445                                // else character is in final form
446                                str06[index] = (isNextArabic(str06, (index + step), step, nIEnd)) ?
447                                        getMedialFormCharacterFE(str06[index]) : getFormCharacterFE(str06[index], FinalForm);
448                        }else{
449                                if(isNextArabic(str06, (index + step), step, nIEnd) == true){
450                                        //character is in Initial form
451                                        str06[index] = getFormCharacterFE(str06[index],InitialForm);
452                                }else{
453                                        str06[index] = getFormCharacterFE(str06[index], IsolatedForm);
454                                }
455                        }
456                        //exam if the current character is cursive
457                        if(!isArabicDiacritics(currentChr)){
458                                previousCursive = 1;
459                        }
460                        if(isStandAlonCharacter(currentChr) == true){
461                                previousCursive = 0;
462                        }
463                }else{
464                        previousCursive = 0;
465                }
466        }
467        var outBuf = "";
468        for(idx = 0; idx < str06.length; idx++){
469                if(!(compress && indexOf(compressArray, compressArray.length, idx) > -1)){
470                        outBuf += str06[idx];
471                }
472        }
473        return outBuf;
474}
475
476function firstStrongDir(/*String*/text){
477        // summary:
478        //              Return the first strong character direction
479        // text:
480        //              The source string.
481        // description:
482        //              Iterates over the text string, letter by letter starting from its beginning,
483        //              searching for first "strong" character.
484        //              Returns if strong character was found with the direction defined by this
485        //              character, if no strong character was found returns an empty string.
486        // returns: String
487        //              "ltr" - if the first strong character is Latin.
488        //              "rtl" - if the first strong character is RTL directed character.
489        //              "" - if the strong character wasn't found.
490        // tags:
491        //              private
492
493        var type = null, uc = null, hi = null;
494        for(var i = 0; i < text.length; i++){
495                uc = text.charAt(i).charCodeAt(0);
496                hi = MasterTable[uc >> 8];
497                type = hi < TBBASE ? hi : UnicodeTable[hi - TBBASE][uc & 0xFF];
498                if(type == UBAT_R || type == UBAT_AL){
499                        return "rtl";
500                }
501                if(type == UBAT_L){
502                        return  "ltr";
503                }
504                if(type == UBAT_B){
505                        break;
506                }
507        }
508        return "";
509}
510
511function lastStrongDir(text){
512        // summary:
513        //              Return the last strong character direction
514        // text:
515        //              The source string.
516        // description:
517        //              Iterates over the text string, letter by letter starting from its end,
518        //              searching for first (from the end) "strong" character.
519        //              Returns if strong character was found with the direction defined by this
520        //              character, if no strong character was found returns an empty string.
521        // tags:
522        //              private         
523        var type = null;
524        for(var i = text.length - 1; i >= 0; i--){
525                type = getCharacterType(text.charAt(i));
526                if(type == UBAT_R || type == UBAT_AL){
527                        return "rtl";
528                }
529                if(type == UBAT_L){
530                        return  "ltr";
531                }
532                if(type == UBAT_B){
533                        break;
534                }
535        }
536        return "";
537}
538
539function deshape(/*String*/text, /*boolean*/rtl, /*boolean*/consume_next_space){
540        // summary:
541        //              deshape the source text.
542        // text:
543        //              the text to be deshape.
544        // rtl:
545        //              flag indicating if the text is in RTL direction (logical
546        //              direction for Arabic words).
547        // consume_next_space:
548        //              flag indicating whether to consume the space next to the
549        //              the lam alef if there is a space followed the Lamalef character to preserve the buffer size.
550        //              In case there is no space next to the lam alef the buffer size will be increased due to the
551        //              expansion of the lam alef one character into lam+alef two characters
552        // returns:
553        //              text deshaped.
554        if(text.length == 0){
555                return;
556        }
557        if(consume_next_space == undefined){
558                consume_next_space = true;
559        }
560        if(rtl == undefined){
561                rtl = true;
562        }
563        text = new String(text);
564
565        var outBuf = "", strFE = [], textBuff = "";
566        if(consume_next_space){
567                for(var j = 0; j < text.length; j++){
568                        if(text.charAt(j) == ' '){
569                                if(rtl){
570                                        if(j > 0){
571                                                if(text.charAt(j - 1) >= '\uFEF5' && text.charAt(j - 1) <= '\uFEFC'){
572                                                        continue;
573                                                }
574                                        }
575                                }else{
576                                        if(j+1 < text.length){
577                                                if(text.charAt(j + 1) >= '\uFEF5' && text.charAt(j + 1) <= '\uFEFC'){
578                                                        continue;
579                                                }
580                                        }                               
581                                }
582                        }
583                        textBuff += text.charAt(j);
584                }
585        }else{
586                textBuff = new String(text);
587        }
588        strFE = textBuff.split("");
589        for(var i = 0; i < textBuff.length; i++){
590                if(strFE[i] >= '\uFE70' && strFE[i] < '\uFEFF'){
591                        var chNum = textBuff.charCodeAt(i);
592                        if(strFE[i] >= '\uFEF5' && strFE[i] <= '\uFEFC'){
593                                //expand the LamAlef
594                                if(rtl){
595                                        //Lam + Alef
596                                        outBuf += '\u0644';
597                                        outBuf += AlefTable[parseInt((chNum - 65269) / 2)];
598                                }else{
599                                        outBuf += AlefTable[parseInt((chNum - 65269) / 2)];
600                                        outBuf += '\u0644';
601                                }
602                        }else{
603                                outBuf += FETo06Table[chNum - 65136];
604                        }
605                }else{
606                        outBuf += strFE[i];
607                }
608        }
609        return outBuf;
610}
611
612function doReorder(str){
613        // summary:
614        //              Helper to the doBidiReorder. Manages the UBA.
615        // str:
616        //              the string to reorder.
617        // returns:
618        //              text reordered according to source and result attributes.
619        // tags:
620        //              private
621        var chars = str.split(""), levels = [];
622
623        computeLevels(chars, levels);
624        swapChars(chars, levels);
625        invertLevel(2, chars, levels);
626        invertLevel(1, chars, levels);
627        return chars.join("");
628}
629
630function computeLevels(chars, levels){
631        var len = chars.length
632                , impTab = bdx.dir ? impTab_RTL : impTab_LTR
633                , prevState = null, newClass = null, newLevel = null, newState = 0
634                , action = null, cond = null, condPos = -1, i = null, ix = null
635                , types = []
636                , classes = []
637                ;
638        bdx.hiLevel = bdx.dir;
639        bdx.lastArabic = false;
640        bdx.hasUBAT_AL = false,
641        bdx.hasUBAT_B = false;
642        bdx.hasUBAT_S = false;
643        for(i = 0; i < len; i++){
644                types[i] = getCharacterType(chars[i]);
645        }
646        for(ix = 0; ix < len; ix++){
647                prevState = newState;
648                classes[ix] = newClass = getCharClass(chars, types, classes, ix);
649                newState = impTab[prevState][newClass];
650                action = newState & 0xF0;
651                newState &= 0x0F;
652                levels[ix] = newLevel = impTab[newState][ITIL];
653                if(action > 0){
654                        if(action == 0x10){     // set conditional run to level 1
655                                for(i = condPos; i < ix; i++){
656                                        levels[i] = 1;
657                                }
658                                condPos = -1;
659                        }else{  // 0x20 confirm the conditional run
660                                condPos = -1;
661                        }
662                }
663                cond = impTab[newState][ITCOND];
664                if(cond){
665                        if(condPos == -1){
666                                condPos = ix;
667                        }
668                }else{  // unconditional level
669                        if(condPos > -1){
670                                for(i = condPos; i < ix; i++){
671                                        levels[i] = newLevel;
672                                }
673                                condPos = -1;
674                        }
675                }
676                if(types[ix] == UBAT_B){
677                        levels[ix] = 0;
678                }
679                bdx.hiLevel |= newLevel;
680        }
681        if(bdx.hasUBAT_S){
682                for(i = 0; i < len; i++){
683                        if(types[i] == UBAT_S){
684                                levels[i] = bdx.dir;
685                                for(var j = i - 1; j >= 0; j--){
686                                        if(types[j] == UBAT_WS){
687                                                levels[j] = bdx.dir;
688                                        }else{
689                                                break;
690                                        }
691                                }
692                        }
693                }
694        }
695}
696
697function swapChars(chars, levels){
698        // summary:
699        //              Swap characters with symmetrical mirroring as all kinds of parenthesis.
700        //              (When needed).
701        // chars:
702        //              The source string as Array of characters.
703        // levels:
704        //              An array (like hash) of flags for each character in the source string,
705        //              that defines if swapping should be applied on the following character.
706        // description:
707        //              First checks if the swapping should be applied, if not returns, else
708        //              uses the levels "hash" to find what characters should be swapped.
709        // tags:
710        //              private
711
712        if(bdx.hiLevel == 0 || bdx.swap.substr(0, 1) == bdx.swap.substr(1, 2)){
713                return;
714        }
715
716        //console.log("bdx.hiLevel == 0: " + bdx.hiLevel + "bdx.swap[0]: "+ bdx.swap[0] +" bdx.swap[1]: " +bdx.swap[1]);
717        for(var i = 0; i < chars.length; i++){
718                if(levels[i] == 1){chars[i] = getMirror(chars[i]);}
719        }
720}
721
722function getCharacterType(ch){
723        // summary:
724        //              Return the type of the character.
725        // ch:
726        //              The character to be checked.
727
728        // description:
729        //              Check the type of the character according to MasterTable,
730        //              type = LTR, RTL, neutral,Arabic-Indic digit etc.
731        // tags:
732        //              private                 
733        var uc = ch.charCodeAt(0)
734                , hi = MasterTable[uc >> 8];
735        return (hi < TBBASE) ? hi : UnicodeTable[hi - TBBASE][uc & 0xFF];
736}
737
738function invertStr(str){
739        // summary:
740        //              Return the reversed string.
741        // str:
742        //              The string to be reversed.
743        // description:
744        //              Reverse the string str.
745        // tags:
746        //              private                                 
747        var chars = str.split("");
748        chars.reverse();
749        return chars.join("");
750}
751
752function indexOf(cArray, cLength, idx){
753        var counter = -1;
754        for(var i = 0; i < cLength; i++){
755                if(cArray[i] == idx){
756                        return i;
757                }
758        }
759        return -1;
760}
761
762function isArabicAlefbet(c){
763        for(var i = 0; i < ArabicAlefBetIntervalsBegine.length; i++){
764                if(c >= ArabicAlefBetIntervalsBegine[i] && c <= ArabicAlefBetIntervalsEnd[i]){
765                        return true;
766                }
767        }
768        return false;
769}
770
771function isNextArabic(str06, index, step, nIEnd){
772        while(((index) * step) < nIEnd && isArabicDiacritics(str06[index])){
773                index += step;
774        }
775        if(((index) * step) < nIEnd && isArabicAlefbet(str06[index])){
776                return true;
777        }
778        return false;
779}
780
781function isNextAlef(str06, index, step, nIEnd){
782        while(((index) * step) < nIEnd && isArabicDiacritics(str06[index])){
783                index += step;
784        }
785        var c = ' ';
786        if(((index) * step) < nIEnd){
787                c = str06[index];
788        }else{
789                return false;
790        }
791        for(var i = 0; i < AlefTable.length; i++){
792                if(AlefTable[i] == c){
793                        return true;
794                }
795        }
796        return false;
797}
798
799function invertLevel(lev, chars, levels){
800        if(bdx.hiLevel < lev){
801                return;
802        }
803        if(lev == 1 && bdx.dir == RTL && !bdx.hasUBAT_B){
804                chars.reverse();
805                return;
806        }
807        var len = chars.length, start = 0, end, lo, hi, tmp;
808        while(start < len){
809                if(levels[start] >= lev){
810                        end = start + 1;
811                        while(end < len && levels[end] >= lev){
812                                end++;
813                        }
814                        for(lo = start, hi = end - 1 ; lo < hi; lo++, hi--){
815                                tmp = chars[lo];
816                                chars[lo] = chars[hi];
817                                chars[hi] = tmp;
818                        }
819                        start = end;
820                }
821                start++;
822        }
823}
824
825function getCharClass(chars, types, classes, ix){
826        // summary:
827        //              Return the class if ix character in chars.
828        // chars:
829        //              The source string as Array of characters.
830        // types:
831        //              Array of types, for each character in chars.
832        // classes:
833        //              Array of classes that already been solved.
834        // ix:
835        //              the index of checked character.
836        // tags:
837        //              private                         
838        var cType = types[ix], wType, nType, len, i;
839        switch(cType){
840                case UBAT_L:
841                case UBAT_R:
842                        bdx.lastArabic = false;
843                case UBAT_ON:
844                case UBAT_AN:
845                        return cType;
846                case UBAT_EN:
847                        return bdx.lastArabic ? UBAT_AN : UBAT_EN;
848                case UBAT_AL:
849                        bdx.lastArabic = true;
850                        bdx.hasUBAT_AL = true;
851                        return UBAT_R;
852                case UBAT_WS:
853                        return UBAT_ON;
854                case UBAT_CS:
855                        if(ix < 1 || (ix + 1) >= types.length ||
856                                ((wType = classes[ix - 1]) != UBAT_EN && wType != UBAT_AN) ||
857                                ((nType = types[ix + 1]) != UBAT_EN && nType != UBAT_AN)){
858                                return UBAT_ON;
859                        }
860                        if(bdx.lastArabic){nType = UBAT_AN;}
861                        return nType == wType ? nType : UBAT_ON;
862                case UBAT_ES:
863                        wType = ix > 0 ? classes[ix - 1] : UBAT_B;
864                        if(wType == UBAT_EN && (ix + 1) < types.length && types[ix + 1] == UBAT_EN){
865                                return UBAT_EN;
866                        }
867                        return UBAT_ON;
868                case UBAT_ET:
869                        if(ix > 0 && classes[ix - 1] == UBAT_EN){
870                                return UBAT_EN;
871                        }
872                        if(bdx.lastArabic){
873                                return UBAT_ON;
874                        }
875                        i = ix + 1;
876                        len = types.length;
877                        while(i < len && types[i] == UBAT_ET){
878                                i++;
879                        }
880                        if(i < len && types[i] == UBAT_EN){
881                                return UBAT_EN;
882                        }
883                        return UBAT_ON;
884                case UBAT_NSM:
885                        if(bdx.inFormat == "VLTR"){     // visual to implicit transformation
886                                len = types.length;
887                                i = ix + 1;
888                                while(i < len && types[i] == UBAT_NSM){
889                                        i++;
890                                }
891                                if(i < len){
892                                        var c = chars[ix]
893                                                , rtlCandidate = (c >= 0x0591 && c <= 0x08FF) || c == 0xFB1E
894                                                ;
895                                        wType = types[i];
896                                        if(rtlCandidate && (wType == UBAT_R || wType == UBAT_AL)){
897                                                return UBAT_R;
898                                        }
899                                }
900                        }
901                        if(ix < 1 || (wType = types[ix - 1]) == UBAT_B){
902                                return UBAT_ON;
903                        }
904                        return classes[ix - 1];
905                case UBAT_B:
906                        lastArabic = false;
907                        bdx.hasUBAT_B = true;
908                        return bdx.dir;
909                case UBAT_S:
910                        bdx.hasUBAT_S = true;
911                        return UBAT_ON;
912                case UBAT_LRE:
913                case UBAT_RLE:
914                case UBAT_LRO:
915                case UBAT_RLO:
916                case UBAT_PDF:
917                        lastArabic = false;
918                case UBAT_BN:
919                        return UBAT_ON;
920        }
921}
922
923function getMirror(c){
924        // summary:
925        //              Calculates the mirrored character of c
926        // c:
927        //              The character to be mirrored.
928        // tags:
929        //              private                                 
930        var mid, low = 0, high = SwapTable.length - 1;
931
932        while(low <= high){
933                mid = Math.floor((low + high) / 2);
934                if(c < SwapTable[mid][0]){
935                        high = mid - 1;
936                }else if(c > SwapTable[mid][0]){
937                        low = mid + 1;
938                }else{
939                        return SwapTable[mid][1];
940                }
941        }
942        return c;
943}
944
945function isStandAlonCharacter(c){
946        for(var i = 0; i < StandAlonForm.length; i++){
947                if(StandAlonForm[i] == c){
948                        return true;
949                }
950        }
951        return false;
952}
953
954function getMedialFormCharacterFE(c){
955        for(var i = 0; i < BaseForm.length; i++){
956                if(c == BaseForm[i]){
957                        return MedialForm[i];
958                }
959        }
960        return c;
961}
962
963function getFormCharacterFE(/*char*/ c, /*char[]*/formArr){
964        for(var i = 0; i < BaseForm.length; i++){
965                if(c == BaseForm[i]){
966                        return formArr[i];
967                }
968        }
969        return c;
970}
971
972function isArabicDiacritics(c){
973        return  (c >= '\u064b' && c <= '\u0655') ? true : false;
974}
975
976function getOrientation(/*Char*/ oc){
977        if(oc == 'L'){
978                return "LTR";
979        }
980        if(oc == 'R'){
981                return "RTL";
982        }
983        if(oc == 'C'){
984                return "CLR";
985        }
986        if(oc == 'D'){
987                return "CRL";
988        }
989}
990
991function setAlefToSpace(str06, index, step, nIEnd){
992        while(((index) * step) < nIEnd && isArabicDiacritics(str06[index])){
993                index += step;
994        }
995        if(((index) * step) < nIEnd){
996                str06[index] = ' ';
997                return true;
998        }
999        return false;
1000}
1001
1002function getLamAlefFE(alef06, LamAlefForm){
1003        for(var i = 0; i < AlefTable.length; i++){
1004                if(alef06 == AlefTable[i]){
1005                        return LamAlefForm[i];
1006                }
1007        }
1008        return alef06;
1009}
1010
1011function LamAlef(alef){
1012        // summary:
1013        //              If the alef variable is an ARABIC ALEF letter,
1014        //              return the LamAlef code associated with the specific
1015        //              alef character.
1016        // alef:
1017        //              The alef code type.
1018        // description:
1019        //              If "alef" is an ARABIC ALEF letter, identify which alef is it,
1020        //              using AlefTable, then return the LamAlef associated with it.
1021        // tags:
1022        //              private                 
1023        for(var i = 0; i < AlefTable.length; i++){
1024                if(AlefTable[i] == alef){
1025                        return AlefTable[i];
1026                }
1027        }
1028        return 0;
1029}
1030
1031var     bdx = {
1032                dir: 0,
1033                defInFormat: "LLTR",
1034                defoutFormat: "VLTR",
1035                defSwap: "YN",
1036                inFormat: "LLTR",
1037                outFormat: "VLTR",
1038                swap: "YN",
1039                hiLevel: 0,
1040                lastArabic: false,
1041                hasUBAT_AL: false,
1042                hasBlockSep: false,
1043                hasSegSep: false
1044};
1045
1046var ITIL = 5;
1047
1048var ITCOND = 6;
1049
1050var LTR = 0;
1051
1052var RTL = 1;
1053
1054/****************************************************************************/
1055/* Array in which directional characters are replaced by their symmetric.       */
1056/****************************************************************************/
1057var SwapTable = [
1058        [ "\u0028", "\u0029" ], /* Round brackets                                       */
1059        [ "\u0029", "\u0028" ],
1060        [ "\u003C", "\u003E" ], /* Less than/greater than                       */
1061        [ "\u003E", "\u003C" ],
1062        [ "\u005B", "\u005D" ], /* Square brackets                                      */
1063        [ "\u005D", "\u005B" ],
1064        [ "\u007B", "\u007D" ], /* Curly brackets                                       */
1065        [ "\u007D", "\u007B" ],
1066        [ "\u00AB", "\u00BB" ], /* Double angle quotation marks */
1067        [ "\u00BB", "\u00AB" ],
1068        [ "\u2039", "\u203A" ], /* single angle quotation mark          */
1069        [ "\u203A", "\u2039" ],
1070        [ "\u207D", "\u207E" ], /* Superscript parentheses                      */
1071        [ "\u207E", "\u207D" ],
1072        [ "\u208D", "\u208E" ], /* Subscript parentheses                        */
1073        [ "\u208E", "\u208D" ],
1074        [ "\u2264", "\u2265" ], /* Less/greater than or equal           */
1075        [ "\u2265", "\u2264" ],
1076        [ "\u2329", "\u232A" ], /* Angle brackets                                       */
1077        [ "\u232A", "\u2329" ],
1078        [ "\uFE59", "\uFE5A" ], /* Small round brackets                 */
1079        [ "\uFE5A", "\uFE59" ],
1080        [ "\uFE5B", "\uFE5C" ], /* Small curly brackets                 */
1081        [ "\uFE5C", "\uFE5B" ],
1082        [ "\uFE5D", "\uFE5E" ], /* Small tortoise shell brackets        */
1083        [ "\uFE5E", "\uFE5D" ],
1084        [ "\uFE64", "\uFE65" ], /* Small less than/greater than */
1085        [ "\uFE65", "\uFE64" ]
1086];
1087var AlefTable = ['\u0622', '\u0623', '\u0625', '\u0627'];
1088
1089var AlefTableFE = [0xFE81, 0xFE82, 0xFE83, 0xFE84, 0xFE87, 0xFE88, 0xFE8D, 0xFE8E];
1090
1091var LamTableFE = [0xFEDD, 0xFEDE, 0xFEDF, 0xFEE0];
1092
1093var LamAlefInialTableFE = ['\ufef5', '\ufef7', '\ufef9', '\ufefb'];
1094
1095var LamAlefMedialTableFE = ['\ufef6', '\ufef8', '\ufefa', '\ufefc'];
1096/**
1097 * Arabic Characters in the base form
1098 */
1099var BaseForm = ['\u0627', '\u0628', '\u062A', '\u062B', '\u062C', '\u062D', '\u062E', '\u062F', '\u0630', '\u0631', '\u0632', '\u0633', '\u0634', '\u0635', '\u0636', '\u0637', '\u0638', '\u0639', '\u063A', '\u0641', '\u0642', '\u0643', '\u0644', '\u0645', '\u0646', '\u0647', '\u0648', '\u064A', '\u0625', '\u0623', '\u0622', '\u0629', '\u0649', '\u06CC', '\u0626', '\u0624', '\u064B', '\u064C', '\u064D', '\u064E', '\u064F', '\u0650', '\u0651', '\u0652', '\u0621'];
1100
1101/**
1102 * Arabic shaped characters in Isolated form
1103 */
1104var IsolatedForm = ['\uFE8D', '\uFE8F', '\uFE95', '\uFE99', '\uFE9D', '\uFEA1', '\uFEA5', '\uFEA9', '\uFEAB', '\uFEAD', '\uFEAF', '\uFEB1', '\uFEB5', '\uFEB9', '\uFEBD', '\uFEC1', '\uFEC5', '\uFEC9', '\uFECD', '\uFED1', '\uFED5', '\uFED9', '\uFEDD', '\uFEE1', '\uFEE5', '\uFEE9', '\uFEED', '\uFEF1', '\uFE87', '\uFE83', '\uFE81', '\uFE93', '\uFEEF', '\uFBFC', '\uFE89', '\uFE85', '\uFE70', '\uFE72', '\uFE74', '\uFE76', '\uFE78', '\uFE7A', '\uFE7C', '\uFE7E', '\uFE80'];
1105
1106/**
1107 * Arabic shaped characters in Final form
1108 */
1109var FinalForm = ['\uFE8E', '\uFE90', '\uFE96', '\uFE9A', '\uFE9E', '\uFEA2', '\uFEA6', '\uFEAA', '\uFEAC', '\uFEAE', '\uFEB0', '\uFEB2', '\uFEB6', '\uFEBA', '\uFEBE', '\uFEC2', '\uFEC6', '\uFECA', '\uFECE', '\uFED2', '\uFED6', '\uFEDA', '\uFEDE', '\uFEE2', '\uFEE6', '\uFEEA', '\uFEEE', '\uFEF2', '\uFE88', '\uFE84', '\uFE82', '\uFE94', '\uFEF0', '\uFBFD', '\uFE8A', '\uFE86', '\uFE70', '\uFE72', '\uFE74', '\uFE76', '\uFE78', '\uFE7A', '\uFE7C', '\uFE7E', '\uFE80'];
1110
1111/**
1112 * Arabic shaped characters in Media form
1113 */
1114var MedialForm = ['\uFE8E', '\uFE92', '\uFE98', '\uFE9C', '\uFEA0', '\uFEA4', '\uFEA8', '\uFEAA', '\uFEAC', '\uFEAE', '\uFEB0', '\uFEB4', '\uFEB8', '\uFEBC', '\uFEC0', '\uFEC4', '\uFEC8', '\uFECC', '\uFED0', '\uFED4', '\uFED8', '\uFEDC', '\uFEE0', '\uFEE4', '\uFEE8', '\uFEEC', '\uFEEE', '\uFEF4', '\uFE88', '\uFE84', '\uFE82', '\uFE94', '\uFEF0', '\uFBFF', '\uFE8C', '\uFE86', '\uFE71', '\uFE72', '\uFE74', '\uFE77', '\uFE79', '\uFE7B', '\uFE7D', '\uFE7F', '\uFE80'];
1115
1116/**
1117 * Arabic shaped characters in Initial form
1118 */
1119var InitialForm = ['\uFE8D', '\uFE91', '\uFE97', '\uFE9B', '\uFE9F', '\uFEA3', '\uFEA7', '\uFEA9', '\uFEAB', '\uFEAD', '\uFEAF', '\uFEB3', '\uFEB7', '\uFEBB', '\uFEBF', '\uFEC3', '\uFEC7', '\uFECB', '\uFECF', '\uFED3', '\uFED7', '\uFEDB', '\uFEDF', '\uFEE3', '\uFEE7', '\uFEEB', '\uFEED', '\uFEF3', '\uFE87', '\uFE83', '\uFE81', '\uFE93', '\uFEEF', '\uFBFE', '\uFE8B', '\uFE85', '\uFE70', '\uFE72', '\uFE74', '\uFE76', '\uFE78', '\uFE7A', '\uFE7C', '\uFE7E', '\uFE80'];
1120
1121/**
1122 * Arabic characters that couldn't join to the next character
1123 */
1124var StandAlonForm = ['\u0621', '\u0627', '\u062F', '\u0630', '\u0631', '\u0632', '\u0648', '\u0622', '\u0629', '\u0626', '\u0624', '\u0625', '\u0675', '\u0623'];
1125
1126var FETo06Table = ['\u064B', '\u064B', '\u064C', '\u061F', '\u064D', '\u061F', '\u064E', '\u064E', '\u064F', '\u064F', '\u0650', '\u0650', '\u0651', '\u0651', '\u0652', '\u0652', '\u0621', '\u0622', '\u0622', '\u0623', '\u0623', '\u0624', '\u0624', '\u0625', '\u0625', '\u0626', '\u0626', '\u0626', '\u0626', '\u0627', '\u0627', '\u0628', '\u0628', '\u0628', '\u0628', '\u0629', '\u0629', '\u062A', '\u062A', '\u062A', '\u062A', '\u062B', '\u062B', '\u062B', '\u062B', '\u062C', '\u062C', '\u062C', '\u062c', '\u062D', '\u062D', '\u062D', '\u062D', '\u062E', '\u062E', '\u062E', '\u062E', '\u062F', '\u062F', '\u0630', '\u0630', '\u0631', '\u0631', '\u0632', '\u0632', '\u0633', '\u0633', '\u0633', '\u0633', '\u0634', '\u0634', '\u0634', '\u0634', '\u0635', '\u0635', '\u0635', '\u0635', '\u0636', '\u0636', '\u0636', '\u0636', '\u0637', '\u0637', '\u0637', '\u0637', '\u0638', '\u0638', '\u0638', '\u0638', '\u0639', '\u0639', '\u0639', '\u0639', '\u063A', '\u063A', '\u063A', '\u063A', '\u0641', '\u0641', '\u0641', '\u0641', '\u0642', '\u0642', '\u0642', '\u0642', '\u0643', '\u0643', '\u0643', '\u0643', '\u0644', '\u0644', '\u0644', '\u0644', '\u0645', '\u0645', '\u0645', '\u0645', '\u0646', '\u0646', '\u0646', '\u0646', '\u0647', '\u0647', '\u0647', '\u0647', '\u0648', '\u0648', '\u0649', '\u0649', '\u064A', '\u064A', '\u064A', '\u064A', '\uFEF5', '\uFEF6', '\uFEF7', '\uFEF8', '\uFEF9', '\uFEFA', '\uFEFB', '\uFEFC', '\u061F', '\u061F', '\u061F'];
1127
1128var ArabicAlefBetIntervalsBegine = ['\u0621', '\u0641'];
1129
1130var ArabicAlefBetIntervalsEnd = ['\u063A', '\u064a'];
1131
1132var Link06 = [
1133        1                       + 32 + 256 * 0x11,
1134        1                       + 32 + 256 * 0x13,
1135        1                       + 256 * 0x15,
1136        1                       + 32 + 256 * 0x17,
1137        1 + 2           + 256 * 0x19,
1138        1                       + 32 + 256 * 0x1D,
1139        1 + 2           + 256 * 0x1F,
1140        1                       + 256 * 0x23,
1141        1 + 2           + 256 * 0x25,
1142        1 + 2           + 256 * 0x29,
1143        1 + 2           + 256 * 0x2D,
1144        1 + 2           + 256 * 0x31,
1145        1 + 2           + 256 * 0x35,
1146        1                       + 256 * 0x39,
1147        1                       + 256 * 0x3B,
1148        1                       + 256 * 0x3D,
1149        1                       + 256 * 0x3F,
1150        1 + 2           + 256 * 0x41,
1151        1 + 2           + 256 * 0x45,
1152        1 + 2           + 256 * 0x49,
1153        1 + 2           + 256 * 0x4D,
1154        1 + 2           + 256 * 0x51,
1155        1 + 2           + 256 * 0x55,
1156        1 + 2           + 256 * 0x59,
1157        1 + 2           + 256 * 0x5D,
1158        0, 0, 0, 0, 0,  /* 0x63B - 0x63F */
1159        1 + 2,
1160        1 + 2           + 256 * 0x61,
1161        1 + 2           + 256 * 0x65,
1162        1 + 2           + 256 * 0x69,
1163        1 + 2           + 16 + 256 * 0x6D,
1164        1 + 2           + 256 * 0x71,
1165        1 + 2           + 256 * 0x75,
1166        1 + 2           + 256 * 0x79,
1167        1                       + 256 * 0x7D,
1168        1                       + 256 * 0x7F,
1169        1 + 2           + 256 * 0x81,
1170        4, 4, 4, 4,
1171        4, 4, 4, 4,     /* 0x64B - 0x652 */
1172        0, 0, 0, 0, 0,
1173        0, 0, 0, 0,     /* 0x653 - 0x65B */
1174        1                       + 256 * 0x85,
1175        1                       + 256 * 0x87,
1176        1                       + 256 * 0x89,
1177        1                       + 256 * 0x8B,
1178        0, 0, 0, 0, 0,
1179        0, 0, 0, 0, 0,
1180        0, 0, 0, 0, 0, 0,/* 0x660 - 0x66F */
1181        4,
1182        0,
1183        1                       + 32,
1184        1                       + 32,
1185        0,
1186        1                       + 32,
1187        1, 1,
1188        1+2, 1+2, 1+2, 1+2, 1+2, 1+2,
1189        1+2, 1+2, 1+2, 1+2, 1+2, 1+2,
1190        1+2, 1+2, 1+2, 1+2,
1191        1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1192        1, 1, 1, 1, 1, 1, 1, 1,
1193        1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2,
1194        1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2,
1195        1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2,
1196        1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, 1+2,
1197        1,
1198        1+2,
1199        1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1200        1+2,
1201        1,
1202        1+2, 1+2, 1+2, 1+2,
1203        1, 1
1204];
1205
1206var LinkFE = [
1207        1 + 2,
1208        1 + 2,
1209        1 + 2, 0, 1+ 2, 0, 1+ 2,
1210        1 + 2,
1211        1+ 2, 1 + 2, 1+2, 1 + 2,
1212        1+ 2, 1 + 2, 1+2, 1 + 2,
1213        0, 0 + 32, 1 + 32, 0 + 32,
1214        1 + 32, 0, 1, 0 + 32,
1215        1 + 32, 0, 2, 1 + 2,
1216        1, 0 + 32, 1 + 32, 0,
1217        2, 1 + 2, 1, 0,
1218        1, 0, 2, 1 + 2,
1219        1, 0, 2, 1 + 2,
1220        1, 0, 2, 1 + 2,
1221        1, 0, 2, 1 + 2,
1222        1, 0, 2, 1 + 2,
1223        1, 0, 1, 0,
1224        1, 0, 1, 0,
1225        1, 0, 2, 1+2,
1226        1, 0, 2, 1+2,
1227        1, 0, 2, 1+2,
1228        1, 0, 2, 1+2,
1229        1, 0, 2, 1+2,
1230        1, 0, 2, 1+2,
1231        1, 0, 2, 1+2,
1232        1, 0, 2, 1+2,
1233        1, 0, 2, 1+2,
1234        1, 0, 2, 1+2,
1235        1, 0, 2, 1+2,
1236        1, 0 + 16, 2 + 16, 1 + 2 +16,
1237        1 + 16, 0, 2, 1+2,
1238        1, 0, 2, 1+2,
1239        1, 0, 2, 1+2,
1240        1, 0, 1, 0,
1241        1, 0, 2, 1+2,
1242        1, 0, 1, 0,
1243        1, 0, 1, 0,
1244        1
1245];
1246var     impTab_LTR = [
1247                                        /*              L,              R,              EN,             AN,             N,              IL,             Cond */
1248        /* 0 LTR text   */      [       0,              3,              0,              1,              0,              0,              0       ],
1249        /* 1 LTR+AN             */      [       0,              3,              0,              1,              2,              2,              0       ],
1250        /* 2 LTR+AN+N   */      [       0,              3,              0,              0x11,   2,              0,              1       ],
1251        /* 3 RTL text   */      [       0,              3,              5,              5,              4,              1,              0       ],
1252        /* 4 RTL cont   */      [       0,              3,              0x15,   0x15,   4,              0,              1       ],
1253        /* 5 RTL+EN/AN  */      [       0,              3,              5,              5,              4,              2,              0       ]
1254];
1255var impTab_RTL = [
1256                                        /*              L,              R,              EN,             AN,             N,              IL,             Cond */
1257        /* 0 RTL text   */      [       2,              0,              1,              1,              0,              1,              0       ],
1258        /* 1 RTL+EN/AN  */      [       2,              0,              1,              1,              0,              2,              0       ],
1259        /* 2 LTR text   */      [       2,              0,              2,              1,              3,              2,              0       ],
1260        /* 3 LTR+cont   */      [       2,              0,              2,              0x21,   3,              1,              1       ]
1261];
1262
1263var UBAT_L      = 0; /* left to right                           */
1264var UBAT_R      = 1; /* right to left                           */
1265var UBAT_EN = 2; /* European digit                              */
1266var UBAT_AN = 3; /* Arabic-Indic digit                  */
1267var UBAT_ON = 4; /* neutral                                             */
1268var UBAT_B      = 5; /* block separator                         */
1269var UBAT_S      = 6; /* segment separator                       */
1270var UBAT_AL = 7; /* Arabic Letter                               */
1271var UBAT_WS = 8; /* white space                                 */
1272var UBAT_CS = 9; /* common digit separator              */
1273var UBAT_ES = 10; /* European digit separator   */
1274var UBAT_ET = 11; /* European digit terminator  */
1275var UBAT_NSM = 12; /* Non Spacing Mark                  */
1276var UBAT_LRE = 13; /* LRE                                               */
1277var UBAT_RLE = 14; /* RLE                                               */
1278var UBAT_PDF = 15; /* PDF                                               */
1279var UBAT_LRO = 16; /* LRO                                               */
1280var UBAT_RLO = 17; /* RLO                                               */
1281var UBAT_BN     = 18; /* Boundary Neutral                       */
1282
1283var TBBASE = 100;
1284
1285var TB00 = TBBASE + 0;
1286var TB05 = TBBASE + 1;
1287var TB06 = TBBASE + 2;
1288var TB07 = TBBASE + 3;
1289var TB20 = TBBASE + 4;
1290var TBFB = TBBASE + 5;
1291var TBFE = TBBASE + 6;
1292var TBFF = TBBASE + 7;
1293
1294var L   = UBAT_L;
1295var R   = UBAT_R;
1296var EN  = UBAT_EN;
1297var AN  = UBAT_AN;
1298var ON  = UBAT_ON;
1299var B   = UBAT_B;
1300var S   = UBAT_S;
1301var AL  = UBAT_AL;
1302var WS  = UBAT_WS;
1303var CS  = UBAT_CS;
1304var ES  = UBAT_ES;
1305var ET  = UBAT_ET;
1306var NSM = UBAT_NSM;
1307var LRE = UBAT_LRE;
1308var RLE = UBAT_RLE;
1309var PDF = UBAT_PDF;
1310var LRO = UBAT_LRO;
1311var RLO = UBAT_RLO;
1312var BN  = UBAT_BN;
1313
1314var MasterTable = [
1315        /************************************************************************************************************************************/
1316        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1317        /************************************************************************************************************************************/
1318        /*0-*/  TB00,   L       ,       L       ,       L       ,       L       ,       TB05,   TB06,   TB07,   R       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1319        /*1-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1320        /*2-*/  TB20,   ON      ,       ON      ,       ON      ,       L       ,       ON      ,       L       ,       ON      ,       L       ,       ON      ,       ON      ,       ON      ,       L       ,       L       ,       ON      ,       ON      ,
1321        /*3-*/  L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1322        /*4-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       L       ,       L       ,       ON      ,
1323        /*5-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1324        /*6-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1325        /*7-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1326        /*8-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1327        /*9-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       L       ,
1328        /*A-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,
1329        /*B-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1330        /*C-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1331        /*D-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       L       ,       L       ,       ON      ,       ON      ,       L       ,       L       ,       ON      ,       ON      ,       L       ,
1332        /*E-*/  L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1333        /*F-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       L       ,       L       ,       L       ,       TBFB,   AL      ,       AL      ,       TBFE,   TBFF
1334];
1335
1336delete TB00;
1337delete TB05;
1338delete TB06;
1339delete TB07;
1340delete TB20;
1341delete TBFB;
1342delete TBFE;
1343delete TBFF;
1344
1345var UnicodeTable = [
1346        [ /*    Table 00: Unicode 00xx */
1347        /************************************************************************************************************************************/
1348        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1349        /************************************************************************************************************************************/
1350        /*0-*/  BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       S       ,       B       ,       S       ,       WS      ,       B       ,       BN      ,       BN      ,
1351        /*1-*/  BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       B       ,       B       ,       B       ,       S       ,
1352        /*2-*/  WS      ,       ON      ,       ON      ,       ET      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ES      ,       CS      ,       ES      ,       CS      ,       CS      ,
1353        /*3-*/  EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       CS      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1354        /*4-*/  ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1355        /*5-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1356        /*6-*/  ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1357        /*7-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       BN      ,
1358        /*8-*/  BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       B       ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,
1359        /*9-*/  BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,
1360        /*A-*/  CS      ,       ON      ,       ET      ,       ET      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       L       ,       ON      ,       ON      ,       BN      ,       ON      ,       ON      ,
1361        /*B-*/  ET      ,       ET      ,       EN      ,       EN      ,       ON      ,       L       ,       ON      ,       ON      ,       ON      ,       EN      ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1362        /*C-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1363        /*D-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1364        /*E-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1365        /*F-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L
1366        ],
1367        [ /*    Table 01: Unicode 05xx */
1368        /************************************************************************************************************************************/
1369        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1370        /************************************************************************************************************************************/
1371        /*0-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1372        /*1-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1373        /*2-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON       , ON   ,       ON      ,
1374        /*3-*/  ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1375        /*4-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1376        /*5-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1377        /*6-*/  ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1378        /*7-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1379        /*8-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1380        /*9-*/  ON      ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1381        /*A-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1382        /*B-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       R       ,       NSM     ,
1383        /*C-*/  R       ,       NSM     ,       NSM     ,       R       ,       NSM     ,       NSM     ,       R       ,       NSM     ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1384        /*D-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,
1385        /*E-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1386        /*F-*/  R       ,       R       ,       R       ,       R       ,       R       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON
1387        ],
1388        [ /*    Table 02: Unicode 06xx */
1389        /************************************************************************************************************************************/
1390        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1391        /************************************************************************************************************************************/
1392        /*0-*/  AN      ,       AN      ,       AN      ,       AN      ,       ON      ,       ON      ,       ON      ,       ON      ,       AL      ,       ET      ,       ET      ,       AL      ,       CS      ,       AL      ,       ON      ,       ON      ,
1393        /*1-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       AL      ,       ON      ,       ON      ,       AL      ,       AL      ,
1394        /*2-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1395        /*3-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1396        /*4-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1397        /*5-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1398        /*6-*/  AN      ,       AN      ,       AN      ,       AN      ,       AN      ,       AN      ,       AN      ,       AN      ,       AN      ,       AN      ,       ET      ,       AN      ,       AN      ,       AL      ,       AL      ,       AL      ,
1399        /*7-*/  NSM     ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1400        /*8-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1401        /*9-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1402        /*A-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1403        /*B-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1404        /*C-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1405        /*D-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       AN      ,       ON      ,       NSM     ,
1406        /*E-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       AL      ,       AL      ,       NSM     ,       NSM     ,       ON      ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       AL      ,       AL      ,
1407        /*F-*/  EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL
1408        ],
1409        [       /*      Table   03:     Unicode 07xx    */
1410        /************************************************************************************************************************************/
1411        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1412        /************************************************************************************************************************************/
1413        /*0-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       ON      ,       AL      ,
1414        /*1-*/  AL      ,       NSM     ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1415        /*2-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1416        /*3-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1417        /*4-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       ON      ,       ON      ,       AL      ,       AL      ,       AL      ,
1418        /*5-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1419        /*6-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1420        /*7-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1421        /*8-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1422        /*9-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1423        /*A-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1424        /*B-*/  NSM     ,       AL      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1425        /*C-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,
1426        /*D-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,
1427        /*E-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1428        /*F-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       R       ,       R       ,       ON      ,       ON      ,       ON      ,       ON      ,       R       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON
1429        ],
1430        [       /*      Table   04:     Unicode 20xx    */
1431        /************************************************************************************************************************************/
1432        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1433        /************************************************************************************************************************************/
1434        /*0-*/  WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       WS      ,       BN      ,       BN      ,       BN      ,       L       ,       R       ,
1435        /*1-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1436        /*2-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       WS      ,       B       ,       LRE     ,       RLE     ,       PDF     ,       LRO     ,       RLO     ,       CS      ,
1437        /*3-*/  ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1438        /*4-*/  ON      ,       ON      ,       ON      ,       ON      ,       CS      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1439        /*5-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       WS      ,
1440        /*6-*/  BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,       BN      ,
1441        /*7-*/  EN      ,       L       ,       ON      ,       ON      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       ES      ,       ES      ,       ON      ,       ON      ,       ON      ,       L       ,
1442        /*8-*/  EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       ES      ,       ES      ,       ON      ,       ON      ,       ON      ,       ON      ,
1443        /*9-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,
1444        /*A-*/  ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,
1445        /*B-*/  ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1446        /*C-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1447        /*D-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1448        /*E-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1449        /*F-*/  NSM     ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON
1450        ],
1451        [       /*      Table   05:     Unicode FBxx    */
1452        /************************************************************************************************************************************/
1453        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1454        /************************************************************************************************************************************/
1455        /*0-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1456        /*1-*/  ON      ,       ON      ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       R       ,       NSM     ,       R       ,
1457        /*2-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       ES      ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,
1458        /*3-*/  R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       ON      ,       R       ,       R       ,       R       ,       R       ,       R       ,       ON      ,       R       ,       ON      ,
1459        /*4-*/  R       ,       R       ,       ON      ,       R       ,       R       ,       ON      ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,       R       ,
1460        /*5-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1461        /*6-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1462        /*7-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1463        /*8-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1464        /*9-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1465        /*A-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1466        /*B-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1467        /*C-*/  AL      ,       AL      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1468        /*D-*/  ON      ,       ON      ,       ON      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1469        /*E-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1470        /*F-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL
1471        ],
1472        [       /*      Table   06:     Unicode FExx    */
1473        /************************************************************************************************************************************/
1474        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1475        /************************************************************************************************************************************/
1476        /*0-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,
1477        /*1-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1478        /*2-*/  NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       NSM     ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1479        /*3-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1480        /*4-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1481        /*5-*/  CS      ,       ON      ,       CS      ,       ON      ,       ON      ,       CS      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ET      ,
1482        /*6-*/  ON      ,       ON      ,       ES      ,       ES      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1483        /*7-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       ON      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1484        /*8-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1485        /*9-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1486        /*A-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1487        /*B-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1488        /*C-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1489        /*D-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1490        /*E-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,
1491        /*F-*/  AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       AL      ,       ON      ,       ON      ,       BN
1492        ],
1493        [       /*      Table   07:     Unicode FFxx    */
1494        /************************************************************************************************************************************/
1495        /*              0               1               2               3               4               5               6               7               8               9               A               B               C               D               E               F       */
1496        /************************************************************************************************************************************/
1497        /*0-*/  ON      ,       ON      ,       ON      ,       ET      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ES      ,       CS      ,       ES      ,       CS      ,       CS      ,
1498        /*1-*/  EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       EN      ,       CS      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1499        /*2-*/  ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1500        /*3-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1501        /*4-*/  ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1502        /*5-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1503        /*6-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1504        /*7-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1505        /*8-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1506        /*9-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1507        /*A-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1508        /*B-*/  L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,
1509        /*C-*/  ON      ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,
1510        /*D-*/  ON      ,       ON      ,       L       ,       L       ,       L       ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       L       ,       L       ,       L       ,       ON      ,       ON      ,       ON      ,
1511        /*E-*/  ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ET      ,       ET      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,
1512        /*F-*/  ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON      ,       ON
1513        ]
1514];
1515
1516delete L;
1517delete R;
1518delete EN;
1519delete AN;
1520delete ON;
1521delete B;
1522delete S;
1523delete AL;
1524delete WS;
1525delete CS;
1526delete ES;
1527delete ET;
1528delete NSM;
1529delete LRE;
1530delete RLE;
1531delete PDF;
1532delete LRO;
1533delete RLO;
1534delete BN;
1535
1536return BidiEngine;
1537});
Note: See TracBrowser for help on using the repository browser.