"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/oniguruma/lib/onig-reg-exp.js" (8 Mar 2017, 2029 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var OnigRegExp, OnigScanner;
    3 
    4   OnigScanner = require('../build/Release/onig_scanner.node').OnigScanner;
    5 
    6   module.exports = OnigRegExp = (function() {
    7     function OnigRegExp(source) {
    8       this.source = source;
    9       this.scanner = new OnigScanner([this.source]);
   10     }
   11 
   12     OnigRegExp.prototype.captureIndicesForMatch = function(string, match) {
   13       var capture, captureIndices, i, len;
   14       if (match != null) {
   15         captureIndices = match.captureIndices;
   16         string = this.scanner.convertToString(string);
   17         for (i = 0, len = captureIndices.length; i < len; i++) {
   18           capture = captureIndices[i];
   19           capture.match = string.slice(capture.start, capture.end);
   20         }
   21         return captureIndices;
   22       } else {
   23         return null;
   24       }
   25     };
   26 
   27     OnigRegExp.prototype.searchSync = function(string, startPosition) {
   28       var match;
   29       if (startPosition == null) {
   30         startPosition = 0;
   31       }
   32       match = this.scanner.findNextMatchSync(string, startPosition);
   33       return this.captureIndicesForMatch(string, match);
   34     };
   35 
   36     OnigRegExp.prototype.search = function(string, startPosition, callback) {
   37       if (startPosition == null) {
   38         startPosition = 0;
   39       }
   40       if (typeof startPosition === 'function') {
   41         callback = startPosition;
   42         startPosition = 0;
   43       }
   44       return this.scanner.findNextMatch(string, startPosition, (function(_this) {
   45         return function(error, match) {
   46           return typeof callback === "function" ? callback(error, _this.captureIndicesForMatch(string, match)) : void 0;
   47         };
   48       })(this));
   49     };
   50 
   51     OnigRegExp.prototype.testSync = function(string) {
   52       return this.searchSync(string) != null;
   53     };
   54 
   55     OnigRegExp.prototype.test = function(string, callback) {
   56       return this.search(string, 0, function(error, result) {
   57         return typeof callback === "function" ? callback(error, result != null) : void 0;
   58       });
   59     };
   60 
   61     return OnigRegExp;
   62 
   63   })();
   64 
   65 }).call(this);