mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Take double-quote characters into account when parsing trigraph
For now, the function parse_trigraph() defined in gobject/glib-mkenums script was not taking double-quotes characters into account: >>> parse_trigraph('name="eek, a comma"') {'name': '"eek', 'a': None} This patch take double-quotes characters into account: >>> parse_trigraph('name="eek, a comma"') {'name': 'eek, a comma'} Closes issue #65
This commit is contained in:
parent
ecbe360a38
commit
7e5607d534
@ -149,8 +149,7 @@ output = '' # Filename to write result into
|
|||||||
|
|
||||||
def parse_trigraph(opts):
|
def parse_trigraph(opts):
|
||||||
result = {}
|
result = {}
|
||||||
|
for opt in re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', opts):
|
||||||
for opt in re.split(r'\s*,\s*', opts):
|
|
||||||
opt = re.sub(r'^\s*', '', opt)
|
opt = re.sub(r'^\s*', '', opt)
|
||||||
opt = re.sub(r'\s*$', '', opt)
|
opt = re.sub(r'\s*$', '', opt)
|
||||||
m = re.search(r'(\w+)(?:=(.+))?', opt)
|
m = re.search(r'(\w+)(?:=(.+))?', opt)
|
||||||
@ -161,7 +160,7 @@ def parse_trigraph(opts):
|
|||||||
val = groups[1]
|
val = groups[1]
|
||||||
else:
|
else:
|
||||||
val = 1
|
val = 1
|
||||||
result[key] = val
|
result[key] = val.strip('"') if val is not None else None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def parse_entries(file, file_name):
|
def parse_entries(file, file_name):
|
||||||
|
@ -520,6 +520,31 @@ comment: {standard_bottom_comment}
|
|||||||
"0",
|
"0",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_with_double_quotes(self):
|
||||||
|
"""Test trigraphs with double-quoted expressions. Issue #65."""
|
||||||
|
h_contents = """
|
||||||
|
typedef enum {
|
||||||
|
FOO_VALUE /*< nick="eek, a comma" >*/
|
||||||
|
} Foo;
|
||||||
|
"""
|
||||||
|
result = self.runMkenumsWithHeader(h_contents)
|
||||||
|
self.assertEqual("", result.err)
|
||||||
|
self.assertSingleEnum(
|
||||||
|
result,
|
||||||
|
"Foo",
|
||||||
|
"foo_",
|
||||||
|
"FOO_",
|
||||||
|
"",
|
||||||
|
"FOO",
|
||||||
|
"",
|
||||||
|
"enum",
|
||||||
|
"Enum",
|
||||||
|
"ENUM",
|
||||||
|
"FOO_VALUE",
|
||||||
|
"eek, a comma",
|
||||||
|
"0",
|
||||||
|
)
|
||||||
|
|
||||||
def test_filename_basename_in_fhead_ftail(self):
|
def test_filename_basename_in_fhead_ftail(self):
|
||||||
template_contents = """
|
template_contents = """
|
||||||
/*** BEGIN file-header ***/
|
/*** BEGIN file-header ***/
|
||||||
|
Loading…
Reference in New Issue
Block a user