Remove reExtended from re constructor. Fixes #5627. (#6514)

* Remove reExtended from re constructor. Fixes #5627.

* Implement `rex` procedure as requested by @Araq.
This commit is contained in:
Dominik Picheta
2017-10-20 20:43:34 +01:00
committed by Andreas Rumpf
parent bfae7bfe83
commit aa96343f1d
2 changed files with 12 additions and 7 deletions

View File

@@ -8,7 +8,9 @@
- Arrays of char cannot be converted to ``cstring`` anymore, pointers to
arrays of char can! This means ``$`` for arrays can finally exist
in ``system.nim`` and do the right thing.
- JSON: Deprecated `getBVal`, `getFNum`, and `getNum` in favour to
`getBool`, `getFloat`, `getBiggestInt`. Also `getInt` procedure was added.
- ``echo`` now works with strings that contain ``\0`` (the binary zero is not
shown) and ``nil`` strings are equal to empty strings.
- JSON: Deprecated `getBVal`, `getFNum`, and `getNum` in favour to
`getBool`, `getFloat`, `getBiggestInt`. Also `getInt` procedure was added.
- `reExtended` is no longer default for the `re` constructor in the `re`
module.

View File

@@ -13,10 +13,6 @@
## We had to de-deprecate this module since too much code relies on it
## and many people prefer its API over ``nre``'s.
##
## **Note:** The 're' proc defaults to the **extended regular expression
## syntax** which lets you use whitespace freely to make your regexes readable.
## However, this means matching whitespace requires ``\s`` or something similar.
##
## This module is implemented by providing a wrapper around the
## `PRCE (Perl-Compatible Regular Expressions) <http://www.pcre.org>`_
## C library. This means that your application will depend on the PRCE
@@ -78,7 +74,7 @@ proc finalizeRegEx(x: Regex) =
if not isNil(x.e):
pcre.free_substring(cast[cstring](x.e))
proc re*(s: string, flags = {reExtended, reStudy}): Regex =
proc re*(s: string, flags = {reStudy}): Regex =
## Constructor of regular expressions.
##
## Note that Nim's
@@ -96,6 +92,13 @@ proc re*(s: string, flags = {reExtended, reStudy}): Regex =
result.e = pcre.study(result.h, options, addr msg)
if not isNil(msg): raiseInvalidRegex($msg)
proc rex*(s: string, flags = {reStudy, reExtended}): Regex =
## Constructor for extended regular expressions.
##
## The extended means that comments starting with `#` and
## whitespace are ignored.
result = re(s, flags)
proc bufSubstr(b: cstring, sPos, ePos: int): string {.inline.} =
## Return a Nim string built from a slice of a cstring buffer.
## Don't assume cstring is '\0' terminated