Merge pull request #2260 from oderwat/upd-deprecated-repeats
Updates to remove deprecated repeatStr() and repeatChar() from all files.
This commit is contained in:
commit
1ca2db0273
27 changed files with 73 additions and 73 deletions
|
|
@ -203,9 +203,9 @@ proc mustRehash(length, counter: int): bool =
|
||||||
assert(length > counter)
|
assert(length > counter)
|
||||||
result = (length * 2 < counter * 3) or (length - counter < 4)
|
result = (length * 2 < counter * 3) or (length - counter < 4)
|
||||||
|
|
||||||
proc spaces(x: int): PRope =
|
proc rspaces(x: int): PRope =
|
||||||
# returns x spaces
|
# returns x spaces
|
||||||
result = toRope(repeatChar(x))
|
result = toRope(spaces(x))
|
||||||
|
|
||||||
proc toYamlChar(c: char): string =
|
proc toYamlChar(c: char): string =
|
||||||
case c
|
case c
|
||||||
|
|
@ -253,7 +253,7 @@ proc typeToYamlAux(n: PType, marker: var IntSet,
|
||||||
indent, maxRecDepth: int): PRope
|
indent, maxRecDepth: int): PRope
|
||||||
proc strTableToYaml(n: TStrTable, marker: var IntSet, indent: int,
|
proc strTableToYaml(n: TStrTable, marker: var IntSet, indent: int,
|
||||||
maxRecDepth: int): PRope =
|
maxRecDepth: int): PRope =
|
||||||
var istr = spaces(indent + 2)
|
var istr = rspaces(indent + 2)
|
||||||
result = toRope("[")
|
result = toRope("[")
|
||||||
var mycount = 0
|
var mycount = 0
|
||||||
for i in countup(0, high(n.data)):
|
for i in countup(0, high(n.data)):
|
||||||
|
|
@ -262,20 +262,20 @@ proc strTableToYaml(n: TStrTable, marker: var IntSet, indent: int,
|
||||||
appf(result, "$N$1$2",
|
appf(result, "$N$1$2",
|
||||||
[istr, symToYamlAux(n.data[i], marker, indent + 2, maxRecDepth - 1)])
|
[istr, symToYamlAux(n.data[i], marker, indent + 2, maxRecDepth - 1)])
|
||||||
inc(mycount)
|
inc(mycount)
|
||||||
if mycount > 0: appf(result, "$N$1", [spaces(indent)])
|
if mycount > 0: appf(result, "$N$1", [rspaces(indent)])
|
||||||
app(result, "]")
|
app(result, "]")
|
||||||
assert(mycount == n.counter)
|
assert(mycount == n.counter)
|
||||||
|
|
||||||
proc ropeConstr(indent: int, c: openArray[PRope]): PRope =
|
proc ropeConstr(indent: int, c: openArray[PRope]): PRope =
|
||||||
# array of (name, value) pairs
|
# array of (name, value) pairs
|
||||||
var istr = spaces(indent + 2)
|
var istr = rspaces(indent + 2)
|
||||||
result = toRope("{")
|
result = toRope("{")
|
||||||
var i = 0
|
var i = 0
|
||||||
while i <= high(c):
|
while i <= high(c):
|
||||||
if i > 0: app(result, ",")
|
if i > 0: app(result, ",")
|
||||||
appf(result, "$N$1\"$2\": $3", [istr, c[i], c[i + 1]])
|
appf(result, "$N$1\"$2\": $3", [istr, c[i], c[i + 1]])
|
||||||
inc(i, 2)
|
inc(i, 2)
|
||||||
appf(result, "$N$1}", [spaces(indent)])
|
appf(result, "$N$1}", [rspaces(indent)])
|
||||||
|
|
||||||
proc symToYamlAux(n: PSym, marker: var IntSet, indent: int,
|
proc symToYamlAux(n: PSym, marker: var IntSet, indent: int,
|
||||||
maxRecDepth: int): PRope =
|
maxRecDepth: int): PRope =
|
||||||
|
|
@ -310,9 +310,9 @@ proc typeToYamlAux(n: PType, marker: var IntSet, indent: int,
|
||||||
result = toRope("[")
|
result = toRope("[")
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: app(result, ",")
|
if i > 0: app(result, ",")
|
||||||
appf(result, "$N$1$2", [spaces(indent + 4), typeToYamlAux(n.sons[i],
|
appf(result, "$N$1$2", [rspaces(indent + 4), typeToYamlAux(n.sons[i],
|
||||||
marker, indent + 4, maxRecDepth - 1)])
|
marker, indent + 4, maxRecDepth - 1)])
|
||||||
appf(result, "$N$1]", [spaces(indent + 2)])
|
appf(result, "$N$1]", [rspaces(indent + 2)])
|
||||||
else:
|
else:
|
||||||
result = toRope("null")
|
result = toRope("null")
|
||||||
result = ropeConstr(indent, [toRope("kind"),
|
result = ropeConstr(indent, [toRope("kind"),
|
||||||
|
|
@ -331,7 +331,7 @@ proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = toRope("null")
|
result = toRope("null")
|
||||||
else:
|
else:
|
||||||
var istr = spaces(indent + 2)
|
var istr = rspaces(indent + 2)
|
||||||
result = ropef("{$N$1\"kind\": $2", [istr, makeYamlString($n.kind)])
|
result = ropef("{$N$1\"kind\": $2", [istr, makeYamlString($n.kind)])
|
||||||
if maxRecDepth != 0:
|
if maxRecDepth != 0:
|
||||||
appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
|
appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
|
||||||
|
|
@ -359,12 +359,12 @@ proc treeToYamlAux(n: PNode, marker: var IntSet, indent: int,
|
||||||
appf(result, ",$N$1\"sons\": [", [istr])
|
appf(result, ",$N$1\"sons\": [", [istr])
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: app(result, ",")
|
if i > 0: app(result, ",")
|
||||||
appf(result, "$N$1$2", [spaces(indent + 4), treeToYamlAux(n.sons[i],
|
appf(result, "$N$1$2", [rspaces(indent + 4), treeToYamlAux(n.sons[i],
|
||||||
marker, indent + 4, maxRecDepth - 1)])
|
marker, indent + 4, maxRecDepth - 1)])
|
||||||
appf(result, "$N$1]", [istr])
|
appf(result, "$N$1]", [istr])
|
||||||
appf(result, ",$N$1\"typ\": $2",
|
appf(result, ",$N$1\"typ\": $2",
|
||||||
[istr, typeToYamlAux(n.typ, marker, indent + 2, maxRecDepth)])
|
[istr, typeToYamlAux(n.typ, marker, indent + 2, maxRecDepth)])
|
||||||
appf(result, "$N$1}", [spaces(indent)])
|
appf(result, "$N$1}", [rspaces(indent)])
|
||||||
|
|
||||||
proc treeToYaml(n: PNode, indent: int = 0, maxRecDepth: int = - 1): PRope =
|
proc treeToYaml(n: PNode, indent: int = 0, maxRecDepth: int = - 1): PRope =
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
|
|
@ -408,7 +408,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = toRope("null")
|
result = toRope("null")
|
||||||
else:
|
else:
|
||||||
var istr = spaces(indent + 2)
|
var istr = rspaces(indent + 2)
|
||||||
result = ropef("{$N$1\"kind\": $2",
|
result = ropef("{$N$1\"kind\": $2",
|
||||||
[istr, makeYamlString($n.kind)])
|
[istr, makeYamlString($n.kind)])
|
||||||
if maxRecDepth != 0:
|
if maxRecDepth != 0:
|
||||||
|
|
@ -440,11 +440,11 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
|
||||||
appf(result, ",$N$1\"sons\": [", [istr])
|
appf(result, ",$N$1\"sons\": [", [istr])
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
if i > 0: app(result, ",")
|
if i > 0: app(result, ",")
|
||||||
appf(result, "$N$1$2", [spaces(indent + 4), debugTree(n.sons[i],
|
appf(result, "$N$1$2", [rspaces(indent + 4), debugTree(n.sons[i],
|
||||||
indent + 4, maxRecDepth - 1, renderType)])
|
indent + 4, maxRecDepth - 1, renderType)])
|
||||||
appf(result, "$N$1]", [istr])
|
appf(result, "$N$1]", [istr])
|
||||||
appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
|
appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
|
||||||
appf(result, "$N$1}", [spaces(indent)])
|
appf(result, "$N$1}", [rspaces(indent)])
|
||||||
|
|
||||||
proc debug(n: PSym) =
|
proc debug(n: PSym) =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
|
|
|
||||||
|
|
@ -949,7 +949,7 @@ proc genEcho(p: BProc, n: PNode) =
|
||||||
initLocExpr(p, n.sons[i], a)
|
initLocExpr(p, n.sons[i], a)
|
||||||
appf(args, ", $1? ($1)->data:\"nil\"", [rdLoc(a)])
|
appf(args, ", $1? ($1)->data:\"nil\"", [rdLoc(a)])
|
||||||
linefmt(p, cpsStmts, "printf($1$2);$n",
|
linefmt(p, cpsStmts, "printf($1$2);$n",
|
||||||
makeCString(repeatStr(n.len, "%s") & tnl), args)
|
makeCString(repeat("%s", n.len) & tnl), args)
|
||||||
|
|
||||||
proc gcUsage(n: PNode) =
|
proc gcUsage(n: PNode) =
|
||||||
if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree)
|
if gSelectedGC == gcNone: message(n.info, warnGcMem, n.renderTree)
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,11 @@ const
|
||||||
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '.', '_'}
|
PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '.', '_'}
|
||||||
|
|
||||||
proc newLine(p: var TTmplParser) =
|
proc newLine(p: var TTmplParser) =
|
||||||
llStreamWrite(p.outp, repeatChar(p.emitPar, ')'))
|
llStreamWrite(p.outp, repeat(')', p.emitPar))
|
||||||
p.emitPar = 0
|
p.emitPar = 0
|
||||||
if p.info.line > int16(1): llStreamWrite(p.outp, "\n")
|
if p.info.line > int16(1): llStreamWrite(p.outp, "\n")
|
||||||
if p.pendingExprLine:
|
if p.pendingExprLine:
|
||||||
llStreamWrite(p.outp, repeatChar(2))
|
llStreamWrite(p.outp, spaces(2))
|
||||||
p.pendingExprLine = false
|
p.pendingExprLine = false
|
||||||
|
|
||||||
proc scanPar(p: var TTmplParser, d: int) =
|
proc scanPar(p: var TTmplParser, d: int) =
|
||||||
|
|
@ -88,24 +88,24 @@ proc parseLine(p: var TTmplParser) =
|
||||||
else:
|
else:
|
||||||
p.info.col = int16(j)
|
p.info.col = int16(j)
|
||||||
localError(p.info, errXNotAllowedHere, "end")
|
localError(p.info, errXNotAllowedHere, "end")
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent))
|
llStreamWrite(p.outp, spaces(p.indent))
|
||||||
llStreamWrite(p.outp, "#end")
|
llStreamWrite(p.outp, "#end")
|
||||||
of wIf, wWhen, wTry, wWhile, wFor, wBlock, wCase, wProc, wIterator,
|
of wIf, wWhen, wTry, wWhile, wFor, wBlock, wCase, wProc, wIterator,
|
||||||
wConverter, wMacro, wTemplate, wMethod:
|
wConverter, wMacro, wTemplate, wMethod:
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent))
|
llStreamWrite(p.outp, spaces(p.indent))
|
||||||
llStreamWrite(p.outp, substr(p.x, d))
|
llStreamWrite(p.outp, substr(p.x, d))
|
||||||
inc(p.indent, 2)
|
inc(p.indent, 2)
|
||||||
of wElif, wOf, wElse, wExcept, wFinally:
|
of wElif, wOf, wElse, wExcept, wFinally:
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent - 2))
|
llStreamWrite(p.outp, spaces(p.indent - 2))
|
||||||
llStreamWrite(p.outp, substr(p.x, d))
|
llStreamWrite(p.outp, substr(p.x, d))
|
||||||
of wLet, wVar, wConst, wType:
|
of wLet, wVar, wConst, wType:
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent))
|
llStreamWrite(p.outp, spaces(p.indent))
|
||||||
llStreamWrite(p.outp, substr(p.x, d))
|
llStreamWrite(p.outp, substr(p.x, d))
|
||||||
if not p.x.contains({':', '='}):
|
if not p.x.contains({':', '='}):
|
||||||
# no inline element --> treat as block:
|
# no inline element --> treat as block:
|
||||||
inc(p.indent, 2)
|
inc(p.indent, 2)
|
||||||
else:
|
else:
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent))
|
llStreamWrite(p.outp, spaces(p.indent))
|
||||||
llStreamWrite(p.outp, substr(p.x, d))
|
llStreamWrite(p.outp, substr(p.x, d))
|
||||||
p.state = psDirective
|
p.state = psDirective
|
||||||
else:
|
else:
|
||||||
|
|
@ -120,11 +120,11 @@ proc parseLine(p: var TTmplParser) =
|
||||||
# next line of string literal:
|
# next line of string literal:
|
||||||
llStreamWrite(p.outp, p.conc)
|
llStreamWrite(p.outp, p.conc)
|
||||||
llStreamWrite(p.outp, "\n")
|
llStreamWrite(p.outp, "\n")
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent + 2))
|
llStreamWrite(p.outp, spaces(p.indent + 2))
|
||||||
llStreamWrite(p.outp, "\"")
|
llStreamWrite(p.outp, "\"")
|
||||||
of psDirective:
|
of psDirective:
|
||||||
newLine(p)
|
newLine(p)
|
||||||
llStreamWrite(p.outp, repeatChar(p.indent))
|
llStreamWrite(p.outp, spaces(p.indent))
|
||||||
llStreamWrite(p.outp, p.emit)
|
llStreamWrite(p.outp, p.emit)
|
||||||
llStreamWrite(p.outp, "(\"")
|
llStreamWrite(p.outp, "(\"")
|
||||||
inc(p.emitPar)
|
inc(p.emitPar)
|
||||||
|
|
|
||||||
|
|
@ -780,7 +780,7 @@ proc genIf(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
moveInto(p, stmt, r)
|
moveInto(p, stmt, r)
|
||||||
appf(p.body, "}$n" | "end$n")
|
appf(p.body, "}$n" | "end$n")
|
||||||
if p.target == targetJS:
|
if p.target == targetJS:
|
||||||
app(p.body, repeatChar(toClose, '}') & tnl)
|
app(p.body, repeat('}', toClose) & tnl)
|
||||||
else:
|
else:
|
||||||
for i in 1..toClose: appf(p.body, "end$n")
|
for i in 1..toClose: appf(p.body, "end$n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -784,7 +784,7 @@ proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
proc writeSurroundingSrc(info: TLineInfo) =
|
proc writeSurroundingSrc(info: TLineInfo) =
|
||||||
const indent = " "
|
const indent = " "
|
||||||
msgWriteln(indent & info.sourceLine.ropeToStr)
|
msgWriteln(indent & info.sourceLine.ropeToStr)
|
||||||
msgWriteln(indent & repeatChar(info.col, ' ') & '^')
|
msgWriteln(indent & spaces(info.col) & '^')
|
||||||
|
|
||||||
proc formatMsg*(info: TLineInfo, msg: TMsgKind, arg: string): string =
|
proc formatMsg*(info: TLineInfo, msg: TMsgKind, arg: string): string =
|
||||||
let frmt = case msg
|
let frmt = case msg
|
||||||
|
|
|
||||||
|
|
@ -166,4 +166,4 @@ proc getCurrentLine(L: TBaseLexer, marker: bool = true): string =
|
||||||
inc(i)
|
inc(i)
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
if marker:
|
if marker:
|
||||||
result.add(repeatChar(getColNumber(L, L.bufpos)) & '^' & "\n")
|
result.add(spaces(getColNumber(L, L.bufpos)) & '^' & "\n")
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ proc addTok(g: var TSrcGen, kind: TTokType, s: string) =
|
||||||
|
|
||||||
proc addPendingNL(g: var TSrcGen) =
|
proc addPendingNL(g: var TSrcGen) =
|
||||||
if g.pendingNL >= 0:
|
if g.pendingNL >= 0:
|
||||||
addTok(g, tkSpaces, "\n" & repeatChar(g.pendingNL))
|
addTok(g, tkSpaces, "\n" & spaces(g.pendingNL))
|
||||||
g.lineLen = g.pendingNL
|
g.lineLen = g.pendingNL
|
||||||
g.pendingNL = - 1
|
g.pendingNL = - 1
|
||||||
|
|
||||||
|
|
@ -190,7 +190,7 @@ proc putComment(g: var TSrcGen, s: string) =
|
||||||
if not isCode and (g.lineLen + (j - i) > MaxLineLen):
|
if not isCode and (g.lineLen + (j - i) > MaxLineLen):
|
||||||
put(g, tkComment, com)
|
put(g, tkComment, com)
|
||||||
optNL(g, ind)
|
optNL(g, ind)
|
||||||
com = '#' & repeatChar(comIndent)
|
com = '#' & spaces(comIndent)
|
||||||
while s[i] > ' ':
|
while s[i] > ' ':
|
||||||
add(com, s[i])
|
add(com, s[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
@ -280,7 +280,7 @@ proc gcom(g: var TSrcGen, n: PNode) =
|
||||||
(g.lineLen < LineCommentColumn):
|
(g.lineLen < LineCommentColumn):
|
||||||
var ml = maxLineLength(n.comment)
|
var ml = maxLineLength(n.comment)
|
||||||
if ml + LineCommentColumn <= MaxLineLen:
|
if ml + LineCommentColumn <= MaxLineLen:
|
||||||
put(g, tkSpaces, repeatChar(LineCommentColumn - g.lineLen))
|
put(g, tkSpaces, spaces(LineCommentColumn - g.lineLen))
|
||||||
putComment(g, n.comment) #assert(g.comStack[high(g.comStack)] = n);
|
putComment(g, n.comment) #assert(g.comStack[high(g.comStack)] = n);
|
||||||
|
|
||||||
proc gcoms(g: var TSrcGen) =
|
proc gcoms(g: var TSrcGen) =
|
||||||
|
|
|
||||||
2
koch.nim
2
koch.nim
|
|
@ -347,7 +347,7 @@ proc temp(args: string) =
|
||||||
if args.len > 0: exec(finalDest & " " & args)
|
if args.len > 0: exec(finalDest & " " & args)
|
||||||
|
|
||||||
proc showHelp() =
|
proc showHelp() =
|
||||||
quit(HelpText % [VersionAsString & repeatChar(44-len(VersionAsString)),
|
quit(HelpText % [VersionAsString & spaces(44-len(VersionAsString)),
|
||||||
CompileDate, CompileTime], QuitSuccess)
|
CompileDate, CompileTime], QuitSuccess)
|
||||||
|
|
||||||
var op = initOptParser()
|
var op = initOptParser()
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ proc rawCompile(pattern: string, flags: cint): PPcre =
|
||||||
offset: cint
|
offset: cint
|
||||||
result = pcre.compile(pattern, flags, addr(msg), addr(offset), nil)
|
result = pcre.compile(pattern, flags, addr(msg), addr(offset), nil)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
raiseInvalidRegex($msg & "\n" & pattern & "\n" & repeatChar(offset) & "^\n")
|
raiseInvalidRegex($msg & "\n" & pattern & "\n" & spaces(offset) & "^\n")
|
||||||
|
|
||||||
proc finalizeRegEx(x: Regex) =
|
proc finalizeRegEx(x: Regex) =
|
||||||
# XXX This is a hack, but PCRE does not export its "free" function properly.
|
# XXX This is a hack, but PCRE does not export its "free" function properly.
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ proc getIndent(L: var TLexer, tok: var TToken) =
|
||||||
tok.line = L.line
|
tok.line = L.line
|
||||||
L.col = tok.ival
|
L.col = tok.ival
|
||||||
tok.ival = max(tok.ival - L.baseIndent, 0)
|
tok.ival = max(tok.ival - L.baseIndent, 0)
|
||||||
tok.symbol = "\n" & repeatChar(tok.ival)
|
tok.symbol = "\n" & spaces(tok.ival)
|
||||||
|
|
||||||
proc rawGetTok(L: var TLexer, tok: var TToken) =
|
proc rawGetTok(L: var TLexer, tok: var TToken) =
|
||||||
tok.symbol = ""
|
tok.symbol = ""
|
||||||
|
|
@ -963,7 +963,7 @@ proc parseLiteralBlock(p: var TRstParser): PRstNode =
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
add(n.text, "\n")
|
add(n.text, "\n")
|
||||||
add(n.text, repeatChar(p.tok[p.idx].ival - indent))
|
add(n.text, spaces(p.tok[p.idx].ival - indent))
|
||||||
inc(p.idx)
|
inc(p.idx)
|
||||||
else:
|
else:
|
||||||
add(n.text, p.tok[p.idx].symbol)
|
add(n.text, p.tok[p.idx].symbol)
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ proc renderRstToRst(d: var TRenderContext, n: PRstNode, result: var string) =
|
||||||
const
|
const
|
||||||
lvlToChar: array[0..8, char] = ['!', '=', '-', '~', '`', '<', '*', '|', '+']
|
lvlToChar: array[0..8, char] = ['!', '=', '-', '~', '`', '<', '*', '|', '+']
|
||||||
if n == nil: return
|
if n == nil: return
|
||||||
var ind = repeatChar(d.indent)
|
var ind = spaces(d.indent)
|
||||||
case n.kind
|
case n.kind
|
||||||
of rnInner:
|
of rnInner:
|
||||||
renderRstSons(d, n, result)
|
renderRstSons(d, n, result)
|
||||||
|
|
@ -124,7 +124,7 @@ proc renderRstToRst(d: var TRenderContext, n: PRstNode, result: var string) =
|
||||||
|
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
result.add(ind)
|
result.add(ind)
|
||||||
result.add repeatChar(headlineLen, lvlToChar[n.level])
|
result.add repeat(lvlToChar[n.level], headlineLen)
|
||||||
of rnOverline:
|
of rnOverline:
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
result.add(ind)
|
result.add(ind)
|
||||||
|
|
@ -132,7 +132,7 @@ proc renderRstToRst(d: var TRenderContext, n: PRstNode, result: var string) =
|
||||||
var headline = ""
|
var headline = ""
|
||||||
renderRstSons(d, n, headline)
|
renderRstSons(d, n, headline)
|
||||||
|
|
||||||
let lvl = repeatChar(headline.len - d.indent, lvlToChar[n.level])
|
let lvl = repeat(lvlToChar[n.level], headline.len - d.indent)
|
||||||
result.add(lvl)
|
result.add(lvl)
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
result.add(headline)
|
result.add(headline)
|
||||||
|
|
@ -143,7 +143,7 @@ proc renderRstToRst(d: var TRenderContext, n: PRstNode, result: var string) =
|
||||||
of rnTransition:
|
of rnTransition:
|
||||||
result.add("\n\n")
|
result.add("\n\n")
|
||||||
result.add(ind)
|
result.add(ind)
|
||||||
result.add repeatChar(78-d.indent, '-')
|
result.add repeat('-', 78-d.indent)
|
||||||
result.add("\n\n")
|
result.add("\n\n")
|
||||||
of rnParagraph:
|
of rnParagraph:
|
||||||
result.add("\n\n")
|
result.add("\n\n")
|
||||||
|
|
@ -196,7 +196,7 @@ proc renderRstToRst(d: var TRenderContext, n: PRstNode, result: var string) =
|
||||||
result.add ':'
|
result.add ':'
|
||||||
result.add tmp
|
result.add tmp
|
||||||
result.add ':'
|
result.add ':'
|
||||||
result.add repeatChar(L - tmp.len - 2)
|
result.add spaces(L - tmp.len - 2)
|
||||||
renderRstToRst(d, n.sons[1], result)
|
renderRstToRst(d, n.sons[1], result)
|
||||||
|
|
||||||
dec(d.indent, L)
|
dec(d.indent, L)
|
||||||
|
|
|
||||||
|
|
@ -461,9 +461,9 @@ proc indentToLevel(level: var int, newLevel: int): string =
|
||||||
if level == newLevel:
|
if level == newLevel:
|
||||||
return
|
return
|
||||||
if newLevel > level:
|
if newLevel > level:
|
||||||
result = repeatStr(newLevel - level, "<ul>")
|
result = repeat("<ul>", newLevel - level)
|
||||||
else:
|
else:
|
||||||
result = repeatStr(level - newLevel, "</ul>")
|
result = repeat("</ul>", level - newLevel)
|
||||||
level = newLevel
|
level = newLevel
|
||||||
|
|
||||||
proc generateDocumentationTOC(entries: seq[TIndexEntry]): string =
|
proc generateDocumentationTOC(entries: seq[TIndexEntry]): string =
|
||||||
|
|
@ -701,7 +701,7 @@ proc renderHeadline(d: PDoc, n: PRstNode, result: var string) =
|
||||||
# Generate index entry using spaces to indicate TOC level for the output HTML.
|
# Generate index entry using spaces to indicate TOC level for the output HTML.
|
||||||
assert n.level >= 0
|
assert n.level >= 0
|
||||||
setIndexTerm(d, refname, tmp.stripTOCHTML,
|
setIndexTerm(d, refname, tmp.stripTOCHTML,
|
||||||
repeatChar(max(0, n.level), ' ') & tmp)
|
spaces(max(0, n.level)) & tmp)
|
||||||
|
|
||||||
proc renderOverline(d: PDoc, n: PRstNode, result: var string) =
|
proc renderOverline(d: PDoc, n: PRstNode, result: var string) =
|
||||||
if d.meta[metaTitle].len == 0:
|
if d.meta[metaTitle].len == 0:
|
||||||
|
|
|
||||||
|
|
@ -816,7 +816,7 @@ proc copy*(p: JsonNode): JsonNode =
|
||||||
# ------------- pretty printing ----------------------------------------------
|
# ------------- pretty printing ----------------------------------------------
|
||||||
|
|
||||||
proc indent(s: var string, i: int) =
|
proc indent(s: var string, i: int) =
|
||||||
s.add(repeatChar(i))
|
s.add(spaces(i))
|
||||||
|
|
||||||
proc newIndent(curr, indent: int, ml: bool): int =
|
proc newIndent(curr, indent: int, ml: bool): int =
|
||||||
if ml: return curr + indent
|
if ml: return curr + indent
|
||||||
|
|
|
||||||
|
|
@ -165,5 +165,5 @@ proc getCurrentLine(L: BaseLexer, marker: bool = true): string =
|
||||||
inc(i)
|
inc(i)
|
||||||
add(result, "\n")
|
add(result, "\n")
|
||||||
if marker:
|
if marker:
|
||||||
add(result, repeatChar(getColNumber(L, L.bufpos)) & "^\n")
|
add(result, spaces(getColNumber(L, L.bufpos)) & "^\n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -628,25 +628,25 @@ proc formatToken(info: TimeInfo, token: string, buf: var string) =
|
||||||
var fr = ($info.year).len()-2
|
var fr = ($info.year).len()-2
|
||||||
if fr < 0: fr = 0
|
if fr < 0: fr = 0
|
||||||
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
||||||
if fyear.len != 2: fyear = repeatChar(2-fyear.len(), '0') & fyear
|
if fyear.len != 2: fyear = repeat('0', 2-fyear.len()) & fyear
|
||||||
buf.add(fyear)
|
buf.add(fyear)
|
||||||
of "yyy":
|
of "yyy":
|
||||||
var fr = ($info.year).len()-3
|
var fr = ($info.year).len()-3
|
||||||
if fr < 0: fr = 0
|
if fr < 0: fr = 0
|
||||||
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
||||||
if fyear.len != 3: fyear = repeatChar(3-fyear.len(), '0') & fyear
|
if fyear.len != 3: fyear = repeat('0', 3-fyear.len()) & fyear
|
||||||
buf.add(fyear)
|
buf.add(fyear)
|
||||||
of "yyyy":
|
of "yyyy":
|
||||||
var fr = ($info.year).len()-4
|
var fr = ($info.year).len()-4
|
||||||
if fr < 0: fr = 0
|
if fr < 0: fr = 0
|
||||||
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
||||||
if fyear.len != 4: fyear = repeatChar(4-fyear.len(), '0') & fyear
|
if fyear.len != 4: fyear = repeat('0', 4-fyear.len()) & fyear
|
||||||
buf.add(fyear)
|
buf.add(fyear)
|
||||||
of "yyyyy":
|
of "yyyyy":
|
||||||
var fr = ($info.year).len()-5
|
var fr = ($info.year).len()-5
|
||||||
if fr < 0: fr = 0
|
if fr < 0: fr = 0
|
||||||
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
var fyear = ($info.year)[fr .. ($info.year).len()-1]
|
||||||
if fyear.len != 5: fyear = repeatChar(5-fyear.len(), '0') & fyear
|
if fyear.len != 5: fyear = repeat('0', 5-fyear.len()) & fyear
|
||||||
buf.add(fyear)
|
buf.add(fyear)
|
||||||
of "z":
|
of "z":
|
||||||
let hrs = (info.timezone div 60) div 60
|
let hrs = (info.timezone div 60) div 60
|
||||||
|
|
|
||||||
|
|
@ -1083,7 +1083,7 @@ proc addEscaped(s: string): string =
|
||||||
else: result.add(c)
|
else: result.add(c)
|
||||||
|
|
||||||
proc nodeToXml(n: PNode, indent: int = 0): string =
|
proc nodeToXml(n: PNode, indent: int = 0): string =
|
||||||
result = repeatChar(indent, ' ') & "<" & n.nodeName
|
result = spaces(indent) & "<" & n.nodeName
|
||||||
if not isNil(n.attributes):
|
if not isNil(n.attributes):
|
||||||
for i in items(n.attributes):
|
for i in items(n.attributes):
|
||||||
result.add(" " & i.name & "=\"" & addEscaped(i.value) & "\"")
|
result.add(" " & i.name & "=\"" & addEscaped(i.value) & "\"")
|
||||||
|
|
@ -1098,23 +1098,23 @@ proc nodeToXml(n: PNode, indent: int = 0): string =
|
||||||
of ElementNode:
|
of ElementNode:
|
||||||
result.add(nodeToXml(i, indent + 2))
|
result.add(nodeToXml(i, indent + 2))
|
||||||
of TextNode:
|
of TextNode:
|
||||||
result.add(repeatChar(indent * 2, ' '))
|
result.add(spaces(indent * 2))
|
||||||
result.add(addEscaped(i.nodeValue))
|
result.add(addEscaped(i.nodeValue))
|
||||||
of CDataSectionNode:
|
of CDataSectionNode:
|
||||||
result.add(repeatChar(indent * 2, ' '))
|
result.add(spaces(indent * 2))
|
||||||
result.add("<![CDATA[" & i.nodeValue & "]]>")
|
result.add("<![CDATA[" & i.nodeValue & "]]>")
|
||||||
of ProcessingInstructionNode:
|
of ProcessingInstructionNode:
|
||||||
result.add(repeatChar(indent * 2, ' '))
|
result.add(spaces(indent * 2))
|
||||||
result.add("<?" & PProcessingInstruction(i).target & " " &
|
result.add("<?" & PProcessingInstruction(i).target & " " &
|
||||||
PProcessingInstruction(i).data & " ?>")
|
PProcessingInstruction(i).data & " ?>")
|
||||||
of CommentNode:
|
of CommentNode:
|
||||||
result.add(repeatChar(indent * 2, ' '))
|
result.add(spaces(indent * 2))
|
||||||
result.add("<!-- " & i.nodeValue & " -->")
|
result.add("<!-- " & i.nodeValue & " -->")
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
result.add("\n")
|
result.add("\n")
|
||||||
# Add the ending tag - </tag>
|
# Add the ending tag - </tag>
|
||||||
result.add(repeatChar(indent, ' ') & "</" & n.nodeName & ">")
|
result.add(spaces(indent) & "</" & n.nodeName & ">")
|
||||||
|
|
||||||
proc `$`*(doc: PDocument): string =
|
proc `$`*(doc: PDocument): string =
|
||||||
## Converts a PDocument object into a string representation of it's XML
|
## Converts a PDocument object into a string representation of it's XML
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ proc traceTree[T,D](root: PNode[T,D]) =
|
||||||
write stdout, space
|
write stdout, space
|
||||||
|
|
||||||
proc doTrace(n: PNode[T,D], level: int) =
|
proc doTrace(n: PNode[T,D], level: int) =
|
||||||
var space = repeatChar(2 * level)
|
var space = spaces(2 * level)
|
||||||
traceln(space)
|
traceln(space)
|
||||||
write stdout, "node: "
|
write stdout, "node: "
|
||||||
if n == nil:
|
if n == nil:
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ proc build_help*(expected: seq[Tparameter_specification] = @[],
|
||||||
let width = prefixes.map(proc (x: string): int = 3 + len(x)).max
|
let width = prefixes.map(proc (x: string): int = 3 + len(x)).max
|
||||||
|
|
||||||
for line in zip(prefixes, helps):
|
for line in zip(prefixes, helps):
|
||||||
result.add(line.a & repeatChar(width - line.a.len) & line.b)
|
result.add(line.a & spaces(width - line.a.len) & line.b)
|
||||||
|
|
||||||
|
|
||||||
proc echo_help*(expected: seq[Tparameter_specification] = @[],
|
proc echo_help*(expected: seq[Tparameter_specification] = @[],
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import streams
|
import streams
|
||||||
from strutils import repeatChar
|
from strutils import repeat
|
||||||
|
|
||||||
proc readPaddedStr*(s: PStream, length: int, padChar = '\0'): TaintedString =
|
proc readPaddedStr*(s: PStream, length: int, padChar = '\0'): TaintedString =
|
||||||
var lastChr = length
|
var lastChr = length
|
||||||
|
|
@ -10,7 +10,7 @@ proc readPaddedStr*(s: PStream, length: int, padChar = '\0'): TaintedString =
|
||||||
proc writePaddedStr*(s: PStream, str: string, length: int, padChar = '\0') =
|
proc writePaddedStr*(s: PStream, str: string, length: int, padChar = '\0') =
|
||||||
if str.len < length:
|
if str.len < length:
|
||||||
s.write(str)
|
s.write(str)
|
||||||
s.write(repeatChar(length - str.len, padChar))
|
s.write(repeat(padChar, length - str.len))
|
||||||
elif str.len > length:
|
elif str.len > length:
|
||||||
s.write(str.substr(0, length - 1))
|
s.write(str.substr(0, length - 1))
|
||||||
else:
|
else:
|
||||||
|
|
@ -37,7 +37,7 @@ when isMainModule:
|
||||||
testStream.setPosition 0
|
testStream.setPosition 0
|
||||||
testStream.writePaddedStr("Sup", 10)
|
testStream.writePaddedStr("Sup", 10)
|
||||||
echo(repr(testStream), testStream.data.len)
|
echo(repr(testStream), testStream.data.len)
|
||||||
doAssert testStream.data == "Sup"&repeatChar(7, '\0')
|
doAssert testStream.data == "Sup"&repeat('\0', 7)
|
||||||
|
|
||||||
testStream.setPosition 0
|
testStream.setPosition 0
|
||||||
res = testStream.readPaddedStr(10)
|
res = testStream.readPaddedStr(10)
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ when isMainModule:
|
||||||
discard """block:
|
discard """block:
|
||||||
var
|
var
|
||||||
TestFile: FileChallengePair
|
TestFile: FileChallengePair
|
||||||
contents = repeatStr(2, "abcdefghijklmnopqrstuvwxyz")
|
contents = repeat("abcdefghijklmnopqrstuvwxyz", 2)
|
||||||
testFile.challenge = newScFileChallenge("foobar.test", FZoneCfg, contents.len.int32)
|
testFile.challenge = newScFileChallenge("foobar.test", FZoneCfg, contents.len.int32)
|
||||||
testFile.file = checksumStr(contents)
|
testFile.file = checksumStr(contents)
|
||||||
myAssets.add testFile"""
|
myAssets.add testFile"""
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ when defined(recordMode):
|
||||||
isRecording = false
|
isRecording = false
|
||||||
proc zeroPad*(s: string; minLen: int): string =
|
proc zeroPad*(s: string; minLen: int): string =
|
||||||
if s.len < minLen:
|
if s.len < minLen:
|
||||||
result = repeatChar(minLen - s.len, '0')
|
result = repeat(0, minLen - s.len)
|
||||||
result.add s
|
result.add s
|
||||||
else:
|
else:
|
||||||
result = s
|
result = s
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ when isMainModule:
|
||||||
var res = t.map(proc(z: int): int = result = z * 10)
|
var res = t.map(proc(z: int): int = result = z * 10)
|
||||||
dumpSeq res
|
dumpSeq res
|
||||||
|
|
||||||
from strutils import toHex, repeatStr
|
from strutils import toHex
|
||||||
var foocakes = t.map(proc(z: int): string =
|
var foocakes = t.map(proc(z: int): string =
|
||||||
result = toHex((z * 23).biggestInt, 4))
|
result = toHex((z * 23).BiggestInt, 4))
|
||||||
dumpSeq foocakes
|
dumpSeq foocakes
|
||||||
|
|
||||||
t.mapInPlace(proc(z: int): int = result = z * 30)
|
t.mapInPlace(proc(z: int): int = result = z * 30)
|
||||||
|
|
|
||||||
|
|
@ -24,17 +24,17 @@ when isMainModule:
|
||||||
import strutils
|
import strutils
|
||||||
var r = compress("Hello")
|
var r = compress("Hello")
|
||||||
echo repr(r)
|
echo repr(r)
|
||||||
var l = "Hello".len
|
var ln = "Hello".len
|
||||||
var rr = uncompress(r, l)
|
var rr = uncompress(r, ln)
|
||||||
echo repr(rr)
|
echo repr(rr)
|
||||||
assert rr == "Hello"
|
assert rr == "Hello"
|
||||||
|
|
||||||
proc `*`(a: string; b: int): string {.inline.} = result = repeatStr(b, a)
|
proc `*`(a: string; b: int): string {.inline.} = result = repeat(a, b)
|
||||||
var s = "yo dude sup bruh homie" * 50
|
var s = "yo dude sup bruh homie" * 50
|
||||||
r = compress(s)
|
r = compress(s)
|
||||||
echo s.len, " -> ", r.len
|
echo s.len, " -> ", r.len
|
||||||
|
|
||||||
l = s.len
|
ln = s.len
|
||||||
rr = uncompress(r, l)
|
rr = uncompress(r, ln)
|
||||||
echo r.len, " -> ", rr.len
|
echo r.len, " -> ", rr.len
|
||||||
assert rr == s
|
assert rr == s
|
||||||
|
|
@ -174,7 +174,7 @@ when isMainModule:
|
||||||
block:
|
block:
|
||||||
var
|
var
|
||||||
TestFile: FileChallengePair
|
TestFile: FileChallengePair
|
||||||
contents = repeatStr(2, "abcdefghijklmnopqrstuvwxyz")
|
contents = repeat("abcdefghijklmnopqrstuvwxyz", 2)
|
||||||
testFile.challenge = newScFileChallenge("foobar.test", FZoneCfg, contents.len.int32)
|
testFile.challenge = newScFileChallenge("foobar.test", FZoneCfg, contents.len.int32)
|
||||||
testFile.file = checksumStr(contents)
|
testFile.file = checksumStr(contents)
|
||||||
myAssets.add testFile
|
myAssets.add testFile
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ Possible Commands:
|
||||||
csource [options] builds the C sources for installation
|
csource [options] builds the C sources for installation
|
||||||
zip builds the installation ZIP package
|
zip builds the installation ZIP package
|
||||||
inno builds the Inno Setup installer
|
inno builds the Inno Setup installer
|
||||||
""" % [NimVersion & repeatChar(44-len(NimVersion)),
|
""" % [NimVersion & spaces(44-len(NimVersion)),
|
||||||
CompileDate, CompileTime]
|
CompileDate, CompileTime]
|
||||||
|
|
||||||
echo HelpText
|
echo HelpText
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ proc highlight(s, match, repl: string, t: tuple[first, last: int],
|
||||||
for i in t.last+1 .. y: stdout.write(s[i])
|
for i in t.last+1 .. y: stdout.write(s[i])
|
||||||
stdout.write("\n")
|
stdout.write("\n")
|
||||||
if showRepl:
|
if showRepl:
|
||||||
stdout.write(repeatChar(alignment-1), "-> ")
|
stdout.write(spaces(alignment-1), "-> ")
|
||||||
for i in x .. t.first-1: stdout.write(s[i])
|
for i in x .. t.first-1: stdout.write(s[i])
|
||||||
writeColored(repl)
|
writeColored(repl)
|
||||||
for i in t.last+1 .. y: stdout.write(s[i])
|
for i in t.last+1 .. y: stdout.write(s[i])
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ macro updated(e: expr): expr {.immediate.} =
|
||||||
proc updatedDate(year, month, day: string): string =
|
proc updatedDate(year, month, day: string): string =
|
||||||
## wrapper around the update macro with easy input.
|
## wrapper around the update macro with easy input.
|
||||||
result = updated("$1-$2-$3T00:00:00Z" % [year,
|
result = updated("$1-$2-$3T00:00:00Z" % [year,
|
||||||
repeatStr(2 - len(month), "0") & month,
|
repeat("0", 2 - len(month)) & month,
|
||||||
repeatStr(2 - len(day), "0") & day])
|
repeat("0", 2 - len(day)) & day])
|
||||||
|
|
||||||
macro entry(e: expr): expr {.immediate.} =
|
macro entry(e: expr): expr {.immediate.} =
|
||||||
## generates the rss xml ``entry`` element.
|
## generates the rss xml ``entry`` element.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue