Tools: add edit to use std min/max instead of MIN2/MAX2 macros
This commit is contained in:
parent
aaf05c2497
commit
afd5faceec
|
@ -1076,6 +1076,41 @@ class edit_generators:
|
|||
|
||||
return edits
|
||||
|
||||
class use_std_min_max(EditGenerator):
|
||||
"""
|
||||
Use `std::min` & `std::max` instead of `MIN2`, `MAX2` macros:
|
||||
|
||||
Replace:
|
||||
MAX2(a, b)
|
||||
With:
|
||||
std::max(a, b)
|
||||
"""
|
||||
is_default = True
|
||||
|
||||
@staticmethod
|
||||
def edit_list_from_file(source: str, data: str, _shared_edit_data: Any) -> List[Edit]:
|
||||
edits: List[Edit] = []
|
||||
|
||||
# The user might include C & C++, if they forget, it is better not to operate on C.
|
||||
if source.lower().endswith((".h", ".c")):
|
||||
return edits
|
||||
|
||||
for src, dst in (
|
||||
("MIN2", "std::min"),
|
||||
("MAX2", "std::max"),
|
||||
):
|
||||
for match in re.finditer(
|
||||
(r"\b(" + src + r")\("),
|
||||
data,
|
||||
):
|
||||
edits.append(Edit(
|
||||
span=match.span(1),
|
||||
content=dst,
|
||||
content_fail='__ALWAYS_FAIL__',
|
||||
))
|
||||
|
||||
return edits
|
||||
|
||||
class use_str_sizeof_macros(EditGenerator):
|
||||
"""
|
||||
Use `STRNCPY` & `SNPRINTF` macros:
|
||||
|
|
Loading…
Reference in New Issue