Drops common suffixes like _test.cc or -inl.h from filename. For example: >>> _DropCommonSuffixes('foo/foo-inl.h') 'foo/foo' >>> _DropCommonSuffixes('foo/bar/foo.cc') 'foo/bar/foo' >>> _DropCommonSuffixes('foo/foo_internal.h') 'foo/foo' >>> _DropCommonS
(filename)
| 5715 | |
| 5716 | |
| 5717 | def _DropCommonSuffixes(filename): |
| 5718 | """Drops common suffixes like _test.cc or -inl.h from filename. |
| 5719 | |
| 5720 | For example: |
| 5721 | >>> _DropCommonSuffixes('foo/foo-inl.h') |
| 5722 | 'foo/foo' |
| 5723 | >>> _DropCommonSuffixes('foo/bar/foo.cc') |
| 5724 | 'foo/bar/foo' |
| 5725 | >>> _DropCommonSuffixes('foo/foo_internal.h') |
| 5726 | 'foo/foo' |
| 5727 | >>> _DropCommonSuffixes('foo/foo_unusualinternal.h') |
| 5728 | 'foo/foo_unusualinternal' |
| 5729 | |
| 5730 | Args: |
| 5731 | filename: The input filename. |
| 5732 | |
| 5733 | Returns: |
| 5734 | The filename with the common suffix removed. |
| 5735 | """ |
| 5736 | for suffix in itertools.chain( |
| 5737 | ( |
| 5738 | f"{test_suffix.lstrip('_')}.{ext}" |
| 5739 | for test_suffix, ext in itertools.product(_test_suffixes, GetNonHeaderExtensions()) |
| 5740 | ), |
| 5741 | ( |
| 5742 | f"{suffix}.{ext}" |
| 5743 | for suffix, ext in itertools.product(["inl", "imp", "internal"], GetHeaderExtensions()) |
| 5744 | ), |
| 5745 | ): |
| 5746 | if ( |
| 5747 | filename.endswith(suffix) |
| 5748 | and len(filename) > len(suffix) |
| 5749 | and filename[-len(suffix) - 1] in ("-", "_") |
| 5750 | ): |
| 5751 | return filename[: -len(suffix) - 1] |
| 5752 | return os.path.splitext(filename)[0] |
| 5753 | |
| 5754 | |
| 5755 | def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"): |
no test coverage detected