-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix pathSubs for windows: --outdir:@projectpath/foo
works cross platform, and without quoting needed
#13407
Closed
Closed
fix pathSubs for windows: --outdir:@projectpath/foo
works cross platform, and without quoting needed
#13407
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2623,69 +2623,80 @@ proc findNormalized(x: string, inArray: openArray[string]): int = | |
proc invalidFormatString() {.noinline.} = | ||
raise newException(ValueError, "invalid format string") | ||
|
||
proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {. | ||
noSideEffect, rtl, extern: "nsuAddf".} = | ||
proc addfCustom*(s: var string, formatstr: string, subs = {'$'}, a: varargs[string, `$`]) {. | ||
noSideEffect, rtl, extern: "nsuAddf2".} = | ||
## The same as ``add(s, formatstr % a)``, but more efficient. | ||
runnableExamples: | ||
var s = "start:" | ||
s.addfCustom("$foo @bar $$ @@ $", subs = {'$', '@'}, ["foo", "FOO", "bar", "BAR"]) | ||
doAssert s == "start:FOO BAR $ @ $" | ||
|
||
const PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\128'..'\255', '_'} | ||
var i = 0 | ||
var num = 0 | ||
while i < len(formatstr): | ||
if formatstr[i] == '$' and i+1 < len(formatstr): | ||
case formatstr[i+1] | ||
of '#': | ||
if num > a.high: invalidFormatString() | ||
add s, a[num] | ||
inc i, 2 | ||
inc num | ||
of '$': | ||
add s, '$' | ||
if formatstr[i] in subs and i+1 < len(formatstr): | ||
if formatstr[i+1] == formatstr[i]: | ||
add s, formatstr[i] | ||
inc(i, 2) | ||
of '1'..'9', '-': | ||
var j = 0 | ||
inc(i) # skip $ | ||
var negative = formatstr[i] == '-' | ||
if negative: inc i | ||
while i < formatstr.len and formatstr[i] in Digits: | ||
j = j * 10 + ord(formatstr[i]) - ord('0') | ||
inc(i) | ||
let idx = if not negative: j-1 else: a.len-j | ||
if idx < 0 or idx > a.high: invalidFormatString() | ||
add s, a[idx] | ||
of '{': | ||
var j = i+2 | ||
var k = 0 | ||
var negative = formatstr[j] == '-' | ||
if negative: inc j | ||
var isNumber = 0 | ||
while j < formatstr.len and formatstr[j] notin {'\0', '}'}: | ||
if formatstr[j] in Digits: | ||
k = k * 10 + ord(formatstr[j]) - ord('0') | ||
if isNumber == 0: isNumber = 1 | ||
else: | ||
isNumber = -1 | ||
inc(j) | ||
if isNumber == 1: | ||
let idx = if not negative: k-1 else: a.len-k | ||
else: | ||
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. note to reviewer: you can check the diff manually, but this is pure re-indentation below here |
||
case formatstr[i+1] | ||
of '#': | ||
if num > a.high: invalidFormatString() | ||
add s, a[num] | ||
inc i, 2 | ||
inc num | ||
of '1'..'9', '-': | ||
var j = 0 | ||
inc(i) # skip subs | ||
var negative = formatstr[i] == '-' | ||
if negative: inc i | ||
while i < formatstr.len and formatstr[i] in Digits: | ||
j = j * 10 + ord(formatstr[i]) - ord('0') | ||
inc(i) | ||
let idx = if not negative: j-1 else: a.len-j | ||
if idx < 0 or idx > a.high: invalidFormatString() | ||
add s, a[idx] | ||
else: | ||
var x = findNormalized(substr(formatstr, i+2, j-1), a) | ||
of '{': | ||
var j = i+2 | ||
var k = 0 | ||
var negative = formatstr[j] == '-' | ||
if negative: inc j | ||
var isNumber = 0 | ||
while j < formatstr.len and formatstr[j] notin {'\0', '}'}: | ||
if formatstr[j] in Digits: | ||
k = k * 10 + ord(formatstr[j]) - ord('0') | ||
if isNumber == 0: isNumber = 1 | ||
else: | ||
isNumber = -1 | ||
inc(j) | ||
if isNumber == 1: | ||
let idx = if not negative: k-1 else: a.len-k | ||
if idx < 0 or idx > a.high: invalidFormatString() | ||
add s, a[idx] | ||
else: | ||
var x = findNormalized(substr(formatstr, i+2, j-1), a) | ||
if x >= 0 and x < high(a): add s, a[x+1] | ||
else: invalidFormatString() | ||
i = j+1 | ||
of 'a'..'z', 'A'..'Z', '\128'..'\255', '_': | ||
var j = i+1 | ||
while j < formatstr.len and formatstr[j] in PatternChars: inc(j) | ||
var x = findNormalized(substr(formatstr, i+1, j-1), a) | ||
if x >= 0 and x < high(a): add s, a[x+1] | ||
else: invalidFormatString() | ||
i = j+1 | ||
of 'a'..'z', 'A'..'Z', '\128'..'\255', '_': | ||
var j = i+1 | ||
while j < formatstr.len and formatstr[j] in PatternChars: inc(j) | ||
var x = findNormalized(substr(formatstr, i+1, j-1), a) | ||
if x >= 0 and x < high(a): add s, a[x+1] | ||
else: invalidFormatString() | ||
i = j | ||
else: | ||
invalidFormatString() | ||
i = j | ||
else: | ||
invalidFormatString() | ||
else: | ||
add s, formatstr[i] | ||
inc(i) | ||
|
||
proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {. | ||
noSideEffect, rtl, extern: "nsuAddf".} = | ||
## Wrapper around `addfCustom` with subs = {'$'} | ||
addfCustom(s, formatstr, subs = {'$'}, a) | ||
|
||
proc `%` *(formatstr: string, a: openArray[string]): string {.noSideEffect, | ||
rtl, extern: "nsuFormatOpenArray".} = | ||
## Interpolates a format string with the values from `a`. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just make an addfCustom for the compiler only then...