@@ -18,6 +18,8 @@ package scala
18
18
19
19
import scala .language .`2.13`
20
20
21
+ import scala .collection .immutable .NumericRange
22
+
21
23
/** `Char`, a 16-bit unsigned integer (equivalent to Java's `char` primitive type) is a
22
24
* subtype of [[scala.AnyVal ]]. Instances of `Char` are not
23
25
* represented by an object in the underlying runtime system.
@@ -484,5 +486,122 @@ object Char extends AnyValCompanion {
484
486
implicit def char2long (x : Char ): Long = x.toLong
485
487
implicit def char2float (x : Char ): Float = x.toFloat
486
488
implicit def char2double (x : Char ): Double = x.toDouble
487
- }
488
489
490
+ extension (self : Char ) {
491
+
492
+ /** Returns `'''true'''` if this number has no decimal component.
493
+ * Always `'''true'''` for `RichInt`.
494
+ */
495
+ @ deprecated(" isWhole on Char is always true" , " 2.12.15" )
496
+ def isWhole : Boolean = true
497
+
498
+ /** Returns `true` iff this is within the
499
+ * range of [[scala.Char ]] MinValue and MaxValue; otherwise returns `false`.
500
+ */
501
+ @ deprecated(" isValidChar on Char is always true" , " 3.8.0" )
502
+ def isValidChar : Boolean = true
503
+
504
+ /** Returns `true` iff this is within the
505
+ * range of [[scala.Byte ]] MinValue and MaxValue; otherwise returns `false`.
506
+ */
507
+ def isValidByte : Boolean = self.toInt <= Byte .MaxValue .toInt
508
+
509
+ /** Returns `true` iff this is within the
510
+ * range of [[scala.Short ]] MinValue and MaxValue; otherwise returns `false`.
511
+ */
512
+ def isValidShort : Boolean = self.toInt <= Short .MaxValue .toInt
513
+
514
+ /** Returns `true` iff this is within the
515
+ * range of [[scala.Int ]] MinValue and MaxValue; otherwise returns `false`.
516
+ */
517
+ @ deprecated(" isValidInt on Char is always true" , " 3.8.0" )
518
+ def isValidInt : Boolean = true
519
+
520
+ /** Returns the absolute value of `this`. */
521
+ @ deprecated(" Char's are never negative; abs is redundant and can be removed" , since = " 3.8.0" )
522
+ def abs : Char = self
523
+
524
+ /** Returns `this` if `this > that` or `that` otherwise. */
525
+ def max (that : Char ): Char = java.lang.Math .max(self.toInt, that.toInt).toChar
526
+
527
+ /** Returns `this` if `this < that` or `that` otherwise. */
528
+ def min (that : Char ): Char = java.lang.Math .min(self.toInt, that.toInt).toChar
529
+
530
+ /** Returns the sign of `this`.
531
+ *
532
+ * zero if the argument is zero, -zero if the argument is -zero,
533
+ * one if the argument is greater than zero, -one if the argument is less than zero,
534
+ * and NaN if the argument is NaN where applicable.
535
+ */
536
+ @ deprecated(" since Char's are never negative, compare to '\\ u0000' instead" , since = " 3.8.0" )
537
+ def sign : Char = java.lang.Integer .signum(self.toInt).toChar
538
+
539
+ /** Returns the signum of `this`. */
540
+ @ deprecated(" use `sign` method instead" , since = " 2.13.0" )
541
+ def signum : Int = self.sign
542
+
543
+ /** Compares `this` to `that` according to the standard total ordering.
544
+ *
545
+ * Returns:
546
+ * - a positive value if `this > that`
547
+ * - a negative value if `this < that`
548
+ * - `0` if `this == that`
549
+ */
550
+ def compare (that : Char ): Int = java.lang.Character .compare(self, that)
551
+
552
+ /** A [[scala.collection.immutable.NumericRange ]] from `this` up to but not including `end`.
553
+ *
554
+ * @param end The final bound of the range to make.
555
+ */
556
+ def until (end : Char ): NumericRange .Exclusive [Char ] = NumericRange (self, end, '\u0001 ' )
557
+
558
+ /** A [[scala.collection.immutable.NumericRange ]] from `this` up to but not including `end`.
559
+ *
560
+ * @param end The final bound of the range to make.
561
+ * @param step The number to increase by for each step of the range.
562
+ */
563
+ def until (end : Char , step : Char ): NumericRange .Exclusive [Char ] = NumericRange (self, end, step)
564
+
565
+ /** A [[scala.collection.immutable.NumericRange ]] from `this` up to and including `end`.
566
+ *
567
+ * @param end The final bound of the range to make.
568
+ */
569
+ def to (end : Char ): NumericRange .Inclusive [Char ] = NumericRange .inclusive(self, end, '\u0001 ' )
570
+
571
+ /** A [[scala.collection.immutable.NumericRange ]] from `this` up to and including `end`.
572
+ *
573
+ * @param end The final bound of the range to make.
574
+ * @param step The number to increase by for each step of the range.
575
+ */
576
+ def to (end : Char , step : Char ): NumericRange .Inclusive [Char ] = NumericRange .inclusive(self, end, step)
577
+
578
+ def asDigit : Int = Character .digit(self, Character .MAX_RADIX )
579
+
580
+ def isControl : Boolean = Character .isISOControl(self)
581
+ def isDigit : Boolean = Character .isDigit(self)
582
+ def isLetter : Boolean = Character .isLetter(self)
583
+ def isLetterOrDigit : Boolean = Character .isLetterOrDigit(self)
584
+ def isWhitespace : Boolean = Character .isWhitespace(self)
585
+ def isSpaceChar : Boolean = Character .isSpaceChar(self)
586
+ def isHighSurrogate : Boolean = Character .isHighSurrogate(self)
587
+ def isLowSurrogate : Boolean = Character .isLowSurrogate(self)
588
+ def isSurrogate : Boolean = isHighSurrogate || isLowSurrogate
589
+ def isUnicodeIdentifierStart : Boolean = Character .isUnicodeIdentifierStart(self)
590
+ def isUnicodeIdentifierPart : Boolean = Character .isUnicodeIdentifierPart(self)
591
+ def isIdentifierIgnorable : Boolean = Character .isIdentifierIgnorable(self)
592
+ def isMirrored : Boolean = Character .isMirrored(self)
593
+
594
+ def isLower : Boolean = Character .isLowerCase(self)
595
+ def isUpper : Boolean = Character .isUpperCase(self)
596
+ def isTitleCase : Boolean = Character .isTitleCase(self)
597
+
598
+ def toLower : Char = Character .toLowerCase(self)
599
+ def toUpper : Char = Character .toUpperCase(self)
600
+ def toTitleCase : Char = Character .toTitleCase(self)
601
+
602
+ def getType : Int = Character .getType(self)
603
+ def getNumericValue : Int = Character .getNumericValue(self)
604
+ def getDirectionality : Byte = Character .getDirectionality(self)
605
+ def reverseBytes : Char = Character .reverseBytes(self)
606
+ }
607
+ }
0 commit comments