(filePath string, lines []string, lineNum, col int, text string, account *types.Account)
| 149 | } |
| 150 | |
| 151 | func applyInsert(filePath string, lines []string, lineNum, col int, text string, account *types.Account) error { |
| 152 | if lineNum < 0 || lineNum >= len(lines) { |
| 153 | return fmt.Errorf("line number out of range: %d", lineNum) |
| 154 | } |
| 155 | |
| 156 | line := lines[lineNum] |
| 157 | runes := []rune(line) |
| 158 | |
| 159 | if col < 0 { |
| 160 | col = 0 |
| 161 | } |
| 162 | if col > len(runes) { |
| 163 | col = len(runes) |
| 164 | } |
| 165 | |
| 166 | newRunes := make([]rune, 0, len(runes)+len([]rune(text))) |
| 167 | newRunes = append(newRunes, runes[:col]...) |
| 168 | newRunes = append(newRunes, []rune(text)...) |
| 169 | newRunes = append(newRunes, runes[col:]...) |
| 170 | |
| 171 | lines[lineNum] = string(newRunes) |
| 172 | return writeFile(filePath, lines, account) |
| 173 | } |
| 174 | |
| 175 | func applyDelete(filePath string, lines []string, startLine, startCol, endLine, endCol int, account *types.Account) error { |
| 176 | if startLine < 0 || startLine >= len(lines) || endLine < 0 || endLine >= len(lines) { |
no test coverage detected