summary refs log tree commit diff stats
path: root/lib/pure/strutils.nim
Commit message (Collapse)AuthorAgeFilesLines
* Update documentation for parseEnum in strutils.nim (#23804)Leon Lysak2024-07-061-2/+2
| | | | | | | 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.
* doc(format): ospaths2,strutils: followup #23560 (#23629)lit2024-05-201-6/+6
| | | followup #23560
* Improve strutils.rsplit doc, proc and iterator have oppose result order. ↵lit2024-05-101-6/+6
| | | | | | | | | | | | | | (#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. ```
* fixes #23304; uses `snprintf` instead of `sprintf` (#23322)ringabout2024-02-201-5/+5
| | | fixes #23304
* Docs:strutils. Expand `multiReplace` docs, add runnableExamples (#23181)Zoom2024-01-081-7/+20
| | | | | | | | | - 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.
* strutils.multiReplace: Making order of replacement explicit (#23022)Joachim Hereth2023-12-021-2/+3
| | | | | | | | | | | | | | | | | | | | | | 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
* complete std prefixes for stdlib (#22887)ringabout2023-10-301-4/+4
| | | | follow up https://github.com/nim-lang/Nim/pull/22851 follow up https://github.com/nim-lang/Nim/pull/22873
* fixes #22696; func `strutils.join` for non-strings uses proc `$` which can ↵ringabout2023-09-301-1/+1
| | | | | | | | 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.
* Markdown code blocks migration part 8 (#22478)Andrey Makarov2023-08-151-42/+72
|
* `strutils.split/rsplit` now return src on an empty sep (#22136)Zoom2023-06-211-23/+37
| | | | | | | | | | | | | | | 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>
* alternative to #21914; split, rsplit now forbid an empty separator (#21961)ringabout2023-05-301-4/+22
|
* int64/uint64 as bigint in JS (#21613)metagn2023-04-111-5/+5
| | | | | | | | | | | * int64/uint64 as bigint in JS * fix CI * convert to compile option * fix lie * smaller diff, changelog entry
* fixes #18134; registers `formatBiggestFloat` in VM (#21299)ringabout2023-01-261-52/+55
| | | | | fixes #18134; registers formatBiggestFloat in vmops strformat supports float format in VM
* fixes #20244; fixes castSizes warnings (#21102)ringabout2022-12-221-2/+14
| | | | | | | | | | | | | | | | | * fixes #20244; fixes castSizes warnings * fixes js * fixes js * fixes js * fixes * typo * extend using uint64 * Update lib/std/syncio.nim
* fix #12122 (#21096)Bung2022-12-161-2/+2
|
* alternative, much simpler algorithm for strict func checking (#21066)Andreas Rumpf2022-12-111-1/+1
| | | | | | | | | | | | | * 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
* fixes ptr to cstring warnings[backport] (#20848)ringabout2022-11-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* follow up #19714; add `memmem` optimizations for `find` on Linux, Macos and ↵ringabout2022-10-131-1/+26
| | | | | | | | | | | | | | | 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>
* strutils, rstgen: avoid deprecated `strutils.delete` (#20488)ee72022-10-051-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The strutils `delete` func with signature func delete*(s: var string, first, last: int) was deprecated in adba5eb45e0a, 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
* fix #19500; remove find optimization [backport: 1.6] (#19714)ringabout2022-09-281-20/+1
| | | | | | | | | | | | | | | | * 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>
* fix #18128 rfind on empty needle returns rightmost index (#20430)n5m2022-09-261-1/+2
| | | rfind on empty needle returns haystack len
* Revert "add `fromChar`" (#20336)ringabout2022-09-121-9/+0
| | | | | Revert "add `fromChar` (#20332)" This reverts commit 846cc746a2350ad3f845a4eb0ce97b864891cd35.
* add `fromChar` (#20332)Hamid Bluri2022-09-111-0/+9
| | | `fromChar` converts `char` to `SomeInteger`, related to `isDigit`
* Improve error message for `strutils.addf` (#20157)konsumlamm2022-08-051-8/+8
| | | Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Fix "Add Wider Ascii Chars sets and func for string formatting" (#20120)Clay Sweetser2022-07-311-3/+3
|
* Add Wider Ascii Chars sets and func for string formatting (#19994)Sultan Al Isaiee2022-07-311-12/+25
| | | | | | | | | | | | | | | | | | | | | * 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>
* Fix `find` routines' api to default to `last=-1` (#19761)Zoom2022-06-071-41/+50
| | | | | | | | | | | | 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>
* Fix questionable suggestion in `strutils` docs (#19765)Zoom2022-05-061-9/+16
| | | | | | | | | | | * 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
* move assertions out of system (#19599)flywind2022-03-231-0/+3
|
* docs: Fix broken cross references to `rfind` in strutils (#19382) [backport]Leon2022-01-131-3/+3
| | | | | | 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>
* Fix nimIdentNormalize, fixes #19067 (#19068)Tomasz Kramkowski2021-10-291-2/+3
| | | | | | | * Make nimIdentNormalize return "" when passed ""; fixes #19067 Fixes #19067 * Add tests for nimIdentNormalize
* docgen: implement doc link resolution in current module (#18642)Andrey Makarov2021-10-281-0/+5
|
* fix a typo (rename `temporal` to `temporary` (#18892) [backport]flywind2021-09-241-1/+1
|
* don't use space after proc names (#18681)flywind2021-08-121-2/+2
|
* deprecate strutils.delete and add an overload with saner semantics ↵Timothee Cour2021-07-181-7/+33
| | | | consistent with sequtils.delete; follows #18487 (#18510)
* don't use `{.rtl.}` for generics, otherwise `-d:useNimRtl` gives `ambiguous ↵Timothee Cour2021-07-011-1/+1
| | | | identifier` nimrtl error (#18406)
* reuse algorithm.fill while building SkipTable (#18138)n5m2021-06-031-12/+2
| | | | | | | | | * 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>
* improve fast returns of find and rfind (#18127)n5m2021-05-311-1/+3
|
* Fix documentation of strutils.stripLineEnd (#17883)Michael Krieger2021-04-281-1/+1
| | | It does not return anything.
* use strstr for a faster find implementation (#17672)Andreas Rumpf2021-04-081-3/+26
| | | | | * use strstr for a faster find implementation * stress the -d:release and -d:danger switches
* [docs]fix #17473 (#17565)flywind2021-03-291-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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 0eed97a84b172b198bf4e6de69c04b84ef9d9f93. * 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>
* strutils: improve doc comments for `replace` funcs (#17427)ee72021-03-201-3/+4
| | | | | | | | | | | | | This commit fixes mispellings of "occurrence" introduced by: - 76a3b350ce0f (#17337) - 8e8bea9044f0 (#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`".
* Clarify behaviour of char replace (#17339)Héctor M. Monacci2021-03-191-1/+1
| | | Clarify behaviour of char replace by adding ```every ocurrence of character```
* Clarify behaviour of ```replace``` (#17337)Héctor M. Monacci2021-03-111-1/+1
| | | | | | | | | | | | * 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>
* Change stdlib imports to use std prefix in most examples (#17202)Danil Yarantsev2021-02-281-1/+1
|
* add strbasics.strip (#16280)flywind2021-02-241-0/+1
|
* A few rst doc fixes (#17151)Danil Yarantsev2021-02-231-1/+1
| | | | | * Fix a couple of rst formatting issues * no need for the extra space
* remove all uses of condsyms symbols defined prior to bootstrap nim 0.20.0 ↵Timothee Cour2021-02-171-11/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#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
* make cstrutils work in VM (#16590)flywind2021-01-051-12/+3
| | | | | * make cstrutils work in VM * more
* refactor cmpIgnoreStyle and cmpIgnoreCase (#16399)flywind2020-12-311-26/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * init * support strutils * more * better * Call len once per string/cstring * Change var to let * Compare ternary on first char * More appropriate param name * fix * better * one test * impl * more efficient * minor Co-authored-by: Clyybber <darkmine956@gmail.com>