( out, olen, ol, state, is_all_upper, usx_hcodes, usx_hcode_lens )
| 489 | |
| 490 | /// Appends the terminator code depending on the state, preset and whether full terminator needs to be encoded to out or not \n |
| 491 | function append_final_bits( |
| 492 | out, |
| 493 | olen, |
| 494 | ol, |
| 495 | state, |
| 496 | is_all_upper, |
| 497 | usx_hcodes, |
| 498 | usx_hcode_lens |
| 499 | ) { |
| 500 | if (usx_hcode_lens[USX_ALPHA]) { |
| 501 | if (USX_NUM != state) { |
| 502 | // for num state, append TERM_CODE directly |
| 503 | // for other state, switch to Num Set first |
| 504 | ol = append_switch_code(out, olen, ol, state); |
| 505 | ol = append_bits( |
| 506 | out, |
| 507 | olen, |
| 508 | ol, |
| 509 | usx_hcodes[USX_NUM], |
| 510 | usx_hcode_lens[USX_NUM] |
| 511 | ); |
| 512 | } |
| 513 | ol = append_bits( |
| 514 | out, |
| 515 | olen, |
| 516 | ol, |
| 517 | usx_vcodes[TERM_CODE & 0x1f], |
| 518 | usx_vcode_lens[TERM_CODE & 0x1f] |
| 519 | ); |
| 520 | } else { |
| 521 | // preset 1, terminate at 2 or 3 SW_CODE, i.e., 4 or 6 continuous 0 bits |
| 522 | // see discussion: https://github.com/siara-cc/Unishox/issues/19#issuecomment-922435580 |
| 523 | ol = append_bits( |
| 524 | out, |
| 525 | olen, |
| 526 | ol, |
| 527 | TERM_BYTE_PRESET_1, |
| 528 | is_all_upper ? TERM_BYTE_PRESET_1_LEN_UPPER : TERM_BYTE_PRESET_1_LEN_LOWER |
| 529 | ); |
| 530 | } |
| 531 | |
| 532 | // fill byte with the last bit |
| 533 | ol = append_bits( |
| 534 | out, |
| 535 | olen, |
| 536 | ol, |
| 537 | ol == 0 || out[(ol - 1) / 8] << ((ol - 1) & 7) >= 0 ? 0 : 0xff, |
| 538 | (8 - (ol % 8)) & 7 |
| 539 | ); |
| 540 | |
| 541 | return ol; |
| 542 | } |
| 543 | |
| 544 | function compare_arr(arr1, arr2, is_str) { |
| 545 | if (is_str) return arr1 === arr2; |
no test coverage detected