Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

es.string.split.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use strict';
  2. var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
  3. var isRegExp = require('../internals/is-regexp');
  4. var anObject = require('../internals/an-object');
  5. var requireObjectCoercible = require('../internals/require-object-coercible');
  6. var speciesConstructor = require('../internals/species-constructor');
  7. var advanceStringIndex = require('../internals/advance-string-index');
  8. var toLength = require('../internals/to-length');
  9. var callRegExpExec = require('../internals/regexp-exec-abstract');
  10. var regexpExec = require('../internals/regexp-exec');
  11. var stickyHelpers = require('../internals/regexp-sticky-helpers');
  12. var fails = require('../internals/fails');
  13. var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y;
  14. var arrayPush = [].push;
  15. var min = Math.min;
  16. var MAX_UINT32 = 0xFFFFFFFF;
  17. // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
  18. // Weex JS has frozen built-in prototypes, so use try / catch wrapper
  19. var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () {
  20. // eslint-disable-next-line regexp/no-empty-group -- required for testing
  21. var re = /(?:)/;
  22. var originalExec = re.exec;
  23. re.exec = function () { return originalExec.apply(this, arguments); };
  24. var result = 'ab'.split(re);
  25. return result.length !== 2 || result[0] !== 'a' || result[1] !== 'b';
  26. });
  27. // @@split logic
  28. fixRegExpWellKnownSymbolLogic('split', function (SPLIT, nativeSplit, maybeCallNative) {
  29. var internalSplit;
  30. if (
  31. 'abbc'.split(/(b)*/)[1] == 'c' ||
  32. // eslint-disable-next-line regexp/no-empty-group -- required for testing
  33. 'test'.split(/(?:)/, -1).length != 4 ||
  34. 'ab'.split(/(?:ab)*/).length != 2 ||
  35. '.'.split(/(.?)(.?)/).length != 4 ||
  36. // eslint-disable-next-line regexp/no-assertion-capturing-group, regexp/no-empty-group -- required for testing
  37. '.'.split(/()()/).length > 1 ||
  38. ''.split(/.?/).length
  39. ) {
  40. // based on es5-shim implementation, need to rework it
  41. internalSplit = function (separator, limit) {
  42. var string = String(requireObjectCoercible(this));
  43. var lim = limit === undefined ? MAX_UINT32 : limit >>> 0;
  44. if (lim === 0) return [];
  45. if (separator === undefined) return [string];
  46. // If `separator` is not a regex, use native split
  47. if (!isRegExp(separator)) {
  48. return nativeSplit.call(string, separator, lim);
  49. }
  50. var output = [];
  51. var flags = (separator.ignoreCase ? 'i' : '') +
  52. (separator.multiline ? 'm' : '') +
  53. (separator.unicode ? 'u' : '') +
  54. (separator.sticky ? 'y' : '');
  55. var lastLastIndex = 0;
  56. // Make `global` and avoid `lastIndex` issues by working with a copy
  57. var separatorCopy = new RegExp(separator.source, flags + 'g');
  58. var match, lastIndex, lastLength;
  59. while (match = regexpExec.call(separatorCopy, string)) {
  60. lastIndex = separatorCopy.lastIndex;
  61. if (lastIndex > lastLastIndex) {
  62. output.push(string.slice(lastLastIndex, match.index));
  63. if (match.length > 1 && match.index < string.length) arrayPush.apply(output, match.slice(1));
  64. lastLength = match[0].length;
  65. lastLastIndex = lastIndex;
  66. if (output.length >= lim) break;
  67. }
  68. if (separatorCopy.lastIndex === match.index) separatorCopy.lastIndex++; // Avoid an infinite loop
  69. }
  70. if (lastLastIndex === string.length) {
  71. if (lastLength || !separatorCopy.test('')) output.push('');
  72. } else output.push(string.slice(lastLastIndex));
  73. return output.length > lim ? output.slice(0, lim) : output;
  74. };
  75. // Chakra, V8
  76. } else if ('0'.split(undefined, 0).length) {
  77. internalSplit = function (separator, limit) {
  78. return separator === undefined && limit === 0 ? [] : nativeSplit.call(this, separator, limit);
  79. };
  80. } else internalSplit = nativeSplit;
  81. return [
  82. // `String.prototype.split` method
  83. // https://tc39.es/ecma262/#sec-string.prototype.split
  84. function split(separator, limit) {
  85. var O = requireObjectCoercible(this);
  86. var splitter = separator == undefined ? undefined : separator[SPLIT];
  87. return splitter !== undefined
  88. ? splitter.call(separator, O, limit)
  89. : internalSplit.call(String(O), separator, limit);
  90. },
  91. // `RegExp.prototype[@@split]` method
  92. // https://tc39.es/ecma262/#sec-regexp.prototype-@@split
  93. //
  94. // NOTE: This cannot be properly polyfilled in engines that don't support
  95. // the 'y' flag.
  96. function (string, limit) {
  97. var res = maybeCallNative(internalSplit, this, string, limit, internalSplit !== nativeSplit);
  98. if (res.done) return res.value;
  99. var rx = anObject(this);
  100. var S = String(string);
  101. var C = speciesConstructor(rx, RegExp);
  102. var unicodeMatching = rx.unicode;
  103. var flags = (rx.ignoreCase ? 'i' : '') +
  104. (rx.multiline ? 'm' : '') +
  105. (rx.unicode ? 'u' : '') +
  106. (UNSUPPORTED_Y ? 'g' : 'y');
  107. // ^(? + rx + ) is needed, in combination with some S slicing, to
  108. // simulate the 'y' flag.
  109. var splitter = new C(UNSUPPORTED_Y ? '^(?:' + rx.source + ')' : rx, flags);
  110. var lim = limit === undefined ? MAX_UINT32 : limit >>> 0;
  111. if (lim === 0) return [];
  112. if (S.length === 0) return callRegExpExec(splitter, S) === null ? [S] : [];
  113. var p = 0;
  114. var q = 0;
  115. var A = [];
  116. while (q < S.length) {
  117. splitter.lastIndex = UNSUPPORTED_Y ? 0 : q;
  118. var z = callRegExpExec(splitter, UNSUPPORTED_Y ? S.slice(q) : S);
  119. var e;
  120. if (
  121. z === null ||
  122. (e = min(toLength(splitter.lastIndex + (UNSUPPORTED_Y ? q : 0)), S.length)) === p
  123. ) {
  124. q = advanceStringIndex(S, q, unicodeMatching);
  125. } else {
  126. A.push(S.slice(p, q));
  127. if (A.length === lim) return A;
  128. for (var i = 1; i <= z.length - 1; i++) {
  129. A.push(z[i]);
  130. if (A.length === lim) return A;
  131. }
  132. q = p = e;
  133. }
  134. }
  135. A.push(S.slice(p));
  136. return A;
  137. }
  138. ];
  139. }, !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC, UNSUPPORTED_Y);