system.substr is not implemented with compilerProcs anymore
This commit is contained in:
parent
16d8fab310
commit
5b59852406
8 changed files with 157 additions and 67 deletions
|
|
@ -413,7 +413,7 @@ include "system/inclrtl"
|
|||
const NoFakeVars* = defined(nimscript) ## true if the backend doesn't support \
|
||||
## "fake variables" like 'var EBADF {.importc.}: cint'.
|
||||
|
||||
when not defined(JS):
|
||||
when not defined(JS) and not defined(gcDestructors):
|
||||
type
|
||||
TGenericSeq {.compilerproc, pure, inheritable.} = object
|
||||
len, reserved: int
|
||||
|
|
@ -1702,17 +1702,6 @@ proc addQuitProc*(QuitProc: proc() {.noconv.}) {.
|
|||
# In case of an unhandled exeption the exit handlers should
|
||||
# not be called explicitly! The user may decide to do this manually though.
|
||||
|
||||
proc substr*(s: string, first = 0): string {.
|
||||
magic: "CopyStr", importc: "copyStr", noSideEffect.}
|
||||
proc substr*(s: string, first, last: int): string {.
|
||||
magic: "CopyStrLast", importc: "copyStrLast", noSideEffect.}
|
||||
## copies a slice of `s` into a new string and returns this new
|
||||
## string. The bounds `first` and `last` denote the indices of
|
||||
## the first and last characters that shall be copied. If ``last``
|
||||
## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len``
|
||||
## is used instead: This means ``substr`` can also be used to `cut`:idx:
|
||||
## or `limit`:idx: a string's length.
|
||||
|
||||
when not defined(nimscript) and not defined(JS):
|
||||
proc zeroMem*(p: pointer, size: Natural) {.inline, benign.}
|
||||
## overwrites the contents of the memory at ``p`` with the value 0.
|
||||
|
|
@ -3262,7 +3251,11 @@ when not defined(JS): #and not defined(nimscript):
|
|||
when hasAlloc: include "system/mmdisp"
|
||||
{.pop.}
|
||||
{.push stack_trace: off, profiler:off.}
|
||||
when hasAlloc: include "system/sysstr"
|
||||
when hasAlloc:
|
||||
when defined(gcDestructors):
|
||||
include "core/strs"
|
||||
else:
|
||||
include "system/sysstr"
|
||||
{.pop.}
|
||||
when hasAlloc: include "system/strmantle"
|
||||
|
||||
|
|
@ -4171,6 +4164,21 @@ when not defined(js):
|
|||
proc toOpenArrayByte*(x: string; first, last: int): openarray[byte] {.
|
||||
magic: "Slice".}
|
||||
|
||||
proc substr*(s: string, first, last: int): string =
|
||||
let L = max(min(last, high(s)) - first + 1, 0)
|
||||
result = newString(L)
|
||||
for i in 0 .. L-1:
|
||||
result[i] = s[i+first]
|
||||
|
||||
proc substr*(s: string, first = 0): string =
|
||||
## copies a slice of `s` into a new string and returns this new
|
||||
## string. The bounds `first` and `last` denote the indices of
|
||||
## the first and last characters that shall be copied. If ``last``
|
||||
## is omitted, it is treated as ``high(s)``. If ``last >= s.len``, ``s.len``
|
||||
## is used instead: This means ``substr`` can also be used to `cut`:idx:
|
||||
## or `limit`:idx: a string's length.
|
||||
result = substr(s, first, high(s))
|
||||
|
||||
type
|
||||
ForLoopStmt* {.compilerProc.} = object ## special type that marks a macro
|
||||
## as a `for-loop macro`:idx:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue