Static analysis - custom rule for ascii characters >127
Hi,
I have to create a custom rule that checks that ascii characters > 127 are not present.
I have some issues doing it.
Can someone help me?
The rule is:
"Define identifiers shall be as following:
< DEFINE_NAME > = D _ < USER_NAME >
Where:
< USER_NAME > length is at most 12 characters and not composed by ascii characters > 127."
Thanks.
Comments
-
You can try to use the following python method:
use correct indentations, that were removed automatically in this post
def checkCharValue( node, context ):
stringName = node.getProperty( 'name' )
for i in range(0, len(stringName)):
charName = stringName[i]
charValue = ord(stringName[i])
if charValue > 127:
context.report("String %s contains character '%s' with value greater than 127: (%d)" % (stringName, charName, charValue))
return 1This method can be added to the appropriate node (in C++Text rule) e.g. for 'String Constant'.
The example of rule:1