File: const_std_string_by_value.py

package info (click to toggle)
widelands 2%3A1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 600,516 kB
  • sloc: cpp: 166,473; ansic: 18,683; python: 7,697; sh: 1,363; xml: 467; makefile: 45
file content (42 lines) | stat: -rw-r--r-- 1,221 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python

"""This catches std::string constants that are passed by value.

They should be passed by reference to avoid needless
construction/destruction.
"""

error_msg = 'const std::string must not be passed by value. Pass by reference!'

strip_comments_and_strings = True
regexp = r"""[\( ](?:const +std::string|std::string +const)(?: +[_a-zA-Z][_a-zA-Z0-9]*)?(?: *=.*)?(?:,(?: |$)|\))"""

forbidden = [
    '(std::string const,',
    ' std::string const abc,',
    ' std::string const abc = "abc",',
    ' std::string const = "abc",',
    ' std::string const)',
    '(const std::string,',
    ' const std::string abc,',
    ' const std::string abc = "abc",',
    ' const std::string = "abc",',
    ' const std::string)',
]

allowed = [
    '(std::string const &,'
    ' std::string const & abc,',
    ' std::string const & = "abc",',
    ' std::string const &)',
    '(const std::string &,',
    ' const std::string & abc,',
    ' const std::string & = "abc",',
    ' const std::string &)',
    ' std::string const abc;',
    ' std::string const abc = "abc";',
    ' std::string const abc("abc");',
    ' const std::string abc;',
    ' const std::string abc = "abc";',
    ' const std::string abc("abc");',
]