source: trip-planner-front/node_modules/core-js/modules/es.string.search.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[6a3a178]1'use strict';
2var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
3var anObject = require('../internals/an-object');
4var requireObjectCoercible = require('../internals/require-object-coercible');
5var sameValue = require('../internals/same-value');
6var toString = require('../internals/to-string');
7var regExpExec = require('../internals/regexp-exec-abstract');
8
9// @@search logic
10fixRegExpWellKnownSymbolLogic('search', function (SEARCH, nativeSearch, maybeCallNative) {
11 return [
12 // `String.prototype.search` method
13 // https://tc39.es/ecma262/#sec-string.prototype.search
14 function search(regexp) {
15 var O = requireObjectCoercible(this);
16 var searcher = regexp == undefined ? undefined : regexp[SEARCH];
17 return searcher !== undefined ? searcher.call(regexp, O) : new RegExp(regexp)[SEARCH](toString(O));
18 },
19 // `RegExp.prototype[@@search]` method
20 // https://tc39.es/ecma262/#sec-regexp.prototype-@@search
21 function (string) {
22 var rx = anObject(this);
23 var S = toString(string);
24 var res = maybeCallNative(nativeSearch, rx, S);
25
26 if (res.done) return res.value;
27
28 var previousLastIndex = rx.lastIndex;
29 if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
30 var result = regExpExec(rx, S);
31 if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
32 return result === null ? -1 : result.index;
33 }
34 ];
35});
Note: See TracBrowser for help on using the repository browser.