Skip to content

Issue with insertSep function in strutils #24788

@ggb-sw

Description

@ggb-sw

Nim Version

insertSep() misbehaves when not dealing with numeric strings.

Not an earth shattering issue since it is easy enough to recode what insertSep does but if the function is there someone might like to look at why it does not behave as I would expect.

See example below.

Description

#!/usr/bin/env -S nim r
# File: test4.nim
# Nim Compiler Version 2.2.2 [Linux: amd64]

import std/strutils

# insertSep documentation suggests that the function is primarily useful for
# splitting numbers but it does not say it will fail if it is used otherwise

# The following works as expected
let src1 = "1234567890123456"
# The line prints "1234 5678 9012 3456"
echo src1.insertSep( ' ', 4)


# The following does not work as expected
# It includes 2 seperators but does not add the third.
let src2 = "SGVsbG8gV29ybGQ="
# The line prints "SGVsbG8g V29y bGQ=" but I would expect "SGVs bG8g V29y bGQ="
echo src2.insertSep( ' ', 4)


Current Output


Expected Output


Known Workarounds

Just rewrote what I needed without using insertSep

Additional Information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions