Commit graph

211 commits

Author SHA1 Message Date
Dominik Picheta
03b073d541 Workaround VM bug in strutils 2018-06-17 23:26:18 +01:00
Dominik Picheta
8081a9b3d0 Exports unicode.toUpper/toLower in strutils module. 2018-06-17 00:12:51 +01:00
Vindaar
e80be6173d Add parse bin int, fixes #8018 (#8020)
* clarify `parseHexInt`, `parseOctInt` docstring and exception msgs

* add `parseBinInt` based on `parseutil.parseBin` implementation

Adds a `parseBinInt`, which parses a binary integer string and returns
it as an integer. This is based on the implementation of
`parseutil.parseBin`, removing the unnecessary parts.

* add tests for all `parse(Hex|Oct|Bin)Int` procs

* replace `parse*Int` proc impls by call to parseutil procs

Replaces the `parse(Hex|Oct|Bin)Int` procedure implementation by calls
to the `parseutil` procs, which receive a mutable argument.

Has the main advantage that the empty string as well as a "prefix
only" string, e.g. "0x" counts as an invalid integer.

Also moves the `parseOctInt` proc further up in the file so that all
`parse` procs are below one another.

* replace `var L` by `let L` in `parse` procs

There's no reason for the usage of `var` here.

* add `maxLen` optional arg for `parseutil.parse(Oct|Bin)`

Plus small change to test cases.

* update changelog about `parse*Int` procs

* fix `rejectParse` template in `tstrutils`

* make sure only `s.len` chars are parsed, if `maxLen+start` > s.len

Fixes a previous bug in `parseHex` (and now affected `parseOct` and
`parseBin`), which allowed to set `start + maxLen` to be larger than
the strings length. This resulted in an out of bounds access.

