Skip to content
Myr

Use loop for acceptParams (#6066)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Blake Embrey · committed by GitHub · parent 9e3dbb4 · Browse files · 1 file+24 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−7 removed

  • other:+24 added−7 removed

1 file+24 added−7 removed

modified:lib/utils.js+24 added-7 removed
82 unmodified lines
83 * @api private84 */8586function acceptParams (str) {87 var parts = str.split(/ *; */);88 var ret = { value: parts[0], quality: 1, params: {} }87 var length = str.length;88 var colonIndex = str.indexOf(';');89 var index = colonIndex === -1 ? length : colonIndex;90 var ret = { value: str.slice(0, index).trim(), quality: 1, params: {} };9190 for (var i = 1; i < parts.length; ++i) {91 var pms = parts[i].split(/ *= */);92 if ('q' === pms[0]) {93 ret.quality = parseFloat(pms[1]);92 while (index < length) {93 var splitIndex = str.indexOf('=', index);94 if (splitIndex === -1) break;9596 var colonIndex = str.indexOf(';', index);97 var endIndex = colonIndex === -1 ? length : colonIndex;9899 if (splitIndex > endIndex) {100 index = str.lastIndexOf(';', splitIndex - 1) + 1;101 continue;102 }103104 var key = str.slice(index, splitIndex).trim();105 var value = str.slice(splitIndex + 1, endIndex).trim();106107 if (key === 'q') {108 ret.quality = parseFloat(value);109 } else {95 ret.params[pms[0]] = pms[1];110 ret.params[key] = value;111 }112113 index = endIndex + 1;114 }115116 return ret;117}
151 unmodified lines