Take into account user-provided inline function patterns

This commit is contained in:
laurens
2019-11-13 12:44:40 +01:00
parent 73fa7a6bb2
commit 8a7c45c20b
+10
View File
@@ -114,8 +114,18 @@ class CMockHeaderParser
/(static\s+inline|inline\s+static)\s*/, # Last part (\s*) is just to remove whitespaces (only to prettify the output)
/(\bstatic\b|\binline\b)\s*/, # Last part (\s*) is just to remove whitespaces (only to prettify the output)
]
user_regex_formats = []
square_bracket_pair_regex_format = /\{[^\{\}]*\}/ # Regex to match one whole block enclosed by two square brackets
@inline_function_patterns.each { |user_format_string|
user_regex = Regexp.new(Regexp.quote(user_format_string))
cleanup_spaces_after_user_regex = /\s*/
user_regex_formats << Regexp.new((user_regex.source) + cleanup_spaces_after_user_regex.source) # Convert user provided string to regex pattern
}
# We first parse the user regex to avoid removing basic inline keywords that the user regex depends upon
inline_function_regex_formats = user_regex_formats + inline_function_regex_formats
# let's clean up the encoding in case they've done anything weird with the characters we might find
source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil)