From c81b7f6bb42efb37eee824075002eb4215e56183 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Fri, 20 Sep 2024 10:16:00 +0800 Subject: [PATCH] llcppsymg:to camel --- chore/_xtool/llcppsymg/parse/parse.go | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/chore/_xtool/llcppsymg/parse/parse.go b/chore/_xtool/llcppsymg/parse/parse.go index 88ff1b4a..31cf40f3 100644 --- a/chore/_xtool/llcppsymg/parse/parse.go +++ b/chore/_xtool/llcppsymg/parse/parse.go @@ -53,9 +53,35 @@ func (c *Context) removePrefix(str string) string { return str } -func (c *Context) genGoName(name string) string { - class := c.removePrefix(c.className) +func toTitle(s string) string { + if s == "" { + return "" + } + return strings.ToUpper(s[:1]) + strings.ToLower(s[1:]) +} + +func toCamel(originName string) string { + if originName == "" { + return "" + } + subs := strings.Split(string(originName), "_") + name := "" + for _, sub := range subs { + name += toTitle(sub) + } + return name +} + +// 1. remove prefix from config +// 2. convert to camel case +func (c *Context) toGoName(name string) string { name = c.removePrefix(name) + return toCamel(name) +} + +func (c *Context) genGoName(name string) string { + class := c.toGoName(c.className) + name = c.toGoName(name) var baseName string if class == "" {