View Javadoc
1   /*
2   AvoidEscapedUnicodeCharacters
3   allowEscapesForControlCharacters = (default)false
4   allowByTailComment = true
5   allowIfAllCharactersEscaped = (default)false
6   allowNonPrintableEscapes = (default)false
7   
8   
9   */
10  
11  package com.puppycrawl.tools.checkstyle.checks.avoidescapedunicodecharacters;
12  
13  public class InputAvoidEscapedUnicodeCharacters5 {
14      private String a = "πŸŽ„"; // violation below
15      private String b = "\uD83E\uDD73absπŸ˜€";
16      private String c = "\uD83C\uDF84πŸ˜€\uD83C\uDF84"; // OK, allowed by trailing comment
17      // violation below
18      private String d = "\uD83C\uDF84πŸ˜€\uD83C\uDF84asdas\uD83C\uDF84abcd";
19  
20      public Object fooEmoji() {
21          String unitAbbrev = "μsΓ°πŸ˜€"; // violation below
22          String unitAbbrev2 = "\u03bcπŸ˜€";
23          String unitAbbrev3 = "πŸ˜€\u03bcs"; // Greek letter mu, "s"
24          String fakeUnicode2 = "\\u23\\u123i\\uπŸ˜€";
25          String content = null;
26          return "πŸ˜€" + content + "\u03bc"; /* OK, allowed by trailing comment */
27      }
28  
29      public boolean matches(String c) {
30          switch (c) {
31              //violation below
32              case "\u03bcπŸŽ„":
33              case "πŸŽ„\u03bc": /* OK, allowed by trailing comment */
34                  // violation below
35              case "\t\u2028":
36                  // violation below
37              case "\nπŸ˜‚\u3000":
38                  return true;
39                  // violation below
40              case "πŸ˜‚\uD83D\uDE02":
41                  return false;
42              default:
43                  return c.equals("\u2000πŸ˜‚\u2000"); // OK, allowed by trailing comment
44          }
45      }
46  }