fix merge conflict
This commit is contained in:
commit
ac8274c60f
3 changed files with 51 additions and 6 deletions
|
|
@ -86,10 +86,10 @@ proc enumToString*(enums: openArray[enum]): string =
|
||||||
- Added `macros.isInstantiationOf` for checking if the proc symbol
|
- Added `macros.isInstantiationOf` for checking if the proc symbol
|
||||||
is instantiation of generic proc symbol.
|
is instantiation of generic proc symbol.
|
||||||
|
|
||||||
- There is a new stdlib mdoule `experimental/diff` to compute the famous "diff"
|
- Added the parameter ``isSorted`` for the ``sequtils.deduplicate`` proc.
|
||||||
|
- There is a new stdlib module `std/diff` to compute the famous "diff"
|
||||||
of two texts by line.
|
of two texts by line.
|
||||||
|
|
||||||
|
|
||||||
### Library changes
|
### Library changes
|
||||||
|
|
||||||
- The string output of `macros.lispRepr` proc has been tweaked
|
- The string output of `macros.lispRepr` proc has been tweaked
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ proc repeat*[T](x: T, n: Natural): seq[T] =
|
||||||
for i in 0 ..< n:
|
for i in 0 ..< n:
|
||||||
result[i] = x
|
result[i] = x
|
||||||
|
|
||||||
proc deduplicate*[T](s: openArray[T]): seq[T] =
|
proc deduplicate*[T](s: openArray[T], isSorted: bool = false): seq[T] =
|
||||||
## Returns a new sequence without duplicates.
|
## Returns a new sequence without duplicates.
|
||||||
##
|
##
|
||||||
## Example:
|
## Example:
|
||||||
|
|
@ -129,6 +129,15 @@ proc deduplicate*[T](s: openArray[T]): seq[T] =
|
||||||
## assert unique1 == @[1, 3, 4, 2, 8]
|
## assert unique1 == @[1, 3, 4, 2, 8]
|
||||||
## assert unique2 == @["a", "c", "d"]
|
## assert unique2 == @["a", "c", "d"]
|
||||||
result = @[]
|
result = @[]
|
||||||
|
if s.len > 0:
|
||||||
|
if isSorted:
|
||||||
|
var prev = s[0]
|
||||||
|
result.add(prev)
|
||||||
|
for i in 1..s.high:
|
||||||
|
if s[i] != prev:
|
||||||
|
prev = s[i]
|
||||||
|
result.add(prev)
|
||||||
|
else:
|
||||||
for itm in items(s):
|
for itm in items(s):
|
||||||
if not result.contains(itm): result.add(itm)
|
if not result.contains(itm): result.add(itm)
|
||||||
|
|
||||||
|
|
@ -827,6 +836,7 @@ macro mapLiterals*(constructor, op: untyped;
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import strutils
|
import strutils
|
||||||
|
from algorithm import sorted
|
||||||
|
|
||||||
# helper for testing double substitution side effects which are handled
|
# helper for testing double substitution side effects which are handled
|
||||||
# by `evalOnceAs`
|
# by `evalOnceAs`
|
||||||
|
|
@ -902,10 +912,18 @@ when isMainModule:
|
||||||
unique2 = deduplicate(dup2)
|
unique2 = deduplicate(dup2)
|
||||||
unique3 = deduplicate(dup3)
|
unique3 = deduplicate(dup3)
|
||||||
unique4 = deduplicate(dup4)
|
unique4 = deduplicate(dup4)
|
||||||
|
unique5 = deduplicate(dup1.sorted, true)
|
||||||
|
unique6 = deduplicate(dup2, true)
|
||||||
|
unique7 = deduplicate(dup3.sorted, true)
|
||||||
|
unique8 = deduplicate(dup4, true)
|
||||||
assert unique1 == @[1, 3, 4, 2, 8]
|
assert unique1 == @[1, 3, 4, 2, 8]
|
||||||
assert unique2 == @["a", "c", "d"]
|
assert unique2 == @["a", "c", "d"]
|
||||||
assert unique3 == @[1, 3, 4, 2, 8]
|
assert unique3 == @[1, 3, 4, 2, 8]
|
||||||
assert unique4 == @["a", "c", "d"]
|
assert unique4 == @["a", "c", "d"]
|
||||||
|
assert unique5 == @[1, 2, 3, 4, 8]
|
||||||
|
assert unique6 == @["a", "c", "d"]
|
||||||
|
assert unique7 == @[1, 2, 3, 4, 8]
|
||||||
|
assert unique8 == @["a", "c", "d"]
|
||||||
|
|
||||||
block: # zip test
|
block: # zip test
|
||||||
let
|
let
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,20 @@ import strutils
|
||||||
|
|
||||||
proc expandTabs*(s: string, tabSize: int = 8): string {.noSideEffect,
|
proc expandTabs*(s: string, tabSize: int = 8): string {.noSideEffect,
|
||||||
procvar.} =
|
procvar.} =
|
||||||
## Expand tab characters in `s` by `tabSize` spaces
|
## Expand tab characters in `s` replacing them by spaces.
|
||||||
|
##
|
||||||
|
## The amount of inserted spaces for each tab character is the difference
|
||||||
|
## between the current column number and the next tab position. Tab positions
|
||||||
|
## occur every `tabSize` characters.
|
||||||
|
## The column number starts at 0 and is increased with every single character
|
||||||
|
## and inserted space, except for newline, which resets the column number
|
||||||
|
## back to 0.
|
||||||
|
runnableExamples:
|
||||||
|
doAssert expandTabs("\t", 4) == " "
|
||||||
|
doAssert expandTabs("\tfoo\t", 4) == " foo "
|
||||||
|
doAssert expandTabs("\tfoo\tbar", 4) == " foo bar"
|
||||||
|
doAssert expandTabs("\tfoo\tbar\t", 4) == " foo bar "
|
||||||
|
doAssert expandTabs("ab\tcd\n\txy\t", 3) == "ab cd\n xy "
|
||||||
|
|
||||||
result = newStringOfCap(s.len + s.len shr 2)
|
result = newStringOfCap(s.len + s.len shr 2)
|
||||||
var pos = 0
|
var pos = 0
|
||||||
|
|
@ -48,6 +61,13 @@ proc partition*(s: string, sep: string,
|
||||||
## Returns a 3 string tuple of (beforeSep, `sep`, afterSep) or
|
## Returns a 3 string tuple of (beforeSep, `sep`, afterSep) or
|
||||||
## (`s`, "", "") if `sep` is not found and `right` is false or
|
## (`s`, "", "") if `sep` is not found and `right` is false or
|
||||||
## ("", "", `s`) if `sep` is not found and `right` is true
|
## ("", "", `s`) if `sep` is not found and `right` is true
|
||||||
|
runnableExamples:
|
||||||
|
doAssert partition("foo:bar", ":") == ("foo", ":", "bar")
|
||||||
|
doAssert partition("foobarbar", "bar") == ("foo", "bar", "bar")
|
||||||
|
doAssert partition("foobarbar", "bank") == ("foobarbar", "", "")
|
||||||
|
doAssert partition("foobarbar", "foo") == ("", "foo", "barbar")
|
||||||
|
doAssert partition("foofoobar", "bar") == ("foofoo", "bar", "")
|
||||||
|
|
||||||
let position = if right: s.rfind(sep) else: s.find(sep)
|
let position = if right: s.rfind(sep) else: s.find(sep)
|
||||||
if position != -1:
|
if position != -1:
|
||||||
return (s[0 ..< position], sep, s[position + sep.len ..< s.len])
|
return (s[0 ..< position], sep, s[position + sep.len ..< s.len])
|
||||||
|
|
@ -59,6 +79,13 @@ proc rpartition*(s: string, sep: string): (string, string, string)
|
||||||
##
|
##
|
||||||
## Returns a 3 string tuple of (beforeSep, `sep`, afterSep) or
|
## Returns a 3 string tuple of (beforeSep, `sep`, afterSep) or
|
||||||
## ("", "", `s`) if `sep` is not found
|
## ("", "", `s`) if `sep` is not found
|
||||||
|
runnableExamples:
|
||||||
|
doAssert rpartition("foo:bar", ":") == ("foo", ":", "bar")
|
||||||
|
doAssert rpartition("foobarbar", "bar") == ("foobar", "bar", "")
|
||||||
|
doAssert rpartition("foobarbar", "bank") == ("", "", "foobarbar")
|
||||||
|
doAssert rpartition("foobarbar", "foo") == ("", "foo", "barbar")
|
||||||
|
doAssert rpartition("foofoobar", "bar") == ("foofoo", "bar", "")
|
||||||
|
|
||||||
return partition(s, sep, right = true)
|
return partition(s, sep, right = true)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue