aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputAvoidEscapedUnicodeCharacters.java
blob: f4f7509be4e0aae38bff1495f597422b00b7aaa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.puppycrawl.tools.checkstyle.checks;

import java.util.concurrent.TimeUnit;

public class InputAvoidEscapedUnicodeCharacters {

	private String unitAbbrev2 = "\u03bcs";

	private String unitAbbrev3 = "\u03bcs"; // Greek letter mu

	private String unitAbbrev4 = "\u03bcs"; // Greek letter mu

	public Object fooString() {
		String unitAbbrev = "μs";
		String unitAbbrev2 = "\u03bcs";
		String unitAbbrev3 = "\u03bcs"; // Greek letter mu, "s"
		String fakeUnicode = "asd\tsasd";
		String fakeUnicode2 = "\\u23\\u123i\\u";
		String content = null;
		return "\ufeff" + content; // byte order mark
	}

	public Object fooChar() {
		char unitAbbrev2 = '\u03bc';
		char unitAbbrev3 = '\u03bc'; // Greek letter mu, "s"
		char content = 0;
		return '\ufeff' + content; // byte order mark
	}

	public void multiplyString() {
		String unitAbbrev2 = "asd\u03bcsasd";
		String unitAbbrev3 = "aBc\u03bcssdf\u03bc"; /* Greek letter mu, "s" */
		String unitAbbrev4 = "\u03bcaBc\u03bcssdf\u03bc";
		String allCharactersEscaped = "\u03bc\u03bc";
	}

	private static String abbreviate(TimeUnit unit) {
		switch (unit) {
		case NANOSECONDS:
			return "ns";
		case MICROSECONDS:
			return "\u03bcs"; // μs
		case MILLISECONDS:
			return "ms";
		case SECONDS:
			return "s";
		case MINUTES:
			return "min";
		case HOURS:
			return "h";
		case DAYS:
			return "d";
		default:
			throw new AssertionError();
		}
	}

		static final String WHITESPACE_TABLE = ""
				+ "\u2002\u3000\r\u0085\u200A\u2005\u2000\u3000\\"
				+ "\u2029\u000B\u3000\u2008\u2003\u205F\u3000\u1680"
				+ "\u0009\u0020\u2006\u2001\u202F\u00A0\u000C\u2009"
				+ "\u3000\u2004\u3000\u3000\u2028\n\u2007\u3000";

	      public boolean matches(char c) {
	        switch (c) {
	          case '\t':
	          case '\n':
	          case '\013':
	          case '\f':
	          case '\r':
	          case ' ':
	          case '\u0085': // some comment
	          case '\u1680':
	          case '\u2028':
	          case '\u2029':
	          case '\u205f':
	          case '\u3000':
	            return true;
	          case '\u2007':
	            return false;
	          default:
	          return c >= '\u2000' && c <= '\u200a';
	      }
	 }

	private String unitAbbrev5 = "\u03bcs"; 	// comment is separated by space + tab
	private String unitAbbrev6 = "\u03bcs";	// comment is separated by tab
	private String unitAbbrev7 = "\u03bcs";	/* comment is separated by tab */
	private String unitAbbrev8 = "\u03bcs"; /* comment
	                                           has 2 lines */
	void foo() {
		for (char c = '\u0000'; c < '\uffff'; c++) {
			if (c == '\u001b' ||     // ESC
					c == '\u2014')   // Em-Dash?
				continue;
		}
	}
	private String unitAbbrev9 = "\u03bcs"; /* comment */ int i;

	private String notAUnicodeEscaped1 = "\\u1234";

	private String notAUnicodeEscaped2 = "\\\\u1234";

	private String onlyEscaped = "\\\u1234";
}