Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to convert any Regenerate set to code that generates it #20

Closed
mathiasbynens opened this issue Apr 23, 2014 · 0 comments
Closed

Comments

@mathiasbynens
Copy link
Owner

This is not really a bug report, but rather a script that is useful when generating test cases:

regenerate.prototype.toCode = function() {
    var data = this.data;
    // Iterate over the data per `(start, end)` pair.
    var index = 0;
    var start;
    var end;
    var length = data.length;
    var loneCodePoints = [];
    var ranges = [];
    while (index < length) {
        start = data[index];
        end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive.
        if (start == end) {
            loneCodePoints.push('0x' + start.toString(16).toUpperCase());
        } else {
            ranges.push(
                'addRange(0x' + start.toString(16).toUpperCase() +
                ', 0x' + end.toString(16).toUpperCase() + ')'
            );
        }
        index += 2;
    }
    return 'regenerate(' + loneCodePoints.join(', ') + ')' +
        (ranges.length ? '.' + ranges.join('.') : '');
};

var set = regenerate(0x1D306, 'a').addRange(0x2CEE, 0x4DFF);
console.log(set.toCode());
// → 'regenerate(0x61, 0x1D306).addRange(0x2CEE, 0x4DFF)'

Let’s allow extending regenerate.prototype for plugins like this.

mathiasbynens added a commit that referenced this issue Apr 23, 2014
This makes it possible to create plugins for Regenerate, such as the one in #20.
mathiasbynens added a commit that referenced this issue May 25, 2014
This makes it possible to create plugins for Regenerate, such as the one in #20.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant