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' >>> _DropCommonSuffixes('foo/foo
(filename)
| 4940 | |
| 4941 | |
| 4942 | def _DropCommonSuffixes(filename): |
| 4943 | """Drops common suffixes like _test.cc or -inl.h from filename. |
| 4944 | |
| 4945 | For example: |
| 4946 | >>> _DropCommonSuffixes('foo/foo-inl.h') |
| 4947 | 'foo/foo' |
| 4948 | >>> _DropCommonSuffixes('foo/bar/foo.cc') |
| 4949 | 'foo/bar/foo' |
| 4950 | >>> _DropCommonSuffixes('foo/foo_internal.h') |
| 4951 | 'foo/foo' |
| 4952 | >>> _DropCommonSuffixes('foo/foo_unusualinternal.h') |
| 4953 | 'foo/foo_unusualinternal' |
| 4954 | |
| 4955 | Args: |
| 4956 | filename: The input filename. |
| 4957 | |
| 4958 | Returns: |
| 4959 | The filename with the common suffix removed. |
| 4960 | """ |
| 4961 | for suffix in itertools.chain( |
| 4962 | ('%s.%s' % (test_suffix.lstrip('_'), ext) |
| 4963 | for test_suffix, ext in itertools.product(_test_suffixes, GetNonHeaderExtensions())), |
| 4964 | ('%s.%s' % (suffix, ext) |
| 4965 | for suffix, ext in itertools.product(['inl', 'imp', 'internal'], GetHeaderExtensions()))): |
| 4966 | if (filename.endswith(suffix) and len(filename) > len(suffix) and |
| 4967 | filename[-len(suffix) - 1] in ('-', '_')): |
| 4968 | return filename[:-len(suffix) - 1] |
| 4969 | return os.path.splitext(filename)[0] |
| 4970 | |
| 4971 | |
| 4972 | def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="default"): |
no test coverage detected