Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1 +1 @@
|
|||
"A". 88*1+,
|
||||
"a". 99*44*+, @
|
||||
|
|
|
|||
21
Task/Character-codes/Bracmat/character-codes.bracmat
Normal file
21
Task/Character-codes/Bracmat/character-codes.bracmat
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
( put
|
||||
$ ( str
|
||||
$ ( "\nLatin a
|
||||
ISO-9959-1: "
|
||||
asc$a
|
||||
" = "
|
||||
chr$97
|
||||
"
|
||||
UTF-8: "
|
||||
utf$a
|
||||
" = "
|
||||
chu$97
|
||||
\n
|
||||
"Cyrillic а (UTF-8): "
|
||||
utf$а
|
||||
" = "
|
||||
chu$1072
|
||||
\n
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
PROCEDURE CharCodes*;
|
||||
VAR
|
||||
c : CHAR;
|
||||
BEGIN
|
||||
c := 'A';
|
||||
StdLog.Char(c);StdLog.String(":> ");StdLog.Int(ORD(c));StdLog.Ln;
|
||||
c := CHR(3A9H);
|
||||
StdLog.Char(c);StdLog.String(":> ");StdLog.Int(ORD(c));StdLog.Ln
|
||||
END CharCodes;
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
scala> 'a' toInt
|
||||
res9: Int = 97
|
||||
res2: Int = 97
|
||||
|
||||
scala> 97 toChar
|
||||
res10: Char = a
|
||||
res3: Char = a
|
||||
|
||||
scala> '\u0061'
|
||||
res4: Char = a
|
||||
|
||||
scala> "\uD869\uDEA5"
|
||||
res5: String = 𪚥
|
||||
|
|
|
|||
|
|
@ -1,7 +1,43 @@
|
|||
def charToInt(c: Char, next: Char): Option[Int] = (c, next) match {
|
||||
case _ if (c.isHighSurrogate && next.isLowSurrogate) => Some(java.lang.Character.toCodePoint(c, next))
|
||||
case _ if (c.isLowSurrogate) => None
|
||||
case _ => Some(c.toInt)
|
||||
}
|
||||
import java.lang.Character._; import scala.annotation.tailrec
|
||||
|
||||
def intToChars(n: Int): Array[Char] = java.lang.Character.toChars(n)
|
||||
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