mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-16 22:07:25 +00:00
Extract method to remove_nested_pair_of_braces in cmock_header_parser
This commit is contained in:
+17
-19
@@ -52,21 +52,27 @@ class CMockHeaderParser
|
|||||||
|
|
||||||
private if $ThisIsOnlyATest.nil? ################
|
private if $ThisIsOnlyATest.nil? ################
|
||||||
|
|
||||||
|
def remove_nested_pairs_of_braces(source)
|
||||||
|
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
||||||
|
if (RUBY_VERSION.split('.')[0].to_i > 1)
|
||||||
|
#we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
||||||
|
r = "\\{([^\\{\\}]*|\\g<0>)*\\}"
|
||||||
|
source.gsub!(/#{r}/m, '{ }')
|
||||||
|
else
|
||||||
|
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return source
|
||||||
|
end
|
||||||
|
|
||||||
def transform_inline_functions(source)
|
def transform_inline_functions(source)
|
||||||
# let's clean up the encoding in case they've done anything weird with the characters we might find
|
# 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)
|
source = source.force_encoding("ISO-8859-1").encode("utf-8", :replace => nil)
|
||||||
|
|
||||||
source.gsub!(/(static|inline)+.*\{.*\w*\}/m) do |m|
|
source.gsub!(/(static|inline)+.*\{.*\w*\}/m) do |m|
|
||||||
m.gsub!(/(static|inline)/, '') # remove static and inline
|
m.gsub!(/(static|inline)/, '') # remove static and inline keywords
|
||||||
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
m = remove_nested_pairs_of_braces(m)
|
||||||
if (RUBY_VERSION.split('.')[0].to_i > 1)
|
|
||||||
#we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
|
||||||
r = "\\{([^\\{\\}]*|\\g<0>)*\\}"
|
|
||||||
m.gsub!(/#{r}/m, '{ }')
|
|
||||||
else
|
|
||||||
while m.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Functions having "{ }" at this point are/were inline functions,
|
# Functions having "{ }" at this point are/were inline functions,
|
||||||
# Disguise them as normal functions with the ";"
|
# Disguise them as normal functions with the ";"
|
||||||
@@ -139,15 +145,7 @@ class CMockHeaderParser
|
|||||||
"#{functype} #{$2.strip}(#{$3});"
|
"#{functype} #{$2.strip}(#{$3});"
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
|
source = remove_nested_pairs_of_braces(source)
|
||||||
if (RUBY_VERSION.split('.')[0].to_i > 1)
|
|
||||||
#we assign a string first because (no joke) if Ruby 1.9.3 sees this line as a regex, it will crash.
|
|
||||||
r = "\\{([^\\{\\}]*|\\g<0>)*\\}"
|
|
||||||
source.gsub!(/#{r}/m, '{ }')
|
|
||||||
else
|
|
||||||
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if (@treat_inlines == :include)
|
if (@treat_inlines == :include)
|
||||||
# Functions having "{ }" at this point are/were inline functions,
|
# Functions having "{ }" at this point are/were inline functions,
|
||||||
|
|||||||
Reference in New Issue
Block a user