~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/compiler/scala/tools/nsc/util/Chars.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* NSC -- new Scala compiler
2
 
 * Copyright 2006-2011 LAMP/EPFL
3
 
 * @author  Martin Odersky
4
 
 */
5
 
 
6
 
package scala.tools.nsc
7
 
package util
8
 
 
9
 
import annotation.{ tailrec, switch }
10
 
import java.lang.{ Character => JCharacter }
11
 
 
12
 
/** Contains constants and classifier methods for characters */
13
 
trait Chars {
14
 
  // Be very careful touching these.
15
 
  // Apparently trivial changes to the way you write these constants
16
 
  // will cause Scanners.scala to go from a nice efficient switch to
17
 
  // a ghastly nested if statement which will bring the type checker
18
 
  // to its knees. See ticket #1456
19
 
  // Martin: (this should be verified now that the pattern rules have been redesigned).
20
 
  final val LF = '\u000A'
21
 
  final val FF = '\u000C'
22
 
  final val CR = '\u000D'
23
 
  final val SU = '\u001A'
24
 
 
25
 
  /** Convert a character digit to an Int according to given base,
26
 
   *  -1 if no success */
27
 
  def digit2int(ch: Char, base: Int): Int = {
28
 
    if ('0' <= ch && ch <= '9' && ch < '0' + base)
29
 
      ch - '0'
30
 
    else if ('A' <= ch && ch < 'A' + base - 10)
31
 
      ch - 'A' + 10
32
 
    else if ('a' <= ch && ch < 'a' + base - 10)
33
 
      ch - 'a' + 10
34
 
    else
35
 
      -1
36
 
  }
37
 
 
38
 
  /** Convert a character to a backslash-u escape */
39
 
  def char2uescape(c: Char): String = {
40
 
    var rest = c.toInt
41
 
    val buf = new StringBuilder
42
 
    for (i <- 1 to 4) {
43
 
      buf ++= (rest % 16).toHexString
44
 
      rest = rest / 16
45
 
    }
46
 
    "\\u" + buf.toString.reverse
47
 
  }
48
 
 
49
 
  /** Is character a line break? */
50
 
  @inline def isLineBreakChar(c: Char) = (c: @switch) match {
51
 
    case LF|FF|CR|SU  => true
52
 
    case _            => false
53
 
  }
54
 
 
55
 
  /** Is character a whitespace character (but not a new line)? */
56
 
  def isWhitespace(c: Char) =
57
 
    c == ' ' || c == '\t' || c == CR
58
 
 
59
 
  /** Can character form part of a doc comment variable $xxx? */
60
 
  def isVarPart(c: Char) =
61
 
    '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
62
 
 
63
 
  /** Can character start an alphanumeric Scala identifier? */
64
 
  def isIdentifierStart(c: Char): Boolean =
65
 
    (c == '_') || (c == '$') || Character.isUnicodeIdentifierStart(c)
66
 
 
67
 
  /** Can character form part of an alphanumeric Scala identifier? */
68
 
  def isIdentifierPart(c: Char) =
69
 
    (c == '$') || Character.isUnicodeIdentifierPart(c)
70
 
 
71
 
  /** Is character a math or other symbol in Unicode?  */
72
 
  def isSpecial(c: Char) = {
73
 
    val chtp = Character.getType(c)
74
 
    chtp == Character.MATH_SYMBOL.toInt || chtp == Character.OTHER_SYMBOL.toInt
75
 
  }
76
 
 
77
 
  private final val otherLetters = Set[Char]('\u0024', '\u005F')  // '$' and '_'
78
 
  private final val letterGroups = {
79
 
    import JCharacter._
80
 
    Set[Byte](LOWERCASE_LETTER, UPPERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, LETTER_NUMBER)
81
 
  }
82
 
  def isScalaLetter(ch: Char) = letterGroups(JCharacter.getType(ch).toByte) || otherLetters(ch)
83
 
 
84
 
  /** Can character form part of a Scala operator name? */
85
 
  def isOperatorPart(c : Char) : Boolean = (c: @switch) match {
86
 
    case '~' | '!' | '@' | '#' | '%' |
87
 
         '^' | '*' | '+' | '-' | '<' |
88
 
         '>' | '?' | ':' | '=' | '&' |
89
 
         '|' | '/' | '\\' => true
90
 
    case c => isSpecial(c)
91
 
  }
92
 
}
93
 
 
94
 
object Chars extends Chars { }
 
 
b'\\ No newline at end of file'