Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
6cb6947b
Commit
6cb6947b
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
extmod/ure: Correctly return None when a group has no match.
See issue #1122.
parent
2a68c2c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
extmod/modure.c
+6
-0
6 additions, 0 deletions
extmod/modure.c
tests/extmod/ure_group.py
+7
-1
7 additions, 1 deletion
tests/extmod/ure_group.py
with
13 additions
and
1 deletion
extmod/modure.c
+
6
−
0
View file @
6cb6947b
...
@@ -65,6 +65,10 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
...
@@ -65,6 +65,10 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
}
}
const
char
*
start
=
self
->
caps
[
no
*
2
];
const
char
*
start
=
self
->
caps
[
no
*
2
];
if
(
start
==
NULL
)
{
// no match for this group
return
mp_const_none
;
}
return
mp_obj_new_str
(
start
,
self
->
caps
[
no
*
2
+
1
]
-
start
,
false
);
return
mp_obj_new_str
(
start
,
self
->
caps
[
no
*
2
+
1
]
-
start
,
false
);
}
}
MP_DEFINE_CONST_FUN_OBJ_2
(
match_group_obj
,
match_group
);
MP_DEFINE_CONST_FUN_OBJ_2
(
match_group_obj
,
match_group
);
...
@@ -97,6 +101,7 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
...
@@ -97,6 +101,7 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
subj
.
end
=
subj
.
begin
+
len
;
subj
.
end
=
subj
.
begin
+
len
;
int
caps_num
=
(
self
->
re
.
sub
+
1
)
*
2
;
int
caps_num
=
(
self
->
re
.
sub
+
1
)
*
2
;
mp_obj_match_t
*
match
=
m_new_obj_var
(
mp_obj_match_t
,
char
*
,
caps_num
);
mp_obj_match_t
*
match
=
m_new_obj_var
(
mp_obj_match_t
,
char
*
,
caps_num
);
memset
(
match
->
caps
,
0
,
caps_num
*
sizeof
(
char
*
));
int
res
=
re1_5_recursiveloopprog
(
&
self
->
re
,
&
subj
,
match
->
caps
,
caps_num
,
is_anchored
);
int
res
=
re1_5_recursiveloopprog
(
&
self
->
re
,
&
subj
,
match
->
caps
,
caps_num
,
is_anchored
);
if
(
res
==
0
)
{
if
(
res
==
0
)
{
m_del_var
(
mp_obj_match_t
,
char
*
,
caps_num
,
match
);
m_del_var
(
mp_obj_match_t
,
char
*
,
caps_num
,
match
);
...
@@ -135,6 +140,7 @@ STATIC mp_obj_t re_split(uint n_args, const mp_obj_t *args) {
...
@@ -135,6 +140,7 @@ STATIC mp_obj_t re_split(uint n_args, const mp_obj_t *args) {
mp_obj_t
retval
=
mp_obj_new_list
(
0
,
NULL
);
mp_obj_t
retval
=
mp_obj_new_list
(
0
,
NULL
);
const
char
**
caps
=
alloca
(
caps_num
*
sizeof
(
char
*
));
const
char
**
caps
=
alloca
(
caps_num
*
sizeof
(
char
*
));
while
(
true
)
{
while
(
true
)
{
memset
(
caps
,
0
,
caps_num
*
sizeof
(
char
*
));
int
res
=
re1_5_recursiveloopprog
(
&
self
->
re
,
&
subj
,
caps
,
caps_num
,
false
);
int
res
=
re1_5_recursiveloopprog
(
&
self
->
re
,
&
subj
,
caps
,
caps_num
,
false
);
// if we didn't have a match, or had an empty match, it's time to stop
// if we didn't have a match, or had an empty match, it's time to stop
...
...
This diff is collapsed.
Click to expand it.
tests/extmod/ure_group.py
+
7
−
1
View file @
6cb6947b
...
@@ -10,7 +10,7 @@ def print_groups(match):
...
@@ -10,7 +10,7 @@ def print_groups(match):
try
:
try
:
i
=
0
i
=
0
while
True
:
while
True
:
print
(
m
.
group
(
i
))
print
(
m
atch
.
group
(
i
))
i
+=
1
i
+=
1
except
IndexError
:
except
IndexError
:
pass
pass
...
@@ -20,3 +20,9 @@ print_groups(m)
...
@@ -20,3 +20,9 @@ print_groups(m)
m
=
re
.
match
(
r
'
([0-9]*)(([a-z]*)([0-9]*))
'
,
'
1234hello567
'
)
m
=
re
.
match
(
r
'
([0-9]*)(([a-z]*)([0-9]*))
'
,
'
1234hello567
'
)
print_groups
(
m
)
print_groups
(
m
)
# optional group that matches
print_groups
(
re
.
match
(
r
'
(a)?b(c)
'
,
'
abc
'
))
# optional group that doesn't match
print_groups
(
re
.
match
(
r
'
(a)?b(c)
'
,
'
bc
'
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment