Tommy Rogers 6 лет назад
Родитель
Сommit
b18fe1cade
1 измененных файлов: 16 добавлений и 7 удалений
  1. 16
    7
      src/main/java/HamletParser.java

+ 16
- 7
src/main/java/HamletParser.java Просмотреть файл

@@ -39,17 +39,26 @@ public class HamletParser {
39 39
     }
40 40
 
41 41
     public String changeWord(String search, String replace){
42
-        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
43
-        Matcher m = patt.matcher(hamletData);
42
+        String upperCaseS = search.toUpperCase();
43
+        String upperCaseR = replace.toUpperCase();
44
+        String lowerCaseSwapped = replaceWord(search, replace, hamletData);
45
+        return replaceWord(upperCaseS, upperCaseR, lowerCaseSwapped);
46
+    }
47
+
48
+    public String replaceWord(String search, String replace, String text){
49
+        Pattern patt = Pattern.compile("\\b" +search + "\\b");
50
+        Matcher m = patt.matcher(text);
44 51
         return m.replaceAll("" + replace + "");
45 52
     }
46 53
 
47
-    public int findWord(String hamletData ,String search) {
48
-        int count = 0;
49
-        Pattern patt = Pattern.compile("\\b" +search + "\\b", Pattern.CASE_INSENSITIVE);
54
+
55
+    public int findWord(String hamletData, String search) {
56
+        Pattern patt = Pattern.compile( search , Pattern.CASE_INSENSITIVE);
50 57
         Matcher m = patt.matcher(hamletData);
51
-     while (m.find())
52
-            count++;
58
+        int count = 0;
59
+     while (m.find()) {
60
+         count++;
61
+     }
53 62
      return count;
54 63
     }
55 64