MCPcopy Index your code
hub / github.com/expr-lang/expr / scanRawString

Method scanRawString

parser/lexer/lexer.go:271–315  ·  view source on GitHub ↗
(quote rune)

Source from the content-addressed store, hash-verified

269}
270
271func (l *Lexer) scanRawString(quote rune) (n int) {
272 var escapedQuotes int
273loop:
274 for {
275 ch := l.next()
276 for ch == quote && l.peek() == quote {
277 // skip current and next char which are the quote escape sequence
278 l.next()
279 ch = l.next()
280 escapedQuotes++
281 }
282 switch ch {
283 case quote:
284 break loop
285 case eof:
286 l.error("literal not terminated")
287 return
288 }
289 n++
290 }
291 str := l.source.String()[l.start.byte+1 : l.end.byte-1]
292
293 // handle simple case where no quoted backtick was found, then no allocation
294 // is needed for the new string
295 if escapedQuotes == 0 {
296 l.emitValue(String, str)
297 return
298 }
299
300 var b strings.Builder
301 var skipped bool
302 b.Grow(len(str) - escapedQuotes)
303 for _, r := range str {
304 if r == quote {
305 if !skipped {
306 skipped = true
307 continue
308 }
309 skipped = false
310 }
311 b.WriteRune(r)
312 }
313 l.emitValue(String, b.String())
314 return
315}

Callers 1

rootFunction · 0.80

Calls 5

nextMethod · 0.95
peekMethod · 0.95
errorMethod · 0.95
emitValueMethod · 0.95
StringMethod · 0.65

Tested by

no test coverage detected