1 /*
2 The MIT License
3
4 Copyright (c) 2004, The Codehaus
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of
7 this software and associated documentation files (the "Software"), to deal in
8 the Software without restriction, including without limitation the rights to
9 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 of the Software, and to permit persons to whom the Software is furnished to do
11 so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 package org.codehaus.mojo.scmchangelog.changelog.log.grammar;
25
26 import java.util.regex.Matcher;
27
28 import java.util.regex.Pattern;
29 import org.codehaus.mojo.scmchangelog.changelog.log.ScmGrammar;
30
31 /**
32 * Abstract grammar to be used as an helper class.
33 * @author ehsavoie
34 * @version $Id: AbstractScmGrammar.java 10686 2009-09-12 20:42:13Z ehsavoie $
35 */
36 public abstract class AbstractScmGrammar
37 implements ScmGrammar
38 {
39 /**
40 * The Regexp Pattern for finding comments.
41 */
42 private static final Pattern COMMENT_PATTERN = Pattern.compile( "/\\*([^*]|(\\*+([^*/])))*\\*+/",
43 Pattern.CASE_INSENSITIVE );
44
45 /**
46 * Removes the comments from the content.
47 * @param content which comments will be removed.
48 * @return the content without the comments.
49 */
50 public String removeComments( String content )
51 {
52 Matcher matcher = COMMENT_PATTERN.matcher( content );
53 String tempExpression = content;
54 boolean hasMore = matcher.find();
55 while ( hasMore )
56 {
57 tempExpression = tempExpression.substring( 0, matcher.start() )
58 + tempExpression.substring( matcher.end() , tempExpression.length() );
59 matcher = COMMENT_PATTERN.matcher( tempExpression );
60 hasMore = matcher.find();
61 }
62 return tempExpression;
63 }
64 }