-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCharacter.java
10369 lines (10003 loc) · 428 KB
/
Character.java
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.lang;
import jdk.internal.HotSpotIntrinsicCandidate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* The {@code Character} class wraps a value of the primitive
* type {@code char} in an object. An object of type
* {@code Character} contains a single field whose type is
* {@code char}.
* <p>
* In addition, this class provides several methods for determining
* a character's category (lowercase letter, digit, etc.) and for converting
* characters from uppercase to lowercase and vice versa.
* <p>
* Character information is based on the Unicode Standard, version 10.0.0.
* <p>
* The methods and data of class {@code Character} are defined by
* the information in the <i>UnicodeData</i> file that is part of the
* Unicode Character Database maintained by the Unicode
* Consortium. This file specifies various properties including name
* and general category for every defined Unicode code point or
* character range.
* <p>
* The file and its description are available from the Unicode Consortium at:
* <ul>
* <li><a href="http://www.unicode.org">http://www.unicode.org</a>
* </ul>
*
* <h3><a id="unicode">Unicode Character Representations</a></h3>
*
* <p>The {@code char} data type (and therefore the value that a
* {@code Character} object encapsulates) are based on the
* original Unicode specification, which defined characters as
* fixed-width 16-bit entities. The Unicode Standard has since been
* changed to allow for characters whose representation requires more
* than 16 bits. The range of legal <em>code point</em>s is now
* U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
* (Refer to the <a
* href="http://www.unicode.org/reports/tr27/#notation"><i>
* definition</i></a> of the U+<i>n</i> notation in the Unicode
* Standard.)
*
* <p><a id="BMP">The set of characters from U+0000 to U+FFFF</a> is
* sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
* <a id="supplementary">Characters</a> whose code points are greater
* than U+FFFF are called <em>supplementary character</em>s. The Java
* platform uses the UTF-16 representation in {@code char} arrays and
* in the {@code String} and {@code StringBuffer} classes. In
* this representation, supplementary characters are represented as a pair
* of {@code char} values, the first from the <em>high-surrogates</em>
* range, (\uD800-\uDBFF), the second from the
* <em>low-surrogates</em> range (\uDC00-\uDFFF).
*
* <p>A {@code char} value, therefore, represents Basic
* Multilingual Plane (BMP) code points, including the surrogate
* code points, or code units of the UTF-16 encoding. An
* {@code int} value represents all Unicode code points,
* including supplementary code points. The lower (least significant)
* 21 bits of {@code int} are used to represent Unicode code
* points and the upper (most significant) 11 bits must be zero.
* Unless otherwise specified, the behavior with respect to
* supplementary characters and surrogate {@code char} values is
* as follows:
*
* <ul>
* <li>The methods that only accept a {@code char} value cannot support
* supplementary characters. They treat {@code char} values from the
* surrogate ranges as undefined characters. For example,
* {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
* this specific value if followed by any low-surrogate value in a string
* would represent a letter.
*
* <li>The methods that accept an {@code int} value support all
* Unicode characters, including supplementary characters. For
* example, {@code Character.isLetter(0x2F81A)} returns
* {@code true} because the code point value represents a letter
* (a CJK ideograph).
* </ul>
*
* <p>In the Java SE API documentation, <em>Unicode code point</em> is
* used for character values in the range between U+0000 and U+10FFFF,
* and <em>Unicode code unit</em> is used for 16-bit
* {@code char} values that are code units of the <em>UTF-16</em>
* encoding. For more information on Unicode terminology, refer to the
* <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
*
* @author Lee Boynton
* @author Guy Steele
* @author Akira Tanaka
* @author Martin Buchholz
* @author Ulf Zibis
* @since 1.0
*/
/*
* char的包装类
*
* 一个有用的链接:https://www.oracle.com/technetwork/articles/java/supplementary-142654.html
*
* Character的局限性是:对于四字节的符号(其实也不是一个char)无法包装(但可以根据其码点值解码为字符串)。
*/
public final class Character implements java.io.Serializable, Comparable<Character> {
/*▼ Unicode符号分类代号 ████████████████████████████████████████████████████████████████████████████████┓ */
/**
* General category "Lu" in the Unicode specification.
*
* @since 1.1
*/
public static final byte UPPERCASE_LETTER = 1; // Lu - Letter, uppercase
/**
* General category "Ll" in the Unicode specification.
*
* @since 1.1
*/
public static final byte LOWERCASE_LETTER = 2; // Ll - Letter, lowercase
/**
* General category "Lt" in the Unicode specification.
*
* @since 1.1
*/
public static final byte TITLECASE_LETTER = 3; // Lt - Letter, titlecase
/**
* General category "Lm" in the Unicode specification.
*
* @since 1.1
*/
public static final byte MODIFIER_LETTER = 4; // Lm - Letter, modifier
/**
* General category "Lo" in the Unicode specification.
*
* @since 1.1
*/
public static final byte OTHER_LETTER = 5; // Lo - Letter, other
/**
* General category "Mn" in the Unicode specification.
*
* @since 1.1
*/
public static final byte NON_SPACING_MARK = 6; // Mn - Mark, nonspacing
/**
* General category "Me" in the Unicode specification.
*
* @since 1.1
*/
public static final byte ENCLOSING_MARK = 7; // Me - Mark, enclosing
/**
* General category "Mc" in the Unicode specification.
*
* @since 1.1
*/
public static final byte COMBINING_SPACING_MARK = 8; // Mc - Mark, spacing combining
/**
* General category "Nd" in the Unicode specification.
*
* @since 1.1
*/
public static final byte DECIMAL_DIGIT_NUMBER = 9; // Nd - Number, decimal digit
/**
* General category "Nl" in the Unicode specification.
*
* @since 1.1
*/
public static final byte LETTER_NUMBER = 10; // Nl - Number, letter
/**
* General category "No" in the Unicode specification.
*
* @since 1.1
*/
public static final byte OTHER_NUMBER = 11; // No - Number, other
/**
* General category "Pd" in the Unicode specification.
*
* @since 1.1
*/
public static final byte DASH_PUNCTUATION = 20; // Pd - Punctuation, dash
/**
* General category "Ps" in the Unicode specification.
*
* @since 1.1
*/
public static final byte START_PUNCTUATION = 21; // Ps - Punctuation, open
/**
* General category "Pe" in the Unicode specification.
*
* @since 1.1
*/
public static final byte END_PUNCTUATION = 22; // Pe - Punctuation, close
/**
* General category "Pc" in the Unicode specification.
*
* @since 1.1
*/
public static final byte CONNECTOR_PUNCTUATION = 23; // Pc - Punctuation, connector
/**
* General category "Po" in the Unicode specification.
*
* @since 1.1
*/
public static final byte OTHER_PUNCTUATION = 24; // Po - Punctuation, other
/**
* General category "Pi" in the Unicode specification.
*
* @since 1.4
*/
public static final byte INITIAL_QUOTE_PUNCTUATION = 29; // Pi - Punctuation, initial quote
/**
* General category "Pf" in the Unicode specification.
*
* @since 1.4
*/
public static final byte FINAL_QUOTE_PUNCTUATION = 30; // Pf - Punctuation, final quote
/**
* General category "Sm" in the Unicode specification.
*
* @since 1.1
*/
public static final byte MATH_SYMBOL = 25; // Sm - Symbol, math
/**
* General category "Sc" in the Unicode specification.
*
* @since 1.1
*/
public static final byte CURRENCY_SYMBOL = 26; // Sc - Symbol, currency
/**
* General category "Sk" in the Unicode specification.
*
* @since 1.1
*/
public static final byte MODIFIER_SYMBOL = 27; // Sk - Symbol, modifier
/**
* General category "So" in the Unicode specification.
*
* @since 1.1
*/
public static final byte OTHER_SYMBOL = 28; // So - Symbol, other
/**
* General category "Zs" in the Unicode specification.
*
* @since 1.1
*/
public static final byte SPACE_SEPARATOR = 12; // Zs - Separator, space
/**
* General category "Zl" in the Unicode specification.
*
* @since 1.1
*/
public static final byte LINE_SEPARATOR = 13; // Zl - Separator, line
/**
* General category "Zp" in the Unicode specification.
*
* @since 1.1
*/
public static final byte PARAGRAPH_SEPARATOR = 14; // Zp - Separator, paragraph
/**
* General category "Cn" in the Unicode specification.
*
* @since 1.1
*/
public static final byte UNASSIGNED = 0; // Cn - Other, not assigned
/**
* General category "Cc" in the Unicode specification.
*
* @since 1.1
*/
public static final byte CONTROL = 15; // Cc - Other, control
/**
* General category "Cf" in the Unicode specification.
*
* @since 1.1
*/
public static final byte FORMAT = 16; // Cf - Other, format
/**
* General category "Co" in the Unicode specification.
*
* @since 1.1
*/
public static final byte PRIVATE_USE = 18; // Co - Other, private use
/**
* General category "Cs" in the Unicode specification.
*
* @since 1.1
*/
public static final byte SURROGATE = 19; // Cs - Other, surrogate
/*▲ Unicode符号分类代号 ████████████████████████████████████████████████████████████████████████████████┛ */
/*▼ Unicode双向字符类型 ████████████████████████████████████████████████████████████████████████████████┓ */
/**
* Undefined bidirectional character type. Undefined {@code char}
* values have undefined directionality in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_UNDEFINED = -1; // 未定义
/**
* Strong bidirectional character type "L" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0; // Left-to-Right
/**
* Strong bidirectional character type "R" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1; // Right-to-Left
/**
* Strong bidirectional character type "AL" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2; // Arabic Letter
/**
* Weak bidirectional character type "EN" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3; // European Number
/**
* Weak bidirectional character type "ES" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4; // European Separator
/**
* Weak bidirectional character type "ET" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5; // European Number Terminator
/**
* Weak bidirectional character type "AN" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6; // Arabic Number
/**
* Weak bidirectional character type "CS" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7; // Common Number Separator
/**
* Weak bidirectional character type "NSM" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_NONSPACING_MARK = 8; // Nonspacing Mark
/**
* Weak bidirectional character type "BN" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9; // Boundary Neutral
/**
* Neutral bidirectional character type "B" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10; // Paragraph Separator
/**
* Neutral bidirectional character type "S" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11; // Segment Separator
/**
* Neutral bidirectional character type "WS" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_WHITESPACE = 12; // Whitespace
/**
* Neutral bidirectional character type "ON" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13; // Other Neutrals
/**
* Strong bidirectional character type "LRE" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14; // Left-to-Right Embedding
/**
* Strong bidirectional character type "LRO" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15; // Left-to-Right Override
/**
* Strong bidirectional character type "RLE" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16; // Right-to-Left Embedding
/**
* Strong bidirectional character type "RLO" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17; // Right-to-Left Override
/**
* Weak bidirectional character type "PDF" in the Unicode specification.
*
* @since 1.4
*/
public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18; // Pop Directional Format
/**
* Weak bidirectional character type "LRI" in the Unicode specification.
*
* @since 9
*/
public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_ISOLATE = 19; // Left-to-Right Isolate
/**
* Weak bidirectional character type "RLI" in the Unicode specification.
*
* @since 9
*/
public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ISOLATE = 20; // Right-to-Left Isolate
/**
* Weak bidirectional character type "FSI" in the Unicode specification.
*
* @since 9
*/
public static final byte DIRECTIONALITY_FIRST_STRONG_ISOLATE = 21; // First Strong Isolate
/**
* Weak bidirectional character type "PDI" in the Unicode specification.
*
* @since 9
*/
public static final byte DIRECTIONALITY_POP_DIRECTIONAL_ISOLATE = 22; // Pop Directional Isolate
/*▲ Unicode双向字符类型 ████████████████████████████████████████████████████████████████████████████████┛ */
/**
* The minimum radix available for conversion to and from strings.
* The constant value of this field is the smallest value permitted for the radix argument in radix-conversion methods such as the {@code digit} method,
* the {@code forDigit} method, and the {@code toString} method of class {@code Integer}.
*
* @see Character#digit(char, int)
* @see Character#forDigit(int, int)
* @see Integer#toString(int, int)
* @see Integer#valueOf(String)
*/
// 进制转换约束下限,最小2进制
public static final int MIN_RADIX = 2;
/**
* The maximum radix available for conversion to and from strings.
* The constant value of this field is the largest value permitted
* for the radix argument in radix-conversion methods such as the
* {@code digit} method, the {@code forDigit} method, and the
* {@code toString} method of class {@code Integer}.
*
* @see Character#digit(char, int)
* @see Character#forDigit(int, int)
* @see Integer#toString(int, int)
* @see Integer#valueOf(String)
*/
// 进制转换约束上限,最大36进制,因为10个数字+26个字母的限制
public static final int MAX_RADIX = 36;
/**
* The constant value of this field is the smallest value of type {@code char}, {@code '\u005Cu0000'}.
*
* @since 1.0.2
*/
// char的最小值,Unicode基本平面区码点最小值
public static final char MIN_VALUE = '\u0000';
/**
* The constant value of this field is the largest value of type {@code char}, {@code '\u005CuFFFF'}.
*
* @since 1.0.2
*/
// char的最大值,Unicode基本平面区码点最大值
public static final char MAX_VALUE = '\uFFFF';
/**
* The {@code Class} instance representing the primitive type {@code char}.
*
* @since 1.1
*/
// 基本类型char的包装类实例
@SuppressWarnings("unchecked")
public static final Class<Character> TYPE = (Class<Character>) Class.getPrimitiveClass("char");
/**
* The minimum value of a <a href="http://www.unicode.org/glossary/#code_point"> Unicode code point</a>, constant {@code U+0000}.
*
* @since 1.5
*/
public static final int MIN_CODE_POINT = 0x000000; // Unicode码点最小值
/**
* The maximum value of a <a href="http://www.unicode.org/glossary/#code_point"> Unicode code point</a>, constant {@code U+10FFFF}.
*
* @since 1.5
*/
public static final int MAX_CODE_POINT = 0x10FFFF; // Unicode码点最大值
/**
* The minimum value of a <a href="http://www.unicode.org/glossary/#supplementary_code_point"> Unicode supplementary code point</a>, constant {@code U+10000}.
*
* @since 1.5
*/
public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000; // Unicode非基本平面区码点最小值
/**
* The minimum value of a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> Unicode high-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuD800'}.
* A high-surrogate is also known as a <i>leading-surrogate</i>.
*
* @since 1.5
*/
public static final char MIN_HIGH_SURROGATE = '\uD800'; // 高代理区[U+D800~U+DBFF]的左边界
/**
* The maximum value of a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> Unicode high-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
* A high-surrogate is also known as a <i>leading-surrogate</i>.
*
* @since 1.5
*/
public static final char MAX_HIGH_SURROGATE = '\uDBFF'; // 高代理区[U+D800~U+DBFF]的右边界
/**
* The minimum value of a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> Unicode low-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
* A low-surrogate is also known as a <i>trailing-surrogate</i>.
*
* @since 1.5
*/
public static final char MIN_LOW_SURROGATE = '\uDC00'; // 低代理区[U+DC00~U+DFFF]的左边界
/**
* The maximum value of a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> Unicode low-surrogate code unit</a> in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
* A low-surrogate is also known as a <i>trailing-surrogate</i>.
*
* @since 1.5
*/
public static final char MAX_LOW_SURROGATE = '\uDFFF'; // 低代理区[U+DC00~U+DFFF]的右边界
/**
* The minimum value of a Unicode surrogate code unit in the UTF-16 encoding, constant {@code '\u005CuD800'}.
*
* @since 1.5
*/
public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE; // Unicode高代理区下限
/**
* The maximum value of a Unicode surrogate code unit in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
*
* @since 1.5
*/
public static final char MAX_SURROGATE = MAX_LOW_SURROGATE; // Unicode低代理区上限
/**
* The number of bits used to represent a {@code char} value in unsigned binary form, constant {@code 16}.
*
* @since 1.5
*/
public static final int SIZE = 16; // (无符号)char所占的位数
/**
* The number of bytes used to represent a {@code char} value in unsigned binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE; // (无符号)char所占的字节数
/**
* Error flag. Use int (code point) to avoid confusion with U+FFFF.
*/
static final int ERROR = 0xFFFFFFFF; // 错误标记
/**
* use serialVersionUID from JDK 1.0.2 for interoperability
*/
private static final long serialVersionUID = 3786198910865385080L;
/**
* The value of the {@code Character}.
*
* @serial
*/
private final char value; // Character包装的值
/**
* Constructs a newly allocated {@code Character} object that represents the specified {@code char} value.
*
* @param value the value to be represented by the {@code Character} object.
*
* @deprecated It is rarely appropriate to use this constructor.
* The static factory {@link #valueOf(char)} is generally a better choice, as it is likely to yield significantly better space and time performance.
*/
// 过时,用valueOf替代。但如果不想使用[0, 127]范围内的字符缓存对象,则可以调用此方法。
@Deprecated(since = "9")
public Character(char value) {
this.value = value;
}
/*▼ 装箱/拆箱 ████████████████████████████████████████████████████████████████████████████████┓ */
/**
* Returns a {@code Character} instance representing the specified {@code char} value.
* If a new {@code Character} instance is not required, this method should generally be used in preference to the constructor {@link #Character(char)},
* as this method is likely to yield significantly better space and time performance by caching frequently requested values.
*
* This method will always cache values in the range {@code '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may cache other values outside of this range.
*
* @param c a char value.
*
* @return a {@code Character} instance representing {@code c}.
*
* @since 1.5
*/
// 装箱,返回char的包装类实例。如果char范围在[0, 127]内,则使用缓存
@HotSpotIntrinsicCandidate
public static Character valueOf(char c) {
if(c <= 127) { // must cache
return CharacterCache.cache[(int) c];
}
return new Character(c);
}
/**
* Returns the value of this {@code Character} object.
*
* @return the primitive {@code char} value represented by
* this object.
*/
// 拆箱,将Character对象转为char值
@HotSpotIntrinsicCandidate
public char charValue() {
return value;
}
/*▲ 装箱/拆箱 ████████████████████████████████████████████████████████████████████████████████┛ */
/*▼ 判断字符属性 ████████████████████████████████████████████████████████████████████████████████┓ */
/**
* Determines if the specified character (Unicode code point) is an alphabet.
* <p>
* A character is considered to be alphabetic if its general category type,
* provided by {@link Character#getType(int) getType(codePoint)}, is any of
* the following:
* <ul>
* <li> {@code UPPERCASE_LETTER}
* <li> {@code LOWERCASE_LETTER}
* <li> {@code TITLECASE_LETTER}
* <li> {@code MODIFIER_LETTER}
* <li> {@code OTHER_LETTER}
* <li> {@code LETTER_NUMBER}
* </ul>
* or it has contributory property Other_Alphabetic as defined by the
* Unicode Standard.
*
* @param codePoint the character (Unicode code point) to be tested.
*
* @return {@code true} if the character is a Unicode alphabet
* character, {@code false} otherwise.
*
* @since 1.7
*/
// true:该字符是字母[Alphabetic]字符
public static boolean isAlphabetic(int codePoint) {
return (((((1 << Character.UPPERCASE_LETTER)
| (1 << Character.LOWERCASE_LETTER)
| (1 << Character.TITLECASE_LETTER)
| (1 << Character.MODIFIER_LETTER)
| (1 << Character.OTHER_LETTER)
| (1 << Character.LETTER_NUMBER)) >> getType(codePoint)) & 1) != 0)
|| CharacterData.of(codePoint).isOtherAlphabetic(codePoint);
}
/**
* Determines if the specified character (Unicode code point) is a CJKV (Chinese, Japanese, Korean and Vietnamese) ideograph, as defined by the Unicode Standard.
*
* @param codePoint the character (Unicode code point) to be tested.
*
* @return {@code true} if the character is a Unicode ideograph
* character, {@code false} otherwise.
*
* @since 1.7
*/
// true:该字符是表意字符
public static boolean isIdeographic(int codePoint) {
return CharacterData.of(codePoint).isIdeographic(codePoint);
}
/**
* Determines if the specified character is
* permissible as the first character in a Java identifier.
* <p>
* A character may start a Java identifier if and only if
* one of the following conditions is true:
* <ul>
* <li> {@link #isLetter(char) isLetter(ch)} returns {@code true}
* <li> {@link #getType(char) getType(ch)} returns {@code LETTER_NUMBER}
* <li> {@code ch} is a currency symbol (such as {@code '$'})
* <li> {@code ch} is a connecting punctuation character (such as {@code '_'}).
* </ul>
*
* <p><b>Note:</b> This method cannot handle <a
* href="#supplementary"> supplementary characters</a>. To support
* all Unicode characters, including supplementary characters, use
* the {@link #isJavaIdentifierStart(int)} method.
*
* @param ch the character to be tested.
*
* @return {@code true} if the character may start a Java identifier;
* {@code false} otherwise.
*
* @see Character#isJavaIdentifierPart(char)
* @see Character#isLetter(char)
* @see Character#isUnicodeIdentifierStart(char)
* @see javax.lang.model.SourceVersion#isIdentifier(CharSequence)
* @since 1.1
*/
// true:该字符可位于Java标识符起始位置
public static boolean isJavaIdentifierStart(char ch) {
return isJavaIdentifierStart((int) ch);
}
/**
* Determines if the character (Unicode code point) is
* permissible as the first character in a Java identifier.
* <p>
* A character may start a Java identifier if and only if
* one of the following conditions is true:
* <ul>
* <li> {@link #isLetter(int) isLetter(codePoint)}
* returns {@code true}
* <li> {@link #getType(int) getType(codePoint)}
* returns {@code LETTER_NUMBER}
* <li> the referenced character is a currency symbol (such as {@code '$'})
* <li> the referenced character is a connecting punctuation character
* (such as {@code '_'}).
* </ul>
*
* @param codePoint the character (Unicode code point) to be tested.
*
* @return {@code true} if the character may start a Java identifier;
* {@code false} otherwise.
*
* @see Character#isJavaIdentifierPart(int)
* @see Character#isLetter(int)
* @see Character#isUnicodeIdentifierStart(int)
* @see javax.lang.model.SourceVersion#isIdentifier(CharSequence)
* @since 1.5
*/
// true:该字符可位于Java标识符起始位置
public static boolean isJavaIdentifierStart(int codePoint) {
return CharacterData.of(codePoint).isJavaIdentifierStart(codePoint);
}
/**
* Determines if the specified character may be part of a Java
* identifier as other than the first character.
* <p>
* A character may be part of a Java identifier if any of the following
* are true:
* <ul>
* <li> it is a letter
* <li> it is a currency symbol (such as {@code '$'})
* <li> it is a connecting punctuation character (such as {@code '_'})
* <li> it is a digit
* <li> it is a numeric letter (such as a Roman numeral character)
* <li> it is a combining mark
* <li> it is a non-spacing mark
* <li> {@code isIdentifierIgnorable} returns
* {@code true} for the character
* </ul>
*
* <p><b>Note:</b> This method cannot handle <a
* href="#supplementary"> supplementary characters</a>. To support
* all Unicode characters, including supplementary characters, use
* the {@link #isJavaIdentifierPart(int)} method.
*
* @param ch the character to be tested.
*
* @return {@code true} if the character may be part of a
* Java identifier; {@code false} otherwise.
*
* @see Character#isIdentifierIgnorable(char)
* @see Character#isJavaIdentifierStart(char)
* @see Character#isLetterOrDigit(char)
* @see Character#isUnicodeIdentifierPart(char)
* @see javax.lang.model.SourceVersion#isIdentifier(CharSequence)
* @since 1.1
*/
// true:该字符可位于Java标识符的非起始部分
public static boolean isJavaIdentifierPart(char ch) {
return isJavaIdentifierPart((int) ch);
}
/**
* Determines if the character (Unicode code point) may be part of a Java
* identifier as other than the first character.
* <p>
* A character may be part of a Java identifier if any of the following
* are true:
* <ul>
* <li> it is a letter
* <li> it is a currency symbol (such as {@code '$'})
* <li> it is a connecting punctuation character (such as {@code '_'})
* <li> it is a digit
* <li> it is a numeric letter (such as a Roman numeral character)
* <li> it is a combining mark
* <li> it is a non-spacing mark
* <li> {@link #isIdentifierIgnorable(int)
* isIdentifierIgnorable(codePoint)} returns {@code true} for
* the character
* </ul>
*
* @param codePoint the character (Unicode code point) to be tested.
*
* @return {@code true} if the character may be part of a
* Java identifier; {@code false} otherwise.
*
* @see Character#isIdentifierIgnorable(int)
* @see Character#isJavaIdentifierStart(int)
* @see Character#isLetterOrDigit(int)
* @see Character#isUnicodeIdentifierPart(int)
* @see javax.lang.model.SourceVersion#isIdentifier(CharSequence)
* @since 1.5
*/
// true:该字符可位于Java标识符的非起始部分
public static boolean isJavaIdentifierPart(int codePoint) {
return CharacterData.of(codePoint).isJavaIdentifierPart(codePoint);
}
/**
* Determines if the specified character is permissible as the
* first character in a Unicode identifier.
* <p>
* A character may start a Unicode identifier if and only if
* one of the following conditions is true:
* <ul>
* <li> {@link #isLetter(char) isLetter(ch)} returns {@code true}
* <li> {@link #getType(char) getType(ch)} returns
* {@code LETTER_NUMBER}.
* </ul>
*
* <p><b>Note:</b> This method cannot handle <a
* href="#supplementary"> supplementary characters</a>. To support
* all Unicode characters, including supplementary characters, use
* the {@link #isUnicodeIdentifierStart(int)} method.
*
* @param ch the character to be tested.
*
* @return {@code true} if the character may start a Unicode
* identifier; {@code false} otherwise.
*
* @see Character#isJavaIdentifierStart(char)
* @see Character#isLetter(char)
* @see Character#isUnicodeIdentifierPart(char)
* @since 1.1
*/
// true:该字符可位于Unicode标识符的起始部分
public static boolean isUnicodeIdentifierStart(char ch) {
return isUnicodeIdentifierStart((int) ch);
}
/**
* Determines if the specified character (Unicode code point) is permissible as the
* first character in a Unicode identifier.
* <p>
* A character may start a Unicode identifier if and only if
* one of the following conditions is true:
* <ul>
* <li> {@link #isLetter(int) isLetter(codePoint)}
* returns {@code true}
* <li> {@link #getType(int) getType(codePoint)}
* returns {@code LETTER_NUMBER}.
* </ul>
*
* @param codePoint the character (Unicode code point) to be tested.
*
* @return {@code true} if the character may start a Unicode
* identifier; {@code false} otherwise.
*
* @see Character#isJavaIdentifierStart(int)
* @see Character#isLetter(int)
* @see Character#isUnicodeIdentifierPart(int)
* @since 1.5
*/
// true:该字符可位于Unicode标识符的起始部分
public static boolean isUnicodeIdentifierStart(int codePoint) {
return CharacterData.of(codePoint).isUnicodeIdentifierStart(codePoint);
}
/**
* Determines if the specified character may be part of a Unicode
* identifier as other than the first character.
* <p>
* A character may be part of a Unicode identifier if and only if
* one of the following statements is true:
* <ul>
* <li> it is a letter
* <li> it is a connecting punctuation character (such as {@code '_'})
* <li> it is a digit
* <li> it is a numeric letter (such as a Roman numeral character)
* <li> it is a combining mark
* <li> it is a non-spacing mark
* <li> {@code isIdentifierIgnorable} returns
* {@code true} for this character.
* </ul>
*
* <p><b>Note:</b> This method cannot handle <a
* href="#supplementary"> supplementary characters</a>. To support
* all Unicode characters, including supplementary characters, use
* the {@link #isUnicodeIdentifierPart(int)} method.
*
* @param ch the character to be tested.
*
* @return {@code true} if the character may be part of a
* Unicode identifier; {@code false} otherwise.
*
* @see Character#isIdentifierIgnorable(char)
* @see Character#isJavaIdentifierPart(char)
* @see Character#isLetterOrDigit(char)
* @see Character#isUnicodeIdentifierStart(char)
* @since 1.1
*/
// true:该字符可位于Unicode标识符的非起始部分
public static boolean isUnicodeIdentifierPart(char ch) {
return isUnicodeIdentifierPart((int) ch);
}
/**
* Determines if the specified character (Unicode code point) may be part of a Unicode
* identifier as other than the first character.
* <p>
* A character may be part of a Unicode identifier if and only if
* one of the following statements is true:
* <ul>
* <li> it is a letter
* <li> it is a connecting punctuation character (such as {@code '_'})
* <li> it is a digit
* <li> it is a numeric letter (such as a Roman numeral character)
* <li> it is a combining mark
* <li> it is a non-spacing mark
* <li> {@code isIdentifierIgnorable} returns
* {@code true} for this character.
* </ul>
*
* @param codePoint the character (Unicode code point) to be tested.
*
* @return {@code true} if the character may be part of a
* Unicode identifier; {@code false} otherwise.
*
* @see Character#isIdentifierIgnorable(int)
* @see Character#isJavaIdentifierPart(int)
* @see Character#isLetterOrDigit(int)
* @see Character#isUnicodeIdentifierStart(int)
* @since 1.5