Commit Graph

338 Commits

Author SHA1 Message Date
metagn
041098e882 clean up stdlib with --jsbigint64 (#24255)
refs #6978, refs #6752, refs #21613, refs #24234

The `jsNoInt64`, `whenHasBigInt64`, `whenJsNoBigInt64` templates are
replaced with bool constants to use with `when`. Weird that I didn't do
this in the first place.

The `whenJsNoBigInt64` template was also slightly misleading. The first
branch was compiled for both no bigint64 on JS as well as on C/C++. It
seems only `trandom` depended on this by mistake.

The workaround for #6752 added in #6978 to `times` is also removed with
`--jsbigint64:on`, but #24233 was also encountered with this, so this PR
depends on #24234.
2024-10-19 16:40:28 +02:00
Leon Lysak
ce75042a9d Update documentation for parseEnum in strutils.nim (#23804)
added small note regarding style insensitivity for parsing enums. the
casing of the first letter is still taken into account for this
function. was confused a little at first because when I read "style
insensitive manner" I thought it meant casing as well and ran into a
couple of `ValueError`'s because of it.
2024-07-06 22:51:15 +02:00
lit
b838d3ece1 doc(format): ospaths2,strutils: followup #23560 (#23629)
followup #23560
2024-05-20 19:18:28 +08:00
lit
2e3777d6f3 Improve strutils.rsplit doc, proc and iterator have oppose result order. (#23570)
[`rsplit
iterator`](https://nim-lang.org/docs/strutils.html#rsplit.i,string,char,int)
yields substring in reversed order,

while [`proc
rsplit`](https://nim-lang.org/docs/strutils.html#rsplit%2Cstring%2Cchar%2Cint)'s
order is not reversed, but its doc only declare ```
The same as the rsplit iterator, but is a func that returns a sequence
of substrings.
```
2024-05-10 10:30:06 +02:00
ringabout
dfd778d056 fixes #23304; uses snprintf instead of sprintf (#23322)
fixes #23304
2024-02-20 07:28:45 +01:00
Zoom
8d1c722d2d Docs:strutils. Expand multiReplace docs, add runnableExamples (#23181)
- Clarified the implications of order of operation.
- Mentioned overlapping isn't handled
- Added the runnableExamples block

Fixes #23160, which supposedly should have been fixed in an earlier PR
#23022, but the wording was still not clear enough to my liking, which
the raised issue kind of confirms.
2024-01-08 08:23:24 +01:00
Joachim Hereth
d5780a3e4e strutils.multiReplace: Making order of replacement explicit (#23022)
In the docs for strutils.multiReplace:

Making it more explicit that left to right comes before the order in the
replacements arg (but that the latter matters too).

E.g.

```
echo "ab".multiReplace(@[("a", "1"), ("ax", "2")])
echo "ab".multiReplace(@[("ab", "2"), ("a", "1")])
```

gives

```
1b
2
```

resolves #23016
2023-12-02 22:41:53 +01:00
ringabout
4d11d0619d complete std prefixes for stdlib (#22887)
follow up https://github.com/nim-lang/Nim/pull/22851
follow up https://github.com/nim-lang/Nim/pull/22873
2023-10-30 17:03:04 +01:00
ringabout
5eeafbf550 fixes #22696; func strutils.join for non-strings uses proc $ which can have side effects (#22770)
fixes #22696
partially revert https://github.com/nim-lang/Nim/pull/16281

`join` calls `$` interally, which might introduce a sideeffect call.
2023-09-30 06:27:27 +02:00
Andrey Makarov
a660c17d30 Markdown code blocks migration part 8 (#22478) 2023-08-15 06:27:36 +02:00
Zoom
5e529b3bfa strutils.split/rsplit now return src on an empty sep (#22136)
This is a rebase of an earlier rejected PR. Following the discussion
around it, this commit provides a valid output for and edge case
of an empty separator for `split` and `rsplit` routines. The empty
separator is interpreted as "split by no separators" and the initial
string is returned. This is consistent with the behaviour of the
`set[char]` version of `split`/`rsplit` routines and unifies them all.

Compared to a commit merged earlier, this one has a benefit of
not using assertions that will be removed in release builds
and thus still not preventing possible infinite loops (which was the
earlier behaviour for this edge case for separator of type `string`).

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-06-21 08:52:33 +02:00
ringabout
40f88da90b alternative to #21914; split, rsplit now forbid an empty separator (#21961) 2023-05-30 13:40:09 +02:00
metagn
f05387045d int64/uint64 as bigint in JS (#21613)
* int64/uint64 as bigint in JS

* fix CI

* convert to compile option

* fix lie

* smaller diff, changelog entry
2023-04-11 21:20:20 +02:00
ringabout
fc068ee06d fixes #18134; registers formatBiggestFloat in VM (#21299)
fixes #18134; registers formatBiggestFloat in vmops

strformat supports float format in VM
2023-01-26 23:03:59 +01:00
ringabout
93b59da490 fixes #20244; fixes castSizes warnings (#21102)
* fixes #20244; fixes castSizes warnings

* fixes js

* fixes js

* fixes js

* fixes

* typo

* extend using uint64

* Update lib/std/syncio.nim
2022-12-22 08:27:11 +01:00
Bung
a9bd78d579 fix #12122 (#21096) 2022-12-16 08:01:15 +01:00
Andreas Rumpf
3812d91390 alternative, much simpler algorithm for strict func checking (#21066)
* alternative, much simpler algorithm for strict func checking

* forgot to git add new compiler module

* new spec is incredibly simple to describe

* fixes bigints regression

* typos

* closes #16305; closes #17387; closes #20863
2022-12-11 16:58:50 +01:00
ringabout
06cd15663d fixes ptr to cstring warnings[backport] (#20848)
* fix =#13790 ptr char (+friends) should not implicitly convert to cstring

* Apply suggestions from code review

* first round; compiles on windows

* nimPreviewSlimSystem

* conversion is unsafe, cast needed

* fixes more tests

* fixes asyncnet

* another try another error

* last one

* true

* one more

* why bugs didn't show at once

* add `nimPreviewCstringConversion` switch

* typo

* fixes ptr to cstring warnings[backport]

* add fixes

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-11-16 10:22:51 +01:00
ringabout
be18f4e513 follow up #19714; add memmem optimizations for find on Linux, Macos and BSDs (#20556)
* fixes tests

* add memmem optimization for find

* fixes

* ty[o

* fixes `"abc".find("") == 0 doesn't work on macOS

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-10-13 23:58:59 +02:00
ee7
10355cb48a strutils, rstgen: avoid deprecated strutils.delete (#20488)
The strutils `delete` func with signature

    func delete*(s: var string, first, last: int)

was deprecated in adba5eb45e, in favor of one with signature

    func delete*(s: var string, slice: Slice[int])

However, a few procedures still used the deprecated form. This commit
updates them, resolving these deprecation warnings:

    rstgen.nim(766, 12) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]
    strutils.nim(1651, 19) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]
    strutils.nim(1679, 7) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]
    strutils.nim(2472, 7) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]

Before this commit:

- `trimZeros` called `s.delete(i+1, i)` for an input that lacks a
  trailing zero (like "1.23").

- `removePrefix*(s: var string, prefix: string)` called
  `s.delete(0, -1)` when the prefix was the empty string.

which did not modify `s`, nor raise an error. But the newer slice
`delete` raises an `IndexDefect` when the start of the slice is greater
than the end, so we avoid calling the new `delete` for such a case.

Recall that exceptions inheriting from `system.Defect` are not tracked
with the `.raises: []` exception tracking mechanism [1], so this commit
does not break existing code like:

    proc foo {.raises: [].} =
      var s = "abc1.20"
      s.removePrefix("abc")
      s.trimZeros()
      doAssert s == "1.2"

The `strutils.delete` deprecation was motivated by a problem with
`system.delete` [2][3]:

    `system.delete` had surprising behavior when the index passed to it
    was out of bounds (it would delete the last entry then). Compile
    with `-d:nimStrictDelete` so that an index error is produced
    instead.

    Be aware however that your code might depend on this quirky behavior
    so a review process is required on your part before you can use
    `-d:nimStrictDelete`. To make this review easier, use the
    `-d:nimAuditDelete` switch, which pretends that `system.delete` is
    deprecated so that it is easier to see where it was used in your
    code.

    `-d:nimStrictDelete` will become the default in upcoming versions.

A similar deprecation happened with `sequtils.delete` [4], but that
deprecated form is already not used in this repo.

[1] https://github.com/nim-lang/Nim/blob/2dec69fe5aa6/doc/manual.md#exception-tracking
[2] https://github.com/nim-lang/Nim/blob/2dec69fe5aa6/changelogs/changelog_1_6_0.md#system
[3] https://github.com/nim-lang/Nim/commit/92cb76571432
[4] https://github.com/nim-lang/Nim/commit/1d6863a7899f
2022-10-05 13:57:17 -04:00
ringabout
65c2518d5c fix #19500; remove find optimization [backport: 1.6] (#19714)
* remove find optimization

close #19500

* save find to std

* add simple tests

* Apply suggestions from code review

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: sandytypical <43030857+xflywind@users.noreply.github.com>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-09-28 16:05:41 -04:00
n5m
9ca88a1889 fix #18128 rfind on empty needle returns rightmost index (#20430)
rfind on empty needle returns haystack len
2022-09-26 15:39:22 -04:00
ringabout
c9a92117f9 Revert "add fromChar" (#20336)
Revert "add `fromChar` (#20332)"

This reverts commit 846cc746a2.
2022-09-12 13:33:47 -04:00
Hamid Bluri
846cc746a2 add fromChar (#20332)
`fromChar` converts `char` to `SomeInteger`, related to `isDigit`
2022-09-11 13:50:06 -04:00
konsumlamm
3fef2fd52c Improve error message for strutils.addf (#20157)
Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-08-05 13:44:21 -04:00
Clay Sweetser
77891cedae Fix "Add Wider Ascii Chars sets and func for string formatting" (#20120) 2022-07-31 23:24:14 -04:00
Sultan Al Isaiee
3987a3bf97 Add Wider Ascii Chars sets and func for string formatting (#19994)
* Add more Ascii Chars sets

- add UpperCaseLetters set
- add LowerCaseLetters set
- add Punctuations set
- add PrintablesNoWhiteSpace set
- add Printables set
- add isPunctuationAscii func
- add isPrintableAscii func

* Omit isPunctuationAscii and isPrintableAscii procs

* Apply suggestions for adding Wider Ascii Chars sets

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>

* Update strutils.nim

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
2022-07-31 20:20:25 -04:00
Zoom
b024a45163 Fix find routines' api to default to last=-1 (#19761)
This changes the default for the `last` parameter of various `find`
routines from `0` to `-1`. Previous default prevents limiting the search
to the first character. This is a logic error, as full text search was
performed for 2 *valid* values of `last`: `0` and `last.high()`.

Adds an overload for `initSkipTable` which returns a newly initialized
table. This encapsulates every single usage of a `var`-acting original
func in this module.

Co-authored-by: flywind <xzsflywind@gmail.com>
2022-06-07 10:35:06 +02:00
Zoom
0455d24d55 Fix questionable suggestion in strutils docs (#19765)
* Fix questionable suggestion in `stutils` docs

- Removes the recommendation to pass a string slice for getting a relative
index for `find` and `rfind` functions, as this currently makes a string
copy, while a simple subtraction is enough.

- Docstring for `SkipTable` type.

* Doc layout fixup
2022-05-06 11:19:27 +02:00
flywind
7f6e800caf move assertions out of system (#19599) 2022-03-23 20:34:53 +01:00
Leon
5853303be0 docs: Fix broken cross references to rfind in strutils (#19382) [backport]
Fixes three broken cross references to `rfind` in strutils.
Breakage due to signature changes of the `rfind` methods.

Co-authored-by: adigitoleo <adigitoleo@dissimulo.com>
2022-01-13 14:45:47 +01:00
Tomasz Kramkowski
ee703c5db4 Fix nimIdentNormalize, fixes #19067 (#19068)
* Make nimIdentNormalize return "" when passed ""; fixes #19067

Fixes #19067

* Add tests for nimIdentNormalize
2021-10-29 11:39:41 +02:00
Andrey Makarov
7ba2659f73 docgen: implement doc link resolution in current module (#18642) 2021-10-28 19:20:52 +02:00
flywind
4adada0d80 fix a typo (rename temporal to temporary (#18892) [backport] 2021-09-24 16:34:12 +02:00
flywind
883c04d444 don't use space after proc names (#18681) 2021-08-12 20:57:12 -04:00
Timothee Cour
adba5eb45e deprecate strutils.delete and add an overload with saner semantics consistent with sequtils.delete; follows #18487 (#18510) 2021-07-18 11:10:08 +02:00
Timothee Cour
779b4e307b don't use {.rtl.} for generics, otherwise -d:useNimRtl gives ambiguous identifier nimrtl error (#18406) 2021-07-01 11:14:01 +02:00
n5m
9df631a379 reuse algorithm.fill while building SkipTable (#18138)
* reuse algorithm.fill while building SkipTable

* Update lib/pure/strutils.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
2021-06-03 14:25:52 +02:00
n5m
064fe18de6 improve fast returns of find and rfind (#18127) 2021-05-31 11:20:15 +02:00
Michael Krieger
7637cff9cf Fix documentation of strutils.stripLineEnd (#17883)
It does not return anything.
2021-04-28 11:33:08 -07:00
Andreas Rumpf
643dbc743b use strstr for a faster find implementation (#17672)
* use strstr for a faster find implementation
* stress the -d:release and -d:danger switches
2021-04-08 00:54:47 +02:00
flywind
e2269f9216 [docs]fix #17473 (#17565)
* fix nim js cmp fails at CT

* Add `hasClosure` to `std/effecttraits`

* type

* Update changelog.md

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* fix #14011

* Delete ttypetraits.nim

* Apply suggestions from code review

* fix #17473

* Revert "fix #14011"

This reverts commit 0eed97a84b.

* Update lib/system.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2021-03-29 14:39:49 +02:00
ee7
b70e33f5bb strutils: improve doc comments for replace funcs (#17427)
This commit fixes mispellings of "occurrence" introduced by:
- 76a3b350ce (#17337)
- 8e8bea9044 (#17339)
and adds the same "every occurrence of" in the `replaceWord` func.

Other changes:
- Prefer "replace with" to "replace by".
- Be more consistent with "the" - prefer "of the character" given that
  we wrote "by the character".
- Try to be more consistent with writing the types - add
  "the string `sub`" given that we wrote "the character `sub`".
2021-03-20 13:22:50 +01:00
Héctor M. Monacci
8e8bea9044 Clarify behaviour of char replace (#17339)
Clarify behaviour of char replace by adding ```every ocurrence of character```
2021-03-19 11:19:41 -07:00
Héctor M. Monacci
76a3b350ce Clarify behaviour of ``replace`` (#17337)
* Clarify behaviour of ```replace```

Clarify behaviour of ```replace``` by adding the word ```every```

* Update lib/pure/strutils.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2021-03-11 14:05:57 +01:00
Danil Yarantsev
56461c280f Change stdlib imports to use std prefix in most examples (#17202) 2021-02-28 13:17:19 -08:00
flywind
3f38f8fbb7 add strbasics.strip (#16280) 2021-02-24 10:22:47 +01:00
Danil Yarantsev
4e619a6bea A few rst doc fixes (#17151)
* Fix a couple of rst formatting issues

* no need for the extra space
2021-02-23 08:59:13 +01:00
Timothee Cour
b9994925f5 remove all uses of condsyms symbols defined prior to bootstrap nim 0.20.0 (#16918)
* nimNoArrayToCstringConversion deadcode
* nimbabel deadcode
* nimHasalignOf deadcode
* nimvarargstyped deadcode
* nimhygiene deadcode
* nimNewTypedesc deadcode
* nimlocks deadcode
* nimHasCppDefine deadcode
* nimHasRunnableExamples deadcode
* nimHasNilChecks deadcode
* nimSymKind deadcode
* minor macros refactoring
* nimVmEqIdent deadcode
* nimNoNil deadcode
* nimNoZeroTerminator deadcode
* nimHasSymOwnerInMacro deadcode
* nimVmExportFixed deadcode
* nimNewRuntime deadcode
* nimAshr deadcode
* nimUncheckedArrayTyp deadcode
* nimHasTypeof deadcode
* nimErrorProcCanHaveBody deadcode
* nimHasHotCodeReloading deadcode
* nimHasSignatureHashInMacro deadcode
* nimHasDefault deadcode
* nimMacrosSizealignof deadcode
2021-02-17 09:32:36 +01:00
flywind
c04f305bf7 make cstrutils work in VM (#16590)
* make cstrutils work in VM

* more
2021-01-05 17:52:26 +01:00