|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
|---|
| 4 | var callBound = require('call-bound');
|
|---|
| 5 |
|
|---|
| 6 | var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
|
|---|
| 7 | var $TypeError = require('es-errors/type');
|
|---|
| 8 | var $charCodeAt = callBound('String.prototype.charCodeAt');
|
|---|
| 9 |
|
|---|
| 10 | var CharSet = require('../helpers/CharSet').CharSet;
|
|---|
| 11 |
|
|---|
| 12 | module.exports = function CharacterRange(A, B) {
|
|---|
| 13 | var a;
|
|---|
| 14 | var b;
|
|---|
| 15 |
|
|---|
| 16 | if (A instanceof CharSet || B instanceof CharSet) {
|
|---|
| 17 | if (!(A instanceof CharSet) || !(B instanceof CharSet)) {
|
|---|
| 18 | throw new $TypeError('Assertion failed: CharSets A and B are not both CharSets');
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | A.yield(function (c) {
|
|---|
| 22 | if (typeof a !== 'undefined') {
|
|---|
| 23 | throw new $TypeError('Assertion failed: CharSet A has more than one character');
|
|---|
| 24 | }
|
|---|
| 25 | a = c;
|
|---|
| 26 | });
|
|---|
| 27 | B.yield(function (c) {
|
|---|
| 28 | if (typeof b !== 'undefined') {
|
|---|
| 29 | throw new $TypeError('Assertion failed: CharSet B has more than one character');
|
|---|
| 30 | }
|
|---|
| 31 | b = c;
|
|---|
| 32 | });
|
|---|
| 33 | } else {
|
|---|
| 34 | if (A.length !== 1 || B.length !== 1) {
|
|---|
| 35 | throw new $TypeError('Assertion failed: CharSets A and B contain exactly one character');
|
|---|
| 36 | }
|
|---|
| 37 | a = A[0];
|
|---|
| 38 | b = B[0];
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | var i = $charCodeAt(a, 0);
|
|---|
| 42 | var j = $charCodeAt(b, 0);
|
|---|
| 43 |
|
|---|
| 44 | if (!(i <= j)) {
|
|---|
| 45 | throw new $TypeError('Assertion failed: i is not <= j');
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | var arr = [];
|
|---|
| 49 | for (var k = i; k <= j; k += 1) {
|
|---|
| 50 | arr[arr.length] = $fromCharCode(k);
|
|---|
| 51 | }
|
|---|
| 52 | return arr;
|
|---|
| 53 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.