Skip to content

Commit e89efb3

Browse files
committed
Treat cpp string as UTF8
Fix arduino/Arduino#5277 Signed-off-by: Cristian Maglie <[email protected]>
1 parent 03500b2 commit e89efb3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/arduino.cc/builder/utils/utils.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"path/filepath"
3939
"runtime"
4040
"strings"
41+
"unicode/utf8"
4142

4243
"arduino.cc/builder/constants"
4344
"arduino.cc/builder/gohasissues"
@@ -443,23 +444,25 @@ func ParseCppString(line string) (string, string, bool) {
443444
return "", line, false
444445
}
445446

446-
switch line[i] {
447+
c, width := utf8.DecodeRuneInString(line[i:])
448+
449+
switch c {
447450
// Backslash, next character is used unmodified
448451
case '\\':
449-
i++
452+
i += width
450453
if i >= len(line) {
451454
return "", line, false
452455
}
453456
res += string(line[i])
454457
break
455458
// Quote, end of string
456459
case '"':
457-
return res, line[i+1:], true
460+
return res, line[i+width:], true
458461
default:
459-
res += string(line[i])
462+
res += string(c)
460463
break
461464
}
462465

463-
i++
466+
i += width
464467
}
465468
}

0 commit comments

Comments
 (0)