Tommy Rogers před 6 roky
rodič
revize
b18fe1cade
1 změnil soubory, kde provedl 16 přidání a 7 odebrání
  1. 16
    7
      src/main/java/HamletParser.java

+ 16
- 7
src/main/java/HamletParser.java Zobrazit soubor

@@ -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