Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public class CheckTheWord {
  2.  
  3. public static String[] checkTheWord(String s, char zn, char zn2) {
  4. int l = 0;
  5. for (int i = 0; i < s.length(); i++) {
  6. if (s.charAt(i) == zn || s.charAt(i) == zn2) {
  7. l++;
  8. }
  9. }
  10.  
  11. String[] tStr = new String[l + 1];
  12. for (int i = 0; i < tStr.length; tStr[i++] = "") ;
  13. l = 0;
  14. for (int i = 0; i < s.length(); i++) {
  15. if (s.charAt(i) == zn || s.charAt(i) == zn2) {
  16. l++;
  17. } else {
  18. tStr[l] += s.charAt(i);
  19. }
  20. }
  21.  
  22. return tStr;
  23.  
  24.  
  25. }
  26.  
  27. public boolean isThereAvulgarWord(String lan) {
  28. // String lan = "Ala ma kota Kot_ma_Alę";
  29. String b[] = {"chuj", "choj","chój","huj", "hój", "kurwa",
  30. "kórwa","korwa","zjebanie","chujowo","chójowo","chojowo"};
  31. boolean wynik = false;
  32.  
  33. String[] tmpTStr2 = checkTheWord(lan, ' ', ',');
  34.  
  35. for (int i = 0; i < tmpTStr2.length; i++) {
  36. for (int j = 0; j < b.length; j++) {
  37.  
  38.  
  39. if (tmpTStr2[i].equals(b[j])) {
  40. return wynik = true;
  41. }
  42. }
  43. }
  44. return wynik;
  45. }
  46.  
  47. }
  48.  
  49.  
  50.  
  51. -------------------------------------------------------------------------------------------------------------------
  52.  
  53.  
  54.  
  55.  
  56. @PostMapping("/save")
  57.  
  58. public String save(Comment comment) {
  59. String text = comment.getCommentUser();
  60. CheckTheWord checkTheWord = new CheckTheWord();
  61. checkTheWord.isThereAvulgarWord(text);
  62. if(checkTheWord.isThereAvulgarWord(text)== true){
  63. return "redirect:/";
  64. }else
  65. commentRepository.save(comment);
  66. return "redirect:/allComment";
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement