MCPcopy Index your code
hub / github.com/dop251/goja / WriteSubstring

Method WriteSubstring

string_unicode.go:311–341  ·  view source on GitHub ↗
(source String, start int, end int)

Source from the content-addressed store, hash-verified

309}
310
311func (b *StringBuilder) WriteSubstring(source String, start int, end int) {
312 a, us := devirtualizeString(source)
313 if us == nil {
314 if b.ascii() {
315 b.asciiBuilder.WriteString(string(a[start:end]))
316 } else {
317 b.unicodeBuilder.writeASCIIString(string(a[start:end]))
318 }
319 return
320 }
321 if b.ascii() {
322 uc := false
323 for i := start; i < end; i++ {
324 if us.CharAt(i) >= utf8.RuneSelf {
325 uc = true
326 break
327 }
328 }
329 if uc {
330 b.switchToUnicode(end - start + 1)
331 } else {
332 b.asciiBuilder.Grow(end - start + 1)
333 for i := start; i < end; i++ {
334 b.asciiBuilder.WriteByte(byte(us.CharAt(i)))
335 }
336 return
337 }
338 }
339 b.unicodeBuilder.buf = append(b.unicodeBuilder.buf, us[start+1:end+1]...)
340 b.unicodeBuilder.unicode = true
341}
342
343func (s unicodeString) Reader() io.RuneReader {
344 return &unicodeRuneReader{

Callers 3

TestValueStringBuilderFunction · 0.95
stringReplaceMethod · 0.95
writeEscapedSourceMethod · 0.80

Calls 7

asciiMethod · 0.95
switchToUnicodeMethod · 0.95
devirtualizeStringFunction · 0.85
WriteStringMethod · 0.80
writeASCIIStringMethod · 0.80
CharAtMethod · 0.65
GrowMethod · 0.45

Tested by 1

TestValueStringBuilderFunction · 0.76