You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@creadur.apache.org by co...@google.com on 2009/07/21 00:52:21 UTC

[apache-rat-pd] r42 commited - To prevent endless loop caused by (\\s|.*)* (more info about this pro...

Revision: 42
Author: maka82
Date: Mon Jul 20 15:51:30 2009
Log: To prevent endless loop caused by (\\s|.*)*  (more info about this  
problem can be found here:  
http://stackoverflow.com/questions/851057/how-to-prevent-regular-expression-of-hang-or-set-time-out-for-it-in-net/859074)  
I have change expression.

I have also made some changes in CPPHeuristicChecker to increase percent of  
found method. Test cases are updated.
http://code.google.com/p/apache-rat-pd/source/detail?r=42

Modified:
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/ActionScriptFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CSharpFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/DelphiFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/FortranFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/JavaFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/JavaScriptFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/PHPFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/PascalFunctionHeuristicChecker.java
   
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/VisualBasicFunctionHeuristicChecker.java
   
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CFunctionHeuristicCheckerTest.java
   
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicCheckerTest.java
   
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/JavaFunctionHeuristicCheckerTest.java

=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/ActionScriptFunctionHeuristicChecker.java	 
Mon Jun 29 16:57:33 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/ActionScriptFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -25,7 +25,8 @@
   * functionName(listOfParameters){function body} <li>function
   * functionName(listOfParameters):returnType {function body}
   *
- *  <p> More info on {@link} http://en.wikipedia.org/wiki/ActionScript
+ * <p>
+ * More info on {@link} http://en.wikipedia.org/wiki/ActionScript
   *
   * @author maka
   *
@@ -37,13 +38,14 @@
  	private static final String ACTION_SCRIPT_CLOSED_BRACKET = "\\}";

  	/**
-	 * Functions in ActionScript can exist in two ways:
-	 * <li>function functionName(listOfParameters){function body}
-	 * <li>function functionName(listOfParameters):returnType {function body}
+	 * Functions in ActionScript can exist in two ways: <li>function
+	 * functionName(listOfParameters){function body} <li>function
+	 * functionName(listOfParameters):returnType {function body}
  	 *
-	 *  <p> More info on {@link} http://en.wikipedia.org/wiki/ActionScript
+	 * <p>
+	 * More info on {@link} http://en.wikipedia.org/wiki/ActionScript
  	 */
-	private static final String ACTION_SCRIPT_FUNCTION_REGEX = "function  
+\\w+ *\\(.*\\)(( *\\: *\\w+)){0,1}\\s*\\{((\\s)|(.*))*\\}";
+	private static final String ACTION_SCRIPT_FUNCTION_REGEX = "function  
+\\w+ *\\([\\s\\S]*\\)(( *\\: *\\w+)){0,1}\\s*\\{[\\s\\S]*\\}[\n\r]*";

  	public ActionScriptFunctionHeuristicChecker(int limit) {
  		super(limit, ACTION_SCRIPT_FUNCTION_REGEX,
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CFunctionHeuristicChecker.java	 
Tue Jul  7 16:06:05 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -46,7 +46,7 @@
  	 * <li>{@link} http://www2.its.strath.ac.uk/courses/c/ <li>{@link}
  	 * http://www.greenend.org.uk/rjk/2003/03/inline.html
  	 */
-	private static final String C_FUNCTION_REGEX = "(\\w+ +\\w+  
*\\((.*)\\)(\\s)*\\{((\\s)*(.*))*\\})";
+	private static final String C_FUNCTION_REGEX = "^[\t ]*\\w+ +\\w+  
*\\([\\s\\S]*\\)(\\s)*\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match macro in C which are multilines. For
@@ -58,14 +58,14 @@
  	 * <p>
  	 * a ^= b; }
  	 */
-	private static final String C_MACRO_REGEX_1 = "(#define +\\w+  
*\\(.*\\)(\\s)*\\{(\\s|.*)*\\})";
+	private static final String C_MACRO_REGEX_1 = "#define +\\w+  
*\\([\\s\\S]*\\)(\\s)*\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match macro in C which are one-line. For  
example:
  	 * <p>
  	 * #define INCREMENT(x) x++
  	 */
-	private static final String C_MACRO_REGEX_2 = "(#define +\\w+  
*\\(.*\\).*[\\n\\r])";
+	private static final String C_MACRO_REGEX_2 = "#define +\\w+  
*\\([\\s\\S]*\\).*[\\n\\r]";

  	/**
  	 * This regular expression match macro in C which are multiline but have  
no
@@ -73,14 +73,15 @@
  	 * <p>
  	 * #define UPDBITS {s->bitb=b;s->bitk=k;}
  	 */
-	private static final String C_MACRO_REGEX_3 = "(#define +\\w+( | 
\\s)*\\{(\\s|.*)*\\})";
+	private static final String C_MACRO_REGEX_3 = "#define +\\w+( | 
\\s)*\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match macros in C. More info on: {@link }
  	 * http://www.cprogramming.com/tutorial/cpreprocessor.html
  	 */
-	private static final String C_MACRO_REGEX = C_MACRO_REGEX_1 + OR_REGEX
-			+ C_MACRO_REGEX_2 + OR_REGEX + C_MACRO_REGEX_3;
+	private static final String C_MACRO_REGEX = "(" + C_MACRO_REGEX_1 + ")"
+			+ OR_REGEX + "(" + C_MACRO_REGEX_2 + ")" + OR_REGEX + "("
+			+ C_MACRO_REGEX_3 + ")";

  	/**
  	 * This regular expression match inline functions in C which are multiline
@@ -89,25 +90,25 @@
  	 * inline void Recycle( char* aBuffer) { nsMemory::Free(aBuffer); }
  	 */

-	private static final String C_INLINE_FUNCTION_1  
= "(inline(\\s)*\\w+(\\s*)(.*)\\(.*\\)(\\s)*\\{(\\s|.*)*\\})";
+	private static final String C_INLINE_FUNCTION_1  
= "inline(\\s)*\\w+(\\s*)(.*)\\([\\s\\S]*\\)(\\s)*\\{[\\s\\S]*\\}[\n\r]*";
  	/**
  	 * This regular expression match inline functions in C which have no
  	 * parametrs.
  	 */
-	private static final String C_INLINE_FUNCTION_2  
= "(inline(\\s)*\\w+(\\s*)(.*)\\{(\\s|.*)*\\})";
+	private static final String C_INLINE_FUNCTION_2  
= "inline(\\s)*\\w+(\\s*)(.*)\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match inline functions in C. More info on :
  	 * {@link} http://www.cprogramming.com/tutorial/lesson13.html
  	 */
-	private static final String C_INLINE_FUNCTION = C_INLINE_FUNCTION_1
-			+ OR_REGEX + C_INLINE_FUNCTION_2;
+	private static final String C_INLINE_FUNCTION = "(" + C_INLINE_FUNCTION_1
+			+ ")" + OR_REGEX + "(" + C_INLINE_FUNCTION_2 + ")";

  	/**
  	 * This regular expression match functions,inline functions and macros in  
C,
  	 */
-	private static final String FUNCTION_REGEX = C_FUNCTION_REGEX + OR_REGEX
-			+ C_MACRO_REGEX + OR_REGEX + C_INLINE_FUNCTION;
+	private static final String FUNCTION_REGEX = "(" + C_FUNCTION_REGEX + ")"
+			+ OR_REGEX + C_MACRO_REGEX + OR_REGEX + C_INLINE_FUNCTION;

  	public CFunctionHeuristicChecker(int limit) {
  		super(limit, FUNCTION_REGEX, C_OPENED_BRACKET, C_CLOSED_BRACKET);
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicChecker.java	 
Tue Jul  7 16:06:05 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -34,10 +34,26 @@
  	private static final String CPP_OPENED_BRACKET = "\\{";

  	/**
-	 * This regular expression mathc functions in C++.
+	 * This regular expression match functions in C++.
  	 */
-	private static final String CPP_FUNCTION_REGEX = "^([(\\w+)]|( +))+  
+(\\w+) *\\((.*)\\)(\\s)*"
-			+ "\\{((\\s)*(.*))*\\}";
+	private static final String CPP_FUNCTION_REGEX_1 = "^[\t ]*([(\\w+)]|(  
+))+ +(\\w+) *\\([\\s\\S]*\\)(\\s)*"
+			+ "\\{[\\s\\S]*\\}[\n\r]*";
+
+	/**
+	 * This regular expression match functions in C++ which have mark "::".  
For
+	 * example:
+	 * <p>
+	 * MyType MyType::Add(const MyType & rhs) { return MyType(itsVal+
+	 * rhs.GetItsVal()); }
+	 */
+	private static final String CPP_FUNCTION_REGEX_2 = "^[\t ]*(\\w+  
*){1,2}\\:\\:\\w+\\s*\\([\\s\\S]*\\)(\\s)*\\{[\\s\\S]*\\}[\n\r]*";
+
+	// TODO add regular expression which will match functions with a reference
+	// to a string as a returning type for example.
+
+	private static final String CPP_FUNCTION_REGEX = "(" +  
CPP_FUNCTION_REGEX_1
+			+ ")|(" + CPP_FUNCTION_REGEX_2 + ")";
+
  	/**
  	 * This regular expression match macros in C++ which are multilines. For
  	 * example: #define SWAP(a, b) {
@@ -48,8 +64,7 @@
  	 * <p>
  	 * a ^= b; }
  	 */
-	// TODO see why when \n is in parameters, endless loop in regex matching  
has happen!!!
-	private static final String CPP_MACRO_REGEX_1 = "#define +\\w+  
*\\(.*\\)\\s*\\{(\\s|(.*))*\\}";
+	private static final String CPP_MACRO_REGEX_1 = "#define +\\w+  
*\\([\\s\\S]*\\)\\s*\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match macro in C++ which are one-line. For
@@ -57,7 +72,7 @@
  	 * <p>
  	 * #define INCREMENT(x) x++
  	 */
-	private static final String CPP_MACRO_REGEX_2 = "#define +\\w+  
*\\(.*\\)*\\)(.*| )*[\\n\\r]";
+	private static final String CPP_MACRO_REGEX_2 = "#define +\\w+  
*\\([\\s\\S]*\\)*.*[\\n\\r]";

  	/**
  	 * This regular expression match macros in C++.
@@ -70,27 +85,44 @@
  	 * and have parametrs. For example: inline void Recycle( char* aBuffer) {
  	 * nsMemory::Free(aBuffer); }
  	 */
-	private static final String CPP_INLINE_FUNCTION_1 = "inline( |\\s)+\\w+( | 
\\s)+(.*)\\(.*\\)(\\s)*\\{(\\s|.*)*\\}";
+	private static final String CPP_INLINE_FUNCTION_1  
= "inline\\s+\\w+\\s+(.*)\\([\\s\\S]*\\)(\\s)*\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match inline functions in C++ which have no
  	 * parametrs.
  	 */
-	private static final String CPP_INLINE_FUNCTION_2 = "inline  
+\\w+(\\s)*\\{(\\s|.*)*\\}";
+	private static final String CPP_INLINE_FUNCTION_2 = "inline  
+\\w+(\\s)*\\{[\\s\\S]*\\}[\n\r]*";
+
+	/**
+	 * This regular expression matches inline functions in C++ which contains
+	 * mark "::". For example:inline size_t SearchResultMessageArg::nTried() {
+	 * return filename_.size(); }
+	 *
+	 */
+	private static final String CPP_INLINE_FUNCTION_3  
= "inline\\s+\\w+\\s+\\w+\\:\\:\\w+\\s*\\([\\s\\S]*\\)(\\s)*\\{[\\s\\S]*\\}[\n\r]*";
+
+	/**
+	 * This regular expression matches inline functions in C++ which contains
+	 * mark "::" and,after parameters, key word const. For example: inline
+	 * size_t SearchResultMessageArg::nTried() const{ return  
filename_.size();}
+	 */
+	private static final String CPP_INLINE_FUNCTION_4  
= "inline\\s+\\w+\\s+\\w+\\:\\:\\w+\\s*\\([\\s\\S]*\\)  
*const(\\s)*\\{[\\s\\S]*\\}[\n\r]*";

  	/**
  	 * This regular expression match inline functions in C++.
  	 */
  	private static final String CPP_INLINE_FUNCTION = "("
  			+ CPP_INLINE_FUNCTION_1 + ")" + OR_REGEX + "("
-			+ CPP_INLINE_FUNCTION_2 + ")";
+			+ CPP_INLINE_FUNCTION_2 + ")" + OR_REGEX + "("
+			+ CPP_INLINE_FUNCTION_3 + ")" + OR_REGEX + "("
+			+ CPP_INLINE_FUNCTION_4 + ")";

  	/**
  	 * This regular expression match functions,inline functions and macros in
  	 * C++,
  	 */
-	private static final String FUNCTION_REGEX = "(" + CPP_FUNCTION_REGEX  
+ ")"
-			+ OR_REGEX + CPP_MACRO_REGEX + OR_REGEX + CPP_INLINE_FUNCTION;
+	private static final String FUNCTION_REGEX = CPP_FUNCTION_REGEX + OR_REGEX
+			+ CPP_MACRO_REGEX + OR_REGEX + CPP_INLINE_FUNCTION;

  	public CPPFunctionHeuristicChecker(int limit) {
  		super(limit, FUNCTION_REGEX, CPP_OPENED_BRACKET, CPP_CLOSED_BRACKET);
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CSharpFunctionHeuristicChecker.java	 
Mon Jun 29 16:57:33 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/CSharpFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -35,8 +35,8 @@
  	 * This is regular expression for C# function matching .
  	 * More info on: {@link}  
http://en.wikipedia.org/wiki/C_Sharp_(programming_language)
  	 */
-	private static final String C_SHARP_FUNCTION_REGEX  
= "^[(public)(protected)(private)(static)(void)(abstract)\\w+]*  
+(.*)\\((.*)\\)(\\s)*"
-			+ "\\{((\\s)*(.*))*\\}";
+	private static final String C_SHARP_FUNCTION_REGEX = "^[\t  
]*[(public)(protected)(private)(static)(void)(abstract)\\w+]*  
+(.*)\\([\\s\\S]*\\)(\\s)*"
+			+ "\\{[\\s\\S]*\\}[\n\r]*";

  	public CSharpFunctionHeuristicChecker(int limit) {
  		super(limit, C_SHARP_FUNCTION_REGEX, C_SHARP_OPENED_BRACKET,
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/DelphiFunctionHeuristicChecker.java	 
Tue Jul  7 16:06:05 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/DelphiFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -37,19 +37,19 @@
  	/**
  	 * This regular expression matches functions in Delphi.
  	 */
-	private static final String DELPHI_FUNCTION_REGEX = "((?i:function)  
+(.*)(\\((.*)\\))*(\\s)*\\: *\\w+  
*;(\\s)*(?i:BEGIN)((\\s)*(.*))*(?i:END;))";
+	private static final String DELPHI_FUNCTION_REGEX = "(?i:function)  
+(.*)(\\([\\s\\S]*\\))*(\\s)*\\: *\\w+  
*;(\\s)*(?i:BEGIN)[\\s\\S]*(?i:END;)[\n\r]*";

  	/**
  	 * This regular expression matches procedures in Delphi.
  	 */
-	private static final String DELPHI_PROCEDURE_REGEX = "((?i:procedure)  
+(.*)(\\((.*)\\))*(\\s)*;(\\s)*(?i:BEGIN)((\\s)*(.*))*(?i:END;))";
+	private static final String DELPHI_PROCEDURE_REGEX = "(?i:procedure)  
+(.*)(\\([\\s\\S]*\\))*(\\s)*;(\\s)*(?i:BEGIN)[\\s\\S]*(?i:END;)[\n\r]*";

  	/**
  	 * This regular expression matches subroutines in Delphi-both functions  
and
  	 * procedures.
  	 */
-	private static final String DELPHI_SUBROUTINE_REGEX =  
DELPHI_FUNCTION_REGEX
-			+ "|" + DELPHI_PROCEDURE_REGEX;
+	private static final String DELPHI_SUBROUTINE_REGEX = "("
+			+ DELPHI_FUNCTION_REGEX + ")|(" + DELPHI_PROCEDURE_REGEX + ")";

  	public DelphiFunctionHeuristicChecker(int limit) {
  		super(limit, DELPHI_SUBROUTINE_REGEX, DELPHI_OPENED_BRACKET,
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/FortranFunctionHeuristicChecker.java	 
Sun Jul 12 17:28:44 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/FortranFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -124,7 +124,7 @@
  	boolean isFortranFunction(String codeToBeChecked, String functionHeader,
  			String functionEndRegex) {
  		boolean toret = false;
-		String functionRegex = functionHeader + "(\\s|(.*))*"
+		String functionRegex = functionHeader + "[\\s\\S]*"
  				+ functionEndRegex;
  		System.out.println(functionRegex);
  		Pattern p = Pattern.compile(functionRegex, Pattern.MULTILINE);
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/JavaFunctionHeuristicChecker.java	 
Sun Jul 12 17:28:44 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/JavaFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -40,8 +40,8 @@
  	 * http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html
  	 *
  	 */
-	private static final String JAVA_FUNCTION_REGEX = "^[\t ]*([(\\w+)<>]|(  
+))+ +(\\w+) *\\((.*)\\) *(throws +\\w+)*\\s*"
-			+ "\\{((\\s)*(.*))*\\}[\n\r]*";
+	private static final String JAVA_FUNCTION_REGEX = "^[\t  
]*([(\\w+)<>\\[\\]]|( +))+ +(\\w+) *\\([\\s\\S]*\\) *(throws +\\w+)*\\s*"
+			+ "\\{[\\s\\S]*\\}[\n\r]*";

  	public JavaFunctionHeuristicChecker(int limit) {
  		super(limit, JAVA_FUNCTION_REGEX, JAVA_OPENED_BRACKET,
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/JavaScriptFunctionHeuristicChecker.java	 
Mon Jun 29 16:57:33 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/JavaScriptFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -38,7 +38,7 @@
  	 * http://www.w3schools.com/jS/js_functions.asp
  	 *
  	 */
-	private static final String JAVA_SCRIPT_FUNCTION_REGEX = "function +\\w+  
*\\(.*\\)\\s*\\{((\\s)|(.*))*\\}";
+	private static final String JAVA_SCRIPT_FUNCTION_REGEX = "function +\\w+  
*\\([\\s\\S]*\\)\\s*\\{[\\s\\S]*\\}[\n\r]*";

  	public JavaScriptFunctionHeuristicChecker(int limit) {
  		super(limit, JAVA_SCRIPT_FUNCTION_REGEX, JAVA_SCRIPT_OPENED_BRACKET,
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/PHPFunctionHeuristicChecker.java	 
Mon Jun 29 16:57:33 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/PHPFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -35,7 +35,7 @@
  	 * This regular expression match PHP functions. More info about functions  
in PHP on:
  	 * {@link} http://www.w3schools.com/PHP/php_functions.asp
  	 */
-	private static final String PHP_FUNCTION_REGEX = "function +\\w+  
*\\(.*\\)\\s*\\{((\\s)*(.*))*\\}";
+	private static final String PHP_FUNCTION_REGEX = "function +\\w+  
*\\([\\s\\S]*\\)\\s*\\{[\\s\\S]*\\}[\n\r]*";

  	public PHPFunctionHeuristicChecker(int limit) {
  		super(limit, PHP_FUNCTION_REGEX, PHP_OPENED_BRACKET, PHP_CLOSED_BRACKET);
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/PascalFunctionHeuristicChecker.java	 
Tue Jul  7 16:06:05 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/PascalFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -31,17 +31,29 @@

  	private static final String PASCAL_CLOSED_BRACKET = "(?i:END)";
  	private static final String PASCAL_OPENED_BRACKET = "(?i:BEGIN)";
+
+	/**
+	 * This regular expression match functions in Pascal.
+	 */
+	private static final String PASCAL_FUNCTION_REGEX = "(?i:function)  
+(.*)\\([\\s\\S]*\\)(\\s)*\\: *\\w+ *;(\\s)*(?i:BEGIN)[\\s\\S]*(?i:END;)";
+
+	/**
+	 * This regular expression match procedures in Pascal.
+	 */
+	private static final String PASCAL_PROCEDURE_REGEX = "(?i:procedure)  
+(.*)\\([\\s\\S]*\\)(\\s)*;(\\s)*(?i:BEGIN)[\\s\\S]*(?i:END;)";
+
  	/**
  	 * This regular expression matches procedures and functions in Pascal.  
Since
  	 * Pascal is case-insensitive program language the regular expression is
  	 * written in that way that it is case-insensitive for key words -
  	 * procedure, function, begin and end. For example: BEGIN,BeGiN and begin
-	 * are treated are equal.
+	 * are treated as equal.
  	 */
-	private static final String PASCAL_FUNCTION_REGEX = "((?i:procedure)  
+(.*)\\((.*)\\)(\\s)*;(\\s)*(?i:BEGIN)((\\s)*(.*))*(?i:END;))| 
((?i:function) +(.*)\\((.*)\\)(\\s)*\\: *\\w+  
*;(\\s)*(?i:BEGIN)((\\s)*(.*))*(?i:END;))";
+	private static final String PASCAL_SUBPROGRAM_REGEX = "("
+			+ PASCAL_FUNCTION_REGEX + ")|(" + PASCAL_PROCEDURE_REGEX + ")";

  	public PascalFunctionHeuristicChecker(int limit) {
-		super(limit, PASCAL_FUNCTION_REGEX, PASCAL_OPENED_BRACKET,
+		super(limit, PASCAL_SUBPROGRAM_REGEX, PASCAL_OPENED_BRACKET,
  				PASCAL_CLOSED_BRACKET);
  	}
  }
=======================================
---  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/VisualBasicFunctionHeuristicChecker.java	 
Tue Jul  7 16:06:05 2009
+++  
/trunk/src/main/java/org/apache/rat/pd/heuristic/functions/VisualBasicFunctionHeuristicChecker.java	 
Mon Jul 20 15:51:30 2009
@@ -44,7 +44,7 @@
  	 * <p>
  	 * End Function
  	 */
-	private static final String VISUAL_BASIC_FUNCTION_REGEX_1  
= "((?i:private)|(?i:public)) +Function +\\w+ *\\(.*\\) *(As)  
+\\w+(\\s|.*)*End +Function";
+	private static final String VISUAL_BASIC_FUNCTION_REGEX_1  
= "((?i:private)|(?i:public)) +Function +\\w+ *\\([\\s\\S]*\\) *(As)  
+\\w+[\\s\\S]*End +Function[\n\r]*";

  	/**
  	 * This regular expression match functions in Visual Basic which don't  
have
@@ -56,7 +56,7 @@
  	 * <p>
  	 * End Function
  	 */
-	private static final String VISUAL_BASIC_FUNCTION_REGEX_2 = "Function  
+\\w+ *\\(.*\\) *(As) +\\w+(\\s|.*)*End +Function";
+	private static final String VISUAL_BASIC_FUNCTION_REGEX_2 = "Function  
+\\w+ *\\([\\s\\S]*\\) *(As) +\\w+[\\s\\S]*End +Function[\n\r]*";

  	/**
  	 * This regular expression matches functions in Visual Basic.
@@ -75,7 +75,7 @@
  	 * <p>
  	 * End Sub
  	 */
-	private static final String VISUAL_BASIC_SUBROUTINES_REGEX_1  
= "((?i:private)|(?i:public)) +Sub +\\w+ *\\(.*\\)(\\s|.*)*End +Sub";
+	private static final String VISUAL_BASIC_SUBROUTINES_REGEX_1  
= "((?i:private)|(?i:public)) +Sub +\\w+ *\\([\\s\\S]*\\)[\\s\\S]*End  
+Sub[\n\r]*";

  	/**
  	 * This regular expression match subroutines in Visual Basic which do not
@@ -87,7 +87,7 @@
  	 * <p>
  	 * End Sub
  	 */
-	private static final String VISUAL_BASIC_SUBROUTINES_REGEX_2 = "Sub +\\w+  
*\\(.*\\)(\\s|.*)*End +Sub";
+	private static final String VISUAL_BASIC_SUBROUTINES_REGEX_2 = "Sub +\\w+  
*\\([\\s\\S]*\\)[\\s\\S]*End +Sub[\n\r]*";

  	/**
  	 * This regular expression matches subroutines in Visual Basic.
=======================================
---  
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CFunctionHeuristicCheckerTest.java	 
Sun Jul 12 17:28:44 2009
+++  
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CFunctionHeuristicCheckerTest.java	 
Mon Jul 20 15:51:30 2009
@@ -52,7 +52,7 @@
  	private static final String SIMPLE_INLINE_FUNCTION_5 = "inline  
nsChangeHint NS_CombineHint(nsChangeHint aH1, nsChangeHint aH2) {\n"
  			+ "  return (nsChangeHint)(aH1 | aH2);\n" + "}";

-	private static final String SIMPLE_FUNCTION_5 = "something void name()  
{}";
+	private static final String SIMPLE_FUNCTION_5 = "something\nvoid name()  
{}";
  	private static final String SIMPLE_FUNCTION_5_SUGGESTED = "void name()  
{}";
  	private static final String INVALID_FUNCTION_2 = "type name   (){}  
something";
  	private static final String INVALID_FUNCTION_3 = "void name(){    
something{}";
=======================================
---  
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicCheckerTest.java	 
Sun Jul 12 17:28:44 2009
+++  
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/CPPFunctionHeuristicCheckerTest.java	 
Mon Jul 20 15:51:30 2009
@@ -28,7 +28,7 @@
  	private CPPFunctionHeuristicChecker checker;

  	private static final String SIMPLE_FUNCTION_1 = "void name (){}";
-	private static final String SIMPLE_FUNCTION_2 = "public void name  (int  
prom1  ,  string prom 2) {\n something; \n}";
+	private static final String SIMPLE_FUNCTION_2 = "public void name  (int  
prom1  , \n string prom 2) {\n something; \n}";
  	private static final String SIMPLE_FUNCTION_3 = "void BubbleSort(apvector  
<int> &num)\n"
  			+ "{\n"
  			+ "      int i, j, flag = 1;    // set flag to 1 to start first pass\n"
@@ -51,14 +51,23 @@
  			+ "     return;   //arrays are passed to functions by address; nothing  
is returned\n"
  			+ "}";

-	private static final String SIMPLE_MACRO_FUNCTION_1 = "#define vecswap(a,  
b, n)        if ((n) > 0) swapfunc((char *)a, (char *)b, (int)n,  
swaptype)\n";
+
+
+	private static final String SIMPLE_FUNCTION_4  
= "MyClass::MyClass(MyClass&)\n"
+			+ "{\n"
+			+ "    std::cout << \"Simple Cat Constructor...\n\";\n"
+			+ "    itsAge = 1;\n" + "}";
+	private static final String SIMPLE_FUNCTION_5 = "MyType MyType::Add(const  
MyType & rhs)\n"
+			+ " {\n" + "     return MyType(itsVal+ rhs.GetItsVal());\n" + " }";
+
+	private static final String SIMPLE_MACRO_FUNCTION_1 = "#define vecswap(a,  
\nb, n)        if ((n) > 0) swapfunc((char *)a, (char *)b, (int)n,  
swaptype)\n";
  	private static final String SIMPLE_MACRO_FUNCTION_2 = "#define vecswap(a,  
b, n) if ((n) > 0) swapfunc((char *)a, (char *)b, (int)n, swaptype)\n";
  	private static final String SIMPLE_MACRO_FUNCTION_3 = "#define  
maxOfTwoParametrs(a,b) \n"
  			+ "       {\n typeof (a) _a = (a); \n"
  			+ "           typeof (b) _b = (b); \n"
  			+ "         _a > _b ? _a : _b; }";
  	private static final String SIMPLE_MACRO_FUNCTION_4 = "#define  
VFTDELTA_VAL()      0,\n";
-	private static final String SIMPLE_MACRO_FUNCTION_5 = "#define  
swap_code(TYPE, parmi, parmj, n) {               \n"
+	private static final String SIMPLE_MACRO_FUNCTION_5 = "#define  
swap_code(TYPE*, parmi$, parmj, n) {               \n"
  			+ "        long i = (n) / sizeof (TYPE);                   \n"
  			+ "        register TYPE *pi = (TYPE *) (parmi);           \n"
  			+ "        register TYPE *pj = (TYPE *) (parmj);           \n"
@@ -71,14 +80,32 @@

  	private static final String SIMPLE_INLINE_FUNCTION_1 = "inline PRInt32  
MinInt(PRInt32 x, PRInt32 y)\n"
  			+ " {\n" + "     return NS_MIN(x, y);\n" + "  }";
+
  	private static final String SIMPLE_INLINE_FUNCTION_2 = "inline PRInt32  
Min_Int(PRInt32 x, PRInt32 y)\n"
  			+ " {\n" + "     return NS_MIN(x, y);\n" + "  }";
+
  	private static final String SIMPLE_INLINE_FUNCTION_3 = "inline void\n"
  			+ "glMultMatrix( const Imath::M44f* m )\n" + "{\n"
  			+ "    throwBadMatrix (*m);\n"
  			+ "    glMultMatrixf( (GLfloat*)(*m)[0] );\n" + "}";

-	private static final String INVALID_FUNCTION_1 = "int sum(){}\n";
+	private static final String SIMPLE_INLINE_FUNCTION_4 = "inline\n"
+			+ "size_t SearchResultMessageArg::nTried() const\n" + "{\n"
+			+ "  return filename_.size();\n" + "}";
+
+	private static final String SIMPLE_INLINE_FUNCTION_5 = "inline void  
A::UpdateX(int newX)\n"
+			+ "	\n"
+			+ "{\n"
+			+ "		\n"
+			+ "  if (g_y != 0 && m_x < newX)\n"
+			+ "  \n"
+			+ "  {\n"
+			+ "	  \n"
+			+ "    m_x = newX;\n"
+			+ "    \n"
+			+ "  }\n" + "  \n" + "}";
+
+	private static final String INVALID_FUNCTION_1 = "int sum(){}\n  
something";
  	private static final String INVALID_FUNCTION_2 = "void name(int  
pom)\n{\nsomething{}";

  	private static final String SIMPLE_MACRO_FUNCTION_6 = "something #define  
name(){}";
@@ -102,60 +129,87 @@
  	 * .
  	 */
  	public void testCheckByHeuristic() {
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_1).isCheckOnInternetNeaded());
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_2).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_1).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_2).isCheckOnInternetNeaded());
  		assertTrue(
  				"This is a function for bubble sort- see  
http://mathbits.com/mathbits/compsci/Arrays/Bubble.htm",
-				checker.checkByHeuristic(SIMPLE_FUNCTION_3).isCheckOnInternetNeaded());
+				checker.checkByHeuristic(SIMPLE_FUNCTION_3)
+						.isCheckOnInternetNeaded());
+
+		assertTrue(
+				"This is a function for bubble sort- see  
http://mathbits.com/mathbits/compsci/Arrays/Bubble.htm",
+				checker.checkByHeuristic(SIMPLE_FUNCTION_4)
+						.isCheckOnInternetNeaded());
+
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_5).isCheckOnInternetNeaded());

  		assertFalse(
-				"There must be false return because there is something after  
function-\n",
-				 
checker.checkByHeuristic(INVALID_FUNCTION_1).isCheckOnInternetNeaded());
+				"There must be false return because there is something after function",
+				checker.checkByHeuristic(INVALID_FUNCTION_1)
+						.isCheckOnInternetNeaded());
  		assertFalse(
  				"There must be false return because the numbers of { and } are not  
equal so this function is not entire",
-				 
checker.checkByHeuristic(INVALID_FUNCTION_1).isCheckOnInternetNeaded());
+				checker.checkByHeuristic(INVALID_FUNCTION_2)
+						.isCheckOnInternetNeaded());

  	}

  	public void testByHeuristicCheckerMacro() {

-		assertTrue("This is valid macro", checker
-				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_1).isCheckOnInternetNeaded());
+		assertTrue("This is valid macro", checker.checkByHeuristic(
+				SIMPLE_MACRO_FUNCTION_1).isCheckOnInternetNeaded());
  		assertTrue(
  				"This is a valid macro which have to many parametrs to write them in  
one line",
-				 
checker.checkByHeuristic(SIMPLE_MACRO_FUNCTION_2).isCheckOnInternetNeaded());
+				checker.checkByHeuristic(SIMPLE_MACRO_FUNCTION_2)
+						.isCheckOnInternetNeaded());
  		assertTrue("This is a valid macro whish is multiline", checker
-				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_3).isCheckOnInternetNeaded());
+				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_3)
+				.isCheckOnInternetNeaded());
  		assertTrue("This is a valid macro wwhish is multiline", checker
-				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_4).isCheckOnInternetNeaded());
+				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_4)
+				.isCheckOnInternetNeaded());
  		assertTrue("This is a valid macro whish is multiline", checker
-				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_5).isCheckOnInternetNeaded());
-		HeuristicCheckerResult result =  
checker.checkByHeuristic(SIMPLE_MACRO_FUNCTION_6);
-		assertTrue(
-				"This string consist macro",
-				result.isCheckOnInternetNeaded());
-		assertEquals("Suggested macro must look like this:",
-				SIMPLE_MACRO_FUNCTION_6_SUGGESTED,  
result.getCodeSuggestedToBeChecked());
+				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_5)
+				.isCheckOnInternetNeaded());
+		HeuristicCheckerResult result = checker
+				.checkByHeuristic(SIMPLE_MACRO_FUNCTION_6);
+		assertTrue("This string consist macro", result
+				.isCheckOnInternetNeaded());
+		assertEquals("Suggested macro must look like this:",
+				SIMPLE_MACRO_FUNCTION_6_SUGGESTED, result
+						.getCodeSuggestedToBeChecked());
  		assertFalse(
  				"There must be false returned because the numbers of open and closed  
brackets are not equal",
-				 
checker.checkByHeuristic(INVALID_MACRO_FUNCTION_2).isCheckOnInternetNeaded());
+				checker.checkByHeuristic(INVALID_MACRO_FUNCTION_2)
+						.isCheckOnInternetNeaded());

  	}

  	public void testByHeuristicCheckerInlineFunctions() {

  		assertTrue("This is a valid multiline inline function", checker
-				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_1).isCheckOnInternetNeaded());
+				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_1)
+				.isCheckOnInternetNeaded());
  		assertTrue("This is a valid multiline inline function", checker
-				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_2).isCheckOnInternetNeaded());
+				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_2)
+				.isCheckOnInternetNeaded());
  		assertTrue("This is a valid multiline inline function", checker
-				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_3).isCheckOnInternetNeaded());
+				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_3)
+				.isCheckOnInternetNeaded());
+		assertTrue("This is a valid multiline inline function", checker
+				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_4)
+				.isCheckOnInternetNeaded());
+		assertTrue("This is a valid multiline inline function", checker
+				.checkByHeuristic(SIMPLE_INLINE_FUNCTION_5)
+				.isCheckOnInternetNeaded());

  		assertFalse(
  				"There must be false returned because the numbers of open and closed  
brackets are not equal",
-				 
checker.checkByHeuristic(INVALID_INLINE_FUNCTION_1).isCheckOnInternetNeaded());
+				checker.checkByHeuristic(INVALID_INLINE_FUNCTION_1)
+						.isCheckOnInternetNeaded());

  	}

