MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / remove_file_prefix

Function remove_file_prefix

addons/misra.py:1428–1449  ·  view source on GitHub ↗

Remove a file path prefix from a give path. leftover directory separators at the beginning of a file after the removal are also stripped. Example: '/remove/this/path/file.c' with a prefix of: '/remove/this/path' becomes: file.c

(file_path, prefix)

Source from the content-addressed store, hash-verified

1426
1427
1428def remove_file_prefix(file_path, prefix):
1429 """
1430 Remove a file path prefix from a give path. leftover
1431 directory separators at the beginning of a file
1432 after the removal are also stripped.
1433
1434 Example:
1435 '/remove/this/path/file.c'
1436 with a prefix of:
1437 '/remove/this/path'
1438 becomes:
1439 file.c
1440 """
1441 result = None
1442 if file_path.startswith(prefix):
1443 result = file_path[len(prefix):]
1444 # Remove any leftover directory separators at the
1445 # beginning
1446 result = result.lstrip('\\/')
1447 else:
1448 result = file_path
1449 return result
1450
1451
1452class Rule():

Callers 1

isRuleSuppressedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected