|
@@ -28,7 +28,6 @@ public class HamletParser {
|
28
|
28
|
String line = scanner.nextLine();
|
29
|
29
|
result.append(line).append("\n");
|
30
|
30
|
}
|
31
|
|
-
|
32
|
31
|
scanner.close();
|
33
|
32
|
}catch(IOException e){
|
34
|
33
|
e.printStackTrace();
|
|
@@ -37,12 +36,18 @@ public class HamletParser {
|
37
|
36
|
return result.toString();
|
38
|
37
|
}
|
39
|
38
|
|
|
39
|
+ public String loadFileAndReplace(String find, String replace){
|
|
40
|
+ Pattern pattern = createRegexPattern(find);
|
|
41
|
+ Matcher matcher = createMatcherFromInput(pattern, hamletData);
|
|
42
|
+ return findReplace(matcher, replace);
|
|
43
|
+ }
|
|
44
|
+
|
40
|
45
|
public String getHamletData(){
|
41
|
46
|
return hamletData;
|
42
|
47
|
}
|
43
|
48
|
|
44
|
|
- public Pattern createRegexPattern(String regex) {
|
45
|
|
- return Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
49
|
+ public Pattern createRegexPattern(String find) {
|
|
50
|
+ return Pattern.compile(find, Pattern.CASE_INSENSITIVE);
|
46
|
51
|
}
|
47
|
52
|
|
48
|
53
|
public Matcher createMatcherFromInput(Pattern pattern, String input) {
|
|
@@ -52,4 +57,10 @@ public class HamletParser {
|
52
|
57
|
public String findReplace(Matcher matcher, String replace) {
|
53
|
58
|
return matcher.replaceAll(replace);
|
54
|
59
|
}
|
|
60
|
+
|
|
61
|
+ public boolean contains(String find, String input){
|
|
62
|
+ Pattern pattern = createRegexPattern(find);
|
|
63
|
+ Matcher matcher = createMatcherFromInput(pattern, input);
|
|
64
|
+ return matcher.find();
|
|
65
|
+ }
|
55
|
66
|
}
|