MCPcopy Create free account
hub / github.com/anus-dev/ANUS / trimPairIfPossible

Function trimPairIfPossible

packages/core/src/utils/editCorrector.ts:658–684  ·  view source on GitHub ↗
(
  target: string,
  trimIfTargetTrims: string,
  currentContent: string,
  expectedReplacements: number,
)

Source from the content-addressed store, hash-verified

656}
657
658function trimPairIfPossible(
659 target: string,
660 trimIfTargetTrims: string,
661 currentContent: string,
662 expectedReplacements: number,
663) {
664 const trimmedTargetString = target.trim();
665 if (target.length !== trimmedTargetString.length) {
666 const trimmedTargetOccurrences = countOccurrences(
667 currentContent,
668 trimmedTargetString,
669 );
670
671 if (trimmedTargetOccurrences === expectedReplacements) {
672 const trimmedReactiveString = trimIfTargetTrims.trim();
673 return {
674 targetString: trimmedTargetString,
675 pair: trimmedReactiveString,
676 };
677 }
678 }
679
680 return {
681 targetString: target,
682 pair: trimIfTargetTrims,
683 };
684}
685
686/**
687 * Unescapes a string that might have been overly escaped by an LLM.

Callers 1

ensureCorrectEditFunction · 0.85

Calls 1

countOccurrencesFunction · 0.85

Tested by

no test coverage detected