Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Character-codes/Scala/character-codes-1.scala
Normal file
11
Task/Character-codes/Scala/character-codes-1.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
scala> 'a' toInt
|
||||
res2: Int = 97
|
||||
|
||||
scala> 97 toChar
|
||||
res3: Char = a
|
||||
|
||||
scala> '\u0061'
|
||||
res4: Char = a
|
||||
|
||||
scala> "\uD869\uDEA5"
|
||||
res5: String = 𪚥
|
||||
43
Task/Character-codes/Scala/character-codes-2.scala
Normal file
43
Task/Character-codes/Scala/character-codes-2.scala
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import java.lang.Character._; import scala.annotation.tailrec
|
||||
|
||||
object CharacterCode extends App {
|
||||
def intToChars(n: Int): Array[Char] = java.lang.Character.toChars(n)
|
||||
|
||||
def UnicodeToList(UTFstring: String) = {
|
||||
@tailrec
|
||||
def inner(str: List[Char], acc: List[String], surrogateHalf: Option[Char]): List[String] = {
|
||||
(str, surrogateHalf) match {
|
||||
case (Nil, _) => acc
|
||||
case (ch :: rest, None) => if (ch.isSurrogate) inner(rest, acc, Some(ch))
|
||||
else inner(rest, acc :+ ch.toString, None)
|
||||
case (ch :: rest, Some(f)) => inner(rest, (acc :+ (f.toString + ch)), None)
|
||||
}
|
||||
}
|
||||
inner(UTFstring.toList, Nil, None)
|
||||
}
|
||||
|
||||
def UnicodeToInt(utf: String) = {
|
||||
def charToInt(high: Char, low: Char) =
|
||||
{ if (isSurrogatePair(high, low)) toCodePoint(high, low) else high.toInt }
|
||||
charToInt(utf(0), if (utf.size > 1) utf(1) else 0)
|
||||
}
|
||||
|
||||
def UTFtoHexString(utf: String) = { utf.map(ch => f"${ch.toInt}%04X").mkString("\"\\u", "\\u", "\"") }
|
||||
|
||||
def flags(ch: String) = { // Testing Unicode character properties
|
||||
(if (ch matches "\\p{M}") "Y" else "N") + (if (ch matches "\\p{Mn}") "Y" else "N")
|
||||
}
|
||||
|
||||
val str = '\uFEFF' /*big-endian BOM*/ + "\u0301a" +
|
||||
"$áabcde¢£¤¥©ÇßIJijŁłʒλπक्तु•₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵℃←→⇒∙⌘☃☹☺☻ア字文𠀀" + intToChars(173733).mkString
|
||||
|
||||
println(s"Example string: $str")
|
||||
println(""" | Chr C/C++/Java source Code Point Hex Dec Mn Name
|
||||
!----+ --- ------------------------- ------- -------- -- """.stripMargin('!') + "-" * 27)
|
||||
|
||||
(UnicodeToList(str)).zipWithIndex.map {
|
||||
case (coll, nr) =>
|
||||
f"$nr%4d: $coll\t${UTFtoHexString(coll)}%27s U+${UnicodeToInt(coll)}%05X" +
|
||||
f"${"(" + UnicodeToInt(coll).toString}%8s) ${flags(coll)} ${getName(coll(0).toInt)} "
|
||||
}.foreach(println)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue