MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / isInsideStringDelimiters

Function isInsideStringDelimiters

cli/src/hooks/use-suggestion-engine.ts:76–104  ·  view source on GitHub ↗
(text: string, position: number)

Source from the content-addressed store, hash-verified

74// Helper to check if a position is inside string delimiters (double quotes or backticks only)
75// Single quotes are excluded because they're commonly used as apostrophes (don't, it's, etc.)
76export const isInsideStringDelimiters = (text: string, position: number): boolean => {
77 let inDoubleQuote = false
78 let inBacktick = false
79
80 for (let i = 0; i < position; i++) {
81 const char = text[i]
82
83 // Check if this character is escaped by counting preceding backslashes
84 let numBackslashes = 0
85 let j = i - 1
86 while (j >= 0 && text[j] === '\\') {
87 numBackslashes++
88 j--
89 }
90
91 // If there's an odd number of backslashes, the character is escaped
92 const isEscaped = numBackslashes % 2 === 1
93
94 if (!isEscaped) {
95 if (char === '"' && !inBacktick) {
96 inDoubleQuote = !inDoubleQuote
97 } else if (char === '`' && !inDoubleQuote) {
98 inBacktick = !inBacktick
99 }
100 }
101 }
102
103 return inDoubleQuote || inBacktick
104}
105
106export const parseAtInLine = (line: string): MentionParseResult => {
107 const atIndex = line.lastIndexOf('@')

Callers 2

parseAtInLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected