-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report entity name to SDT function #85
base: master
Are you sure you want to change the base?
Changes from all commits
7a2ff8a
1f04dba
8200e9f
5fbf58b
5ae033d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,33 +91,24 @@ func (T *Token) UintValue() (uint64, error) { | |
return strconv.ParseUint(string(T.Lit), 10, 64) | ||
} | ||
|
||
var ( | ||
sdtPlaceholdersNum = regexp.MustCompile(`\$(\d+)`) | ||
sdtReplacementNum = []byte(`X[$1]`) | ||
sdtPlaceholdersAll = regexp.MustCompile(`\$\*`) | ||
sdtReplacementAll = []byte(`attribsSliceToEmpyInterfaceSlice(X)...`) | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a small comment here explaining the functionality of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there was no such explanation in the original code, so I do did not add it :) are you sure any explanation is required here? this code is completely self-explaining FMPOV |
||
func (T *Token) SDTVal() string { | ||
sdt := string(T.Lit) | ||
rex, err := regexp.Compile("\\$[0-9]+") | ||
if err != nil { | ||
panic(err) | ||
} | ||
idx := rex.FindAllStringIndex(sdt, -1) | ||
res := "" | ||
if len(idx) <= 0 { | ||
res = sdt | ||
} else { | ||
for i, loc := range idx { | ||
if loc[0] > 0 { | ||
if i > 0 { | ||
res += sdt[idx[i-1][1]:loc[0]] | ||
} else { | ||
res += sdt[0:loc[0]] | ||
} | ||
} | ||
res += "X[" | ||
res += sdt[loc[0]+1 : loc[1]] | ||
res += "]" | ||
} | ||
if idx[len(idx)-1][1] < len(sdt) { | ||
res += sdt[idx[len(idx)-1][1]:] | ||
} | ||
} | ||
res := string( | ||
sdtPlaceholdersNum.ReplaceAll( | ||
sdtPlaceholdersAll.ReplaceAll( | ||
T.Lit, | ||
sdtReplacementAll, | ||
), | ||
sdtReplacementNum, | ||
), | ||
) | ||
|
||
return strings.TrimSpace(res[2 : len(res)-2]) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure but are the variables holding compiled regular expressions required to be global ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course it is not required to be global
in the same time it might be compiled once on package init and used everywhere later