MCPcopy
hub / github.com/VSCodeVim/Vim / evaluateSlice

Method evaluateSlice

src/vimscript/expression/evaluate.ts:436–477  ·  view source on GitHub ↗
(sequence: Value, start: Value, end: Value)

Source from the content-addressed store, hash-verified

434 }
435
436 private evaluateSlice(sequence: Value, start: Value, end: Value): Value {
437 let _start = toInt(start);
438 let _end = toInt(end);
439 switch (sequence.type) {
440 case 'string':
441 case 'number':
442 case 'float': {
443 const _sequence = toString(sequence);
444 while (_start < 0) {
445 _start += _sequence.length;
446 }
447 while (_end < 0) {
448 _end += _sequence.length;
449 }
450 if (_end < _start) {
451 return str('');
452 }
453 return str(_sequence.substring(_start, _end + 1));
454 }
455 case 'list': {
456 while (_start < 0) {
457 _start += sequence.items.length;
458 }
459 while (_end < 0) {
460 _end += sequence.items.length;
461 }
462 if (_end < _start) {
463 return list([]);
464 }
465 return list(sequence.items.slice(_start, _end + 1));
466 }
467 case 'dictionary': {
468 throw VimError.CannotUseSliceWithADictionary();
469 }
470 case 'funcref': {
471 throw VimError.CannotIndexAFuncref();
472 }
473 case 'blob': {
474 return blob(new Uint8Array(sequence.data).slice(_start, _end + 1));
475 }
476 }
477 }
478
479 private evaluateUnary(operator: UnaryOp, operand: Expression): NumberValue | FloatValue {
480 return mapNumber(this.evaluate(operand), (x: number) => {

Callers 1

evaluateMethod · 0.95

Calls 7

strFunction · 0.90
listFunction · 0.90
blobFunction · 0.90
toIntFunction · 0.85
CannotIndexAFuncrefMethod · 0.80
toStringFunction · 0.70

Tested by

no test coverage detected