feat: add StrUtil.find_mb.
This commit is contained in:
@@ -105,7 +105,7 @@ def process(path_to_file: str):
|
||||
is_template,
|
||||
is_empty,
|
||||
)
|
||||
class_keyword_pos, _ = StrUtil.find_m(line, 'class ', 'struct ', 'union ')
|
||||
class_keyword_pos, _ = StrUtil.find_mb(line, 'class ', 'struct ', 'union ')
|
||||
assert class_keyword_pos != -1, f"path = {path_to_file}, line = '{line}'"
|
||||
|
||||
if not is_empty:
|
||||
|
||||
@@ -302,7 +302,7 @@ class reference_wrapper {
|
||||
if not in_forward_declaration_list:
|
||||
founded_cl = CppUtil.find_class_definition(line)
|
||||
if founded_cl:
|
||||
class_keyword_pos, _ = StrUtil.find_m(line, 'class ', 'struct ', 'union ')
|
||||
class_keyword_pos, _ = StrUtil.find_mb(line, 'class ', 'struct ', 'union ')
|
||||
assert class_keyword_pos != -1, f"path = {path_to_file}, line = '{line}'"
|
||||
|
||||
if not stripped_line.endswith('{};'):
|
||||
|
||||
@@ -18,7 +18,7 @@ def find_class_definition(line: str) -> str | None:
|
||||
# KEYWORD A {
|
||||
# KEYWORD A { ... }; (in single line)
|
||||
|
||||
keyword_pos, keyword = StrUtil.find_m(line, 'enum class ', 'class ', 'struct ', 'union ')
|
||||
keyword_pos, keyword = StrUtil.find_mb(line, 'enum class ', 'class ', 'struct ', 'union ')
|
||||
if keyword_pos == -1 or keyword == 'enum class ':
|
||||
return None
|
||||
|
||||
@@ -67,7 +67,7 @@ def find_class_forward_declaration(line: str) -> ForwardDeclaration | None:
|
||||
if namespace_pos != -1 and left_brace_pos != -1:
|
||||
namespace_decl = line[namespace_pos + len('namespace') : left_brace_pos].strip()
|
||||
|
||||
keyword_pos, keyword = StrUtil.find_m(line, 'class ', 'struct ', 'union ')
|
||||
keyword_pos, keyword = StrUtil.find_mb(line, 'class ', 'struct ', 'union ')
|
||||
if keyword_pos == -1:
|
||||
return None
|
||||
|
||||
|
||||
@@ -19,6 +19,20 @@ def endswith_m(con: str, *args) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def find_mb(con: str, *args) -> int: # bounded
|
||||
r_pos = -1
|
||||
r_arg = None
|
||||
for arg in args:
|
||||
matched = re.search(rf'\b{re.escape(arg)}\b', con)
|
||||
if not matched:
|
||||
continue
|
||||
pos = matched.start()
|
||||
if pos != -1 and (r_pos == -1 or pos < r_pos):
|
||||
r_pos = pos
|
||||
r_arg = arg
|
||||
return r_pos, r_arg
|
||||
|
||||
|
||||
def find_m(con: str, *args) -> int:
|
||||
r_pos = -1
|
||||
r_arg = None
|
||||
|
||||
Reference in New Issue
Block a user