reinsert_formatting_codes

in lib/twitter_cldr/shared/bidi.rb [460:502]


      def reinsert_formatting_codes
        if @formatter_indices
          input = @length
          output = @levels.size

          
          (@formatter_indices.size - 1).downto(0) do |index|
            next_fmt = @formatter_indices[index]

            
            
            
            
            len = output - next_fmt - 1
            output = next_fmt
            input -= len

            
            
            if next_fmt + 1 < @levels.size
              arraycopy(@levels, input, @levels, next_fmt + 1, len)
            end

            
            right_level = if output == @levels.length - 1
              @base_embedding
            else
              @levels[output + 1] || 0
            end

            left_level = if input == 0
              @base_embedding
            else
              @levels[input] || 0;
            end

            @levels[output] = [left_level, right_level].max
          end
        end

        @length = @levels.size
      end