File: java.lang.Character

package info (click to toggle)
bock 0.20.2.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,228 kB
  • ctags: 1,370
  • sloc: ansic: 7,367; java: 5,553; yacc: 963; lex: 392; makefile: 243; sh: 90; perl: 42
file content (120 lines) | stat: -rw-r--r-- 2,479 bytes parent folder | download | duplicates (3)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// java.lang.Character
// An implementation of the Java Language Specification section 20.5
// Written by Charles Briscoe-Smith; refer to the file LEGAL for details.

package java.lang;

public final class Character {
	public static final char MIN_VALUE = (char) 0x0;
	public static final char MAX_VALUE = (char) 0xffff;
	public static final int MIN_RADIX = 2;
	public static final int MAX_RADIX = 36;

	private char myvalue;

	public Character(char value)
	{
		myvalue=value;
	}

	public String toString()
	{
		char[] buf=new char[1];
		buf[0]=myvalue;
		return new String(buf);
	}
	public boolean equals(Object obj)
	{
		try {
			return ((Character) obj).myvalue==myvalue;
		} catch (NullPointerException e) {
			return false;
		} catch (ClassCastException e) {
			return false;
		}
	}
	public int hashCode()
	{
		return (int) myvalue;
	}
	public char charValue()
	{
		return myvalue;
	}

	public static boolean isLowerCase(char ch)
	{
		return (ch>=0x61 && ch<=0x7a)
		       || (ch>=0xdf && ch<=0xf6)
		       || (ch>=0xf8 && ch<=0xff);
	}

	public static boolean isUpperCase(char ch)
	{
		return (ch>=0x41 && ch<=0x5a)
		       || (ch>=0xc0 && ch<=0xd6)
		       || (ch>=0xd8 && ch<=0xde);
	}

	public static boolean isDigit(char ch)
	{
		return ch>=0x30 && ch<=0x39;
	}

	public static boolean isSpace(char ch)
	{
		return ch==(char)0x9 || ch==(char) 0xa || ch==(char) 0xc
		       || ch==(char) 0xd || ch==(char) 0x20;
	}

	public static char toLowerCase(char ch)
	{
		if (ch>=0x41 && ch<=0x5a) return ch+0x61-0x41;
		if (ch>=0xc0 && ch<=0xd6) return ch+0xe0-0xc0;
		if (ch>=0xd8 && ch<=0xde) return ch+0xf8-0xd8;
		return ch;
	}

	public static char toUpperCase(char ch)
	{
		if (ch>=0x61 && ch<=0x7a) return ch+0x41-0x61;
		if (ch>=0xe0 && ch<=0xf6) return ch+0xc0-0xe0;
		if (ch>=0xf8 && ch<=0xfe) return ch+0xd8-0xf8;
		if (ch==0xff) return 0x178;
		return ch;
	}

	public static int digit(char ch, int radix)
	{
		if (radix < MIN_RADIX || radix > MAX_RADIX) {
			return -1;
		}
		if (ch>=0x30 && ch<=0x39) {
			ch-=0x30;
		} else if (ch>=0x41 && ch<=0x5a) {
			ch+=10-0x41;
		} else if (ch>=0x61 && ch<=0x7a) {
			ch+=10-0x61;
		} else {
			return -1;
		}
		if (ch<radix) {
			return ch;
		} else {
			return -1;
		}
	}

	public static char forDigit(int digit, int radix)
	{
		if (radix < MIN_RADIX || radix > MAX_RADIX
		    || digit < 0 || digit >= radix)
		{
			return (char) 0;
		}
		if (digit < 10)
			return '0' + digit;
		else
			return 'a' + digit - 10;
	}
}