* move `parse*Int` proc change to breaking changes, add double `
2018-06-13 13:32:12 -04:00
Kaushal Modi
24df909d8a Make isUpper (and variants) work for strings with non-alpha chars
The other variants are isLower, isUpperAscii and isLowerAscii

Fixes https://github.com/nim-lang/Nim/issues/7963.

This commit changes the behavior and signatures of:

- isUpper, isLower in the unicode module
- isUpperAscii, isLowerAscii in the strutils module

A second mandatory parameter skipNonAlpha is added to these 4 procs.

(This change affects only for the case where the input is a *string*.)

---

With skipNonAlpha set to true, the behavior mimics the Python isupper and
islower behavior i.e. non-alphabetic chars/runes are ignored when checking if
the string is upper-case or lower-case.

    Before this commit:

      doAssert(not isUpper("A B"))

    After this commit:

      doAssert(not isUpper("A B", false))    <-- old behavior
      doAssert isUpper("A B", true)

      Below two are equivalent:

                           isUpper("A B", true)

        isAlpha("A B") and isUpper("A B", false)

.. and the similar for other 3 procs.
2018-06-08 15:14:29 -04:00
skilchen
91765e583d fix handling of default precision in formatBiggestFloat for the js backend (#7928) 2018-06-01 22:24:32 -04:00
Zahary Karadjov
70ec344bbf bugfix: strutils.find was broken for strings with uneven number of chars
For some reason, the problem was manifesting only inside the VM, it was
detecting an attempt to read past the string end (i.e. the formerly
accessible null byte).

To catch such errors, strutils now performs static tests too.

I've solved the problem by re-implementing the Boyer-Moore algotihm
in a cleaner way and I took the opportunity to make some other
optimisations to strutils.
2018-05-07 09:37:49 +02:00
Andreas Rumpf
0fad659bf7 make more tests green 2018-04-30 02:52:58 +02:00
Andreas Rumpf
9b8603adcd strutils: code cleanups and do not rely on the terminating binary zero anymore 2018-04-28 21:59:43 +02:00
Oscar Nihlgård
8caf257607 Don't escape multibyte characters (#7570) 2018-04-23 11:09:48 +02:00
Jacek Sieka
72dfe176f5 remove dead code elimination option (#7669) 2018-04-23 11:02:38 +02:00
Araq
5d13e3f28b fixes #7507 2018-04-19 00:09:55 +02:00
Arne Döring
ed5b7cbac0 move eqIdent to vm.nim (#7585)
* Strutils comment changes.

* fix typo
2018-04-15 23:38:43 +02:00
Andreas Rumpf
50d4224d41 fixes #6205 2018-04-14 00:40:24 +02:00
ryanc-signiq
67fd7a7f86 FIXUP: Removed +1 causing substr slicing to skip chars on first iteration of while loop (#7312) 2018-03-08 08:33:41 +01:00
Andreas Rumpf
0132442c1d strutils.strip: improve the documentation; fixes #7159 2018-03-05 21:45:13 +01:00
Andreas Rumpf
5c8332d871 fixes #7293 2018-03-05 19:46:13 +01:00
Dominik Picheta
1a565d7b20
Merge pull request #6517 from FedericoCeratto/hexstr
Add string-to-hex and back conversions
2018-01-26 15:32:28 +00:00
Fabian Keller
6df6ec27ec Improved collection-to-string behavior (#6825) 2017-12-14 14:02:13 +01:00
Dominik Picheta
45821ea2ab Fixes #4377. 2017-11-28 21:55:29 +01:00
Araq
653dcb8027 cleaned up strutils.nim 2017-11-28 01:15:33 +01:00
Federico Ceratto
4100932a4b Add string-to-hex and back conversions
Add parseHexStr and toHex and tests.
2017-11-27 16:43:41 +00:00
Araq
a720539f5e fixes system.runnableExamples; strutils makes use of runnableExamples 2017-11-26 03:24:59 +01:00
Fabian Keller
001298eb22 fixes #6589 again (#6766) 2017-11-17 10:51:39 +01:00
Fabian Keller
5e66a7ce59 Modified handling of zero precision in formatFloat (#6719) 2017-11-15 21:23:33 +01:00
Fabian Keller
7c588f2cc4 added doc examples for formatFloat (#6704) 2017-11-07 08:07:25 +01:00
olwi
0586529ff5 Adds optional maxsplit parameter to splitWhitespace (#6503) (#6690)
* Adds optional maxsplit parameter to splitWhitespace() (#6503)
* Adds an example to splitWhitespace doc comment. Minor fixes to several doc comments
2017-11-06 09:36:06 +01:00
Araq
3174cfe55c make tests green again 2017-11-01 00:20:40 +01:00
Bo Lingen
c182d37f45 Update removeSuffix implementations to match removePrefix (#6636) 2017-10-30 22:45:13 +01:00
Andreas Rumpf
74640862cb Merge branch 'devel' of github.com:nim-lang/Nim into devel 2017-10-29 20:36:21 +01:00
Fabian Keller
293a873051 fixes #6589 (#6590) 2017-10-29 20:09:46 +01:00
Andreas Rumpf
6a3288a60e more replacements for the deprecated '<' 2017-10-29 08:55:30 +01:00
Bo Lingen
e135135469 add strutils.removePrefix proc (#6473) 2017-10-28 10:47:23 +02:00
Dmitry Atamanov
93fd0b0cb5 strutils.find enhancements (#6582) 2017-10-28 09:30:19 +02:00
Viktor Marosvary
ce04288d64 isAlphaNumberic and isDigit improvement + tests (#6579)
if we encounter a character that does not satisfy the proc, we return immediately, without continuing to loop over the rest of the chars in the string.
2017-10-24 10:22:18 +02:00
Silvio
424b998f72 Fix removeSuffix rst code blocks
Add newline before `code-block` for `removeSuffix`
2017-10-23 11:11:08 +02:00
Dominik Picheta
ecfbe4940b Merge pull request #6051 from couven92/alignLeft
Add left-aligning string proc to strutils
2017-10-22 23:11:13 +01:00
Andreas Rumpf
3308d26581 breaking change: arrays of char do not convert to cstring; ptr to array of char does 2017-10-10 00:17:20 +02:00
Andreas Rumpf
9b1a23c554 minor breacking change: in string formats '' the '1' is now interpreted as a number, not as an identifier. This is more consistent with the rest of the mini language and allows '12'. 2017-10-06 08:28:16 +02:00
Andreas Rumpf
2b592a6425 in prepration for the upcoming different integer inference rules 2017-09-16 10:29:29 +02:00
Simon Krauter
94e336fe85 Fix wrong result of countLines() (#6371) 2017-09-15 10:45:22 +02:00
Fredrik Høisæther Rasch
37a615a31f Added Multi-Replacement proc for strings (#6193) 2017-08-07 19:58:11 +02:00
Fredrik Høisæther Rasch
177a634992 Add safeties for alignLeft 2017-07-04 11:52:54 +02:00
Fredrik Høisæther Rasch
9823c677b8 Augment align proc with alignLeft proc 2017-07-04 11:52:37 +02:00
Markus F.X.J. Oberhumer
a0f39e0ab4 Ascii character code 127 (DEL) is not printable and must be quoted. (#5984)
This is a follow-up to #5823.
2017-06-15 20:42:23 +02:00
Simon Krauter
40e9e751f0 Extend documenation of formatFloat() (#5799)
Added line: "If ``precision == 0``, it tries to format it nicely." (copied from formatBiggestFloat())
2017-05-13 21:50:44 +02:00
Andreas Rumpf
9f5492becd strutils.nim: make removeSuffix robust on empty strings 2017-03-18 10:42:11 +01:00
Simon Krauter
a42801d100 Make countLines() the same as len(splitLines(s)) (#5470)
The result of countLines() is now increased by 1 compared to the old
version.
Fixes #5460.
2017-03-03 01:31:17 +01:00
Araq
5ce8e0b5cd better docs for strutils.escape 2017-02-26 01:02:50 +01:00
Dennis Felsing
4af2c26c91 Make toHex work for uints (#5423) 2017-02-24 16:48:22 +01:00
flyx
ac9c2126e6 Added BiggestUInt (#5378) 2017-02-13 11:20:07 +01:00