From 1d4f9eff3d42d236b31299214ba4f6805eb33f75 Mon Sep 17 00:00:00 2001 From: Softonik Date: Tue, 13 Feb 2024 02:22:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B9:=20=D0=9F=D1=80=D0=B5=D0=BE=D0=B1=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20fmt.Sprint()=20->=20std:?= =?UTF-8?q?:to=5Fstring()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/features/app.feature | 21 +++++++++++++++++++++ pkg/service/func.go | 7 +++---- pkg/service/mapping.go | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/service/features/app.feature b/pkg/service/features/app.feature index 3eeb1b9..c37bb99 100644 --- a/pkg/service/features/app.feature +++ b/pkg/service/features/app.feature @@ -543,4 +543,25 @@ Serial.println("Connecting ..."); Serial.println("Connected!"); } void loop() {} +``` + + Сценарий: Преобразование fmt.Sprint() -> std::to_string() + * Исходник: +``` +package test + +func Setup() { + a := "" + a += fmt.Sprint(5) + a += "A " + fmt.Sprint(19) + " A " + fmt.Sprint(a) +} +``` + * Результат: +``` +void setup(); +void setup() { +std::string a=""; +a+=std::to_string(5); +a+="A "+std::to_string(19)+" A "+std::to_string(a); +} ``` diff --git a/pkg/service/func.go b/pkg/service/func.go index b553fea..af97195 100644 --- a/pkg/service/func.go +++ b/pkg/service/func.go @@ -112,16 +112,15 @@ func handleFuncDeclType(t *ast.FuncType) string { return code } -func handleFuncDeclName(ident *ast.Ident) string { - code := "" +func handleFuncDeclName(ident *ast.Ident) (code string) { if ident == nil { - return code + return } code += ident.Name if val, ok := mapping[code]; ok { code = val } - return code + return } func handleFuncDeclParams(t *ast.FuncType) string { diff --git a/pkg/service/mapping.go b/pkg/service/mapping.go index f75d08e..ba3479e 100644 --- a/pkg/service/mapping.go +++ b/pkg/service/mapping.go @@ -1,6 +1,7 @@ package service var mapping = map[string]string{ + "fmt.Sprint": "std::to_string", "digital.Low": "LOW", "digital.High": "HIGH", "digital.ModeInput": "INPUT",