| 2781 | }; |
| 2782 | // Utility used by replace and split above |
| 2783 | function copyStyles(from, to, source, dest) { |
| 2784 | for (var i = 0, pos = 0, state = 0; pos < to; i+=2) { |
| 2785 | var part = source[i], end = pos + part.length; |
| 2786 | if (state == 0) { |
| 2787 | if (end > from) dest.push(part.slice(from - pos, Math.min(part.length, to - pos)), source[i+1]); |
| 2788 | if (end >= from) state = 1; |
| 2789 | } |
| 2790 | else if (state == 1) { |
| 2791 | if (end > to) dest.push(part.slice(0, to - pos), source[i+1]); |
| 2792 | else dest.push(part, source[i+1]); |
| 2793 | } |
| 2794 | pos = end; |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | // Data structure that holds the sequence of lines. |
| 2799 | function LeafChunk(lines) { |