Skip to content

Commit a3e2f29

Browse files
committed
[LOG] Fix double indirection for %% literal
Signed-off-by: Martino Facchin <[email protected]>
1 parent 68dcd24 commit a3e2f29

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/arduino.cc/builder/i18n/i18n.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
)
4242

4343
var PLACEHOLDER = regexp.MustCompile("{(\\d)}")
44+
var LITERAL_PERCENT_SIGN = "_LITERAL_PERCENT_SIGN_"
4445

4546
type Logger interface {
4647
Fprintln(w io.Writer, level string, format string, a ...interface{})
@@ -61,11 +62,15 @@ func (s NoopLogger) Name() string {
6162
type HumanLogger struct{}
6263

6364
func (s HumanLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
64-
fmt.Fprintln(w, Format(format, a...))
65+
msg := Format(format, a...)
66+
// since fmt.Fprintln will be called without vardiadic arguments, drop the second %
67+
msg = strings.Replace(msg, LITERAL_PERCENT_SIGN, "%", -1)
68+
fmt.Fprintln(w, msg)
6569
}
6670

6771
func (s HumanLogger) Println(level string, format string, a ...interface{}) {
68-
s.Fprintln(os.Stdout, level, Format(format, a...))
72+
msg := Format(format, a...)
73+
s.Fprintln(os.Stdout, level, msg)
6974
}
7075

7176
func (s HumanLogger) Name() string {
@@ -100,6 +105,7 @@ func (s MachineLogger) Name() string {
100105

101106
func FromJavaToGoSyntax(s string) string {
102107
submatches := PLACEHOLDER.FindAllStringSubmatch(s, -1)
108+
s = strings.Replace(s, "%%", LITERAL_PERCENT_SIGN, -1)
103109
for _, submatch := range submatches {
104110
idx, err := strconv.Atoi(submatch[1])
105111
if err != nil {

0 commit comments

Comments
 (0)