View Javadoc
1   package com.puppycrawl.tools.checkstyle.checks.avoidescapedunicodecharacters;
2   
3   import java.util.concurrent.TimeUnit;
4   
5   public class InputAvoidEscapedUnicodeCharacters {
6   
7   	private String unitAbbrev2 = "\u03bcs";
8   
9   	private String unitAbbrev3 = "\u03bcs"; // Greek letter mu
10  
11  	private String unitAbbrev4 = "\u03bcs"; // Greek letter mu
12  
13  	public Object fooString() {
14  		String unitAbbrev = "μs";
15  		String unitAbbrev2 = "\u03bcs";
16  		String unitAbbrev3 = "\u03bcs"; // Greek letter mu, "s"
17  		String fakeUnicode = "asd\tsasd";
18  		String fakeUnicode2 = "\\u23\\u123i\\u";
19  		String content = null;
20  		return "\ufeff" + content; // byte order mark
21  	}
22  
23  	public Object fooChar() {
24  		char unitAbbrev2 = '\u03bc';
25  		char unitAbbrev3 = '\u03bc'; // Greek letter mu, "s"
26  		char content = 0;
27  		return '\ufeff' + content; // byte order mark
28  	}
29  
30  	public void multiplyString() {
31  		String unitAbbrev2 = "asd\u03bcsasd";
32  		String unitAbbrev3 = "aBc\u03bcssdf\u03bc"; /* Greek letter mu, "s" */
33  		String unitAbbrev4 = "\u03bcaBc\u03bcssdf\u03bc";
34  		String allCharactersEscaped = "\u03bc\u03bc";
35  	}
36  
37  	private static String abbreviate(TimeUnit unit) {
38  		switch (unit) {
39  		case NANOSECONDS:
40  			return "ns";
41  		case MICROSECONDS:
42  			return "\u03bcs"; // μs
43  		case MILLISECONDS:
44  			return "ms";
45  		case SECONDS:
46  			return "s";
47  		case MINUTES:
48  			return "min";
49  		case HOURS:
50  			return "h";
51  		case DAYS:
52  			return "d";
53  		default:
54  			throw new AssertionError();
55  		}
56  	}
57  
58  		static final String WHITESPACE_TABLE = ""
59  				+ "\u2002\u3000\r\u0085\u200A\u2005\u2000\u3000\\"
60  				+ "\u2029\u000B\u3000\u2008\u2003\u205F\u3000\u1680"
61  				+ "\u0009\u0020\u2006\u2001\u202F\u00A0\u000C\u2009"
62  				+ "\u3000\u2004\u3000\u3000\u2028\n\u2007\u3000";
63  
64  	      public boolean matches(char c) {
65  	        switch (c) {
66  	          case '\t':
67  	          case '\n':
68  	          case '\013':
69  	          case '\f':
70  	          case '\r':
71  	          case ' ':
72  	          case '\u0085': // some comment
73  	          case '\u1680':
74  	          case '\u2028':
75  	          case '\u2029':
76  	          case '\u205f':
77  	          case '\u3000':
78  	            return true;
79  	          case '\u2007':
80  	            return false;
81  	          default:
82  	          return c >= '\u2000' && c <= '\u200a';
83  	      }
84  	 }
85  
86  	private String unitAbbrev5 = "\u03bcs"; 	// comment is separated by space + tab
87  	private String unitAbbrev6 = "\u03bcs";	// comment is separated by tab
88  	private String unitAbbrev7 = "\u03bcs";	/* comment is separated by tab */
89  	private String unitAbbrev8 = "\u03bcs"; /* comment
90  	                                           has 2 lines */
91  	void foo() {
92  		for (char c = '\u0000'; c < '\uffff'; c++) {
93  			if (c == '\u001b' ||     // ESC
94  					c == '\u2014')   // Em-Dash?
95  				continue;
96  		}
97  	}
98  	private String unitAbbrev9 = "\u03bcs"; /* comment */ int i;
99  
100 	private String notAUnicodeEscaped1 = "\\u1234";
101 
102 	private String notAUnicodeEscaped2 = "\\\\u1234";
103 
104 	private String onlyEscaped = "\\\u1234";
105 }