1
2
3
4
5
6
7
8
9
10
11 package com.puppycrawl.tools.checkstyle.checks.avoidescapedunicodecharacters;
12
13 import java.util.concurrent.TimeUnit;
14
15 public class InputAvoidEscapedUnicodeCharacters1 {
16
17 private String unitAbbrev2 = "\u03bcs";
18
19 private String unitAbbrev3 = "\u03bcs";
20
21 private String unitAbbrev4 = "\u03bcs";
22
23 public Object fooString() {
24 String unitAbbrev = "μs";
25 String unitAbbrev2 = "\u03bcs";
26 String unitAbbrev3 = "\u03bcs";
27 String fakeUnicode = "asd\tsasd";
28 String fakeUnicode2 = "\\u23\\u123i\\u";
29 String content = null;
30 return "\ufeff" + content;
31 }
32
33 public Object fooChar() {
34 char unitAbbrev2 = '\u03bc';
35 char unitAbbrev3 = '\u03bc';
36 char content = 0;
37 return '\ufeff' + content;
38 }
39
40 public void multiplyString() {
41 String unitAbbrev2 = "asd\u03bcsasd";
42 String unitAbbrev3 = "aBc\u03bcssdf\u03bc";
43 String unitAbbrev4 = "\u03bcaBc\u03bcssdf\u03bc";
44 String allCharactersEscaped = "\u03bc\u03bc";
45 }
46
47 private static String abbreviate(TimeUnit unit) {
48 switch (unit) {
49 case NANOSECONDS:
50 return "ns";
51 case MICROSECONDS:
52 return "\u03bcs";
53 case MILLISECONDS:
54 return "ms";
55 case SECONDS:
56 return "s";
57 case MINUTES:
58 return "min";
59 case HOURS:
60 return "h";
61 case DAYS:
62 return "d";
63 default:
64 throw new AssertionError();
65 }
66 }
67
68 static final String WHITESPACE_TABLE = ""
69 + "\u2002\u3000\r\u0085\u200A\u2005\u2000\u3000\\"
70 + "\u2029\u000B\u3000\u2008\u2003\u205F\u3000\u1680"
71 + "\u0009\u0020\u2006\u2001\u202F\u00A0\u000C\u2009"
72 + "\u3000\u2004\u3000\u3000\u2028\n\u2007\u3000";
73
74 public boolean matches(char c) {
75 switch (c) {
76 case '\t':
77 case '\n':
78 case '\013':
79 case '\f':
80 case '\r':
81 case ' ':
82 case '\u0085':
83 case '\u1680':
84 case '\u2028':
85 case '\u2029':
86 case '\u205f':
87 case '\u3000':
88 return true;
89 case '\u2007':
90 return false;
91 default:
92 return c >= '\u2000' && c <= '\u200a';
93 }
94 }
95
96 private String unitAbbrev5 = "\u03bcs";
97 private String unitAbbrev6 = "\u03bcs";
98 private String unitAbbrev7 = "\u03bcs";
99 private String unitAbbrev8 = "\u03bcs";
100
101 void foo() {
102 for (char c = '\u0000'; c < '\uffff'; c++) {
103 if (c == '\u001b' ||
104 c == '\u2014')
105 continue;
106 }
107 }
108 private String unitAbbrev9 = "\u03bcs"; int i;
109
110 private String notAUnicodeEscaped1 = "\\u1234";
111
112 private String notAUnicodeEscaped2 = "\\\\u1234";
113
114 private String onlyEscaped = "\\\u1234";
115
116 private String sumilarToEscapedByB = "b\u1234";
117 private String sumilarToEscapedCommentedByB = "b\u1234";
118 private String sumilarToEscapedByF = "f\u1234";
119 private String sumilarToEscapedCommentedByF = "f\u1234";
120 private String sumilarToEscapedByR = "r\u1234";
121 private String sumilarToEscapedCommentedByR = "r\u1234";
122 private String sumilarToEscapedByN = "n\u1234";
123 private String sumilarToEscapedCommentedByN = "n\u1234";
124 private String sumilarToEscapedByT = "t\u1234";
125 private String sumilarToEscapedCommentedByT = "t\u1234";
126 private String validEscapeWithManyUs = "t\uuuuuuuuu1234";
127 private String validEscapeWithManyUsCommented = "t\uuuuuuuuu1234";
128 }