=======================================
---  
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/JavaFunctionHeuristicCheckerTest.java	 
Sun Jul 12 17:28:44 2009
+++  
/trunk/src/test/java/org/apache/rat/pd/heuristic/functions/JavaFunctionHeuristicCheckerTest.java	 
Mon Jul 20 15:51:30 2009
@@ -40,19 +40,21 @@
  			+ "\nreturn super.getClass();\n" + "}";
  	private static final String SIMPLE_FUNCTION_5 = "public static String  
getClass  (){if (this){ \n"
  			+ "return 0; }}";
-
+
  	private static final String SIMPLE_FUNCTION_6 = "public static String  
getFile() throws FileNotFoundException{"
-		+ "return super.getFile();" + "}";
+			+ "return super.getFile();" + "}";
  	private static final String SIMPLE_FUNCTION_7 = "something\npublic static  
String getClass(){"
-		+ "return super.getClass();" + "}";
+			+ "return super.getClass();" + "}";
  	private static final String SIMPLE_FUNCTION_7_SUGGESTION = "public static  
String getClass(){"
-		+ "return super.getClass();" + "}";
-
+			+ "return super.getClass();" + "}";
+
+	private static final String SIMPLE_FUNCTION_8 = "public static  
List<String> getList(){"
+			+ "return super.getList();" + "}";;
+
  	private static final String INVALID_FUNCTION_1 = "public static String  
getClass{\n"
  			+ "return super.getClass();\n" + "}";
  	private static final String INVALID_FUNCTION_2 = "public static String  
getClass();";
  	private static final String INVALID_FUNCTION_3 = "public static String  
getClass(){if(this) {return o;};";
-

  	/*
  	 * (non-Javadoc)
@@ -69,29 +71,33 @@
  	 * .
  	 */
  	public void testCheckByHeuristic() {
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_1).isCheckOnInternetNeaded());
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_2).isCheckOnInternetNeaded());
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_3).isCheckOnInternetNeaded());
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_4).isCheckOnInternetNeaded());
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_5).isCheckOnInternetNeaded());
-		assertTrue("This is a function", checker
-				.checkByHeuristic(SIMPLE_FUNCTION_6).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_1).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_2).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_3).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_4).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_5).isCheckOnInternetNeaded());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_6).isCheckOnInternetNeaded());
  		HeuristicCheckerResult result = checker
-		.checkByHeuristic(SIMPLE_FUNCTION_7);
+				.checkByHeuristic(SIMPLE_FUNCTION_7);
  		assertTrue("This is a function", result.isCheckOnInternetNeaded());
-		assertEquals("suggested code must look like  
this",SIMPLE_FUNCTION_7_SUGGESTION, result.getCodeSuggestedToBeChecked());
-
-		assertFalse("This is not a valid  function", checker
-				.checkByHeuristic(INVALID_FUNCTION_1).isCheckOnInternetNeaded());
-		assertFalse("This is not a valid  function", checker
-				.checkByHeuristic(INVALID_FUNCTION_2).isCheckOnInternetNeaded());
-		assertFalse("This is not a valid  function", checker
-				.checkByHeuristic(INVALID_FUNCTION_3).isCheckOnInternetNeaded());
+		assertEquals("suggested code must look like this",
+				SIMPLE_FUNCTION_7_SUGGESTION, result
+						.getCodeSuggestedToBeChecked());
+		assertTrue("This is a function", checker.checkByHeuristic(
+				SIMPLE_FUNCTION_8).isCheckOnInternetNeaded());
+
+		assertFalse("This is not a valid  function", checker.checkByHeuristic(
+				INVALID_FUNCTION_1).isCheckOnInternetNeaded());
+		assertFalse("This is not a valid  function", checker.checkByHeuristic(
+				INVALID_FUNCTION_2).isCheckOnInternetNeaded());
+		assertFalse("This is not a valid  function", checker.checkByHeuristic(
+				INVALID_FUNCTION_3).isCheckOnInternetNeaded());

  	}