Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,12 +1,32 @@
|
|||
set inString to "Hello World" as Unicode text
|
||||
set inString to "Hello é̦世界"
|
||||
set byteCount to 0
|
||||
set idList to id of inString
|
||||
|
||||
repeat with incr in idList
|
||||
set byteCount to byteCount + 2
|
||||
if incr as integer > 65535 then
|
||||
set byteCount to byteCount + 2
|
||||
end if
|
||||
repeat with c in inString
|
||||
set t to id of c
|
||||
if ((count of t) > 0) then
|
||||
repeat with i in t
|
||||
set byteCount to byteCount + doit(i)
|
||||
end repeat
|
||||
else
|
||||
set byteCount to byteCount + doit(t)
|
||||
end if
|
||||
end repeat
|
||||
|
||||
byteCount
|
||||
|
||||
on doit(cid)
|
||||
set n to (cid as integer)
|
||||
if n > 67108863 then -- 0x3FFFFFF
|
||||
return 6
|
||||
else if n > 2097151 then -- 0x1FFFFF
|
||||
return 5
|
||||
else if n > 65535 then -- 0xFFFF
|
||||
return 4
|
||||
else if n > 2047 then -- 0x07FF
|
||||
return 3
|
||||
else if n > 127 then -- 0x7F
|
||||
return 2
|
||||
else
|
||||
return 1
|
||||
end if
|
||||
end doit
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
? LEN("HELLO, WORLD!")
|
||||
2
Task/String-length/Emacs-Lisp/string-length-1.l
Normal file
2
Task/String-length/Emacs-Lisp/string-length-1.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(length "hello")
|
||||
=> 5
|
||||
2
Task/String-length/Emacs-Lisp/string-length-2.l
Normal file
2
Task/String-length/Emacs-Lisp/string-length-2.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(string-bytes "\u1D518\u1D52B\u1D526")
|
||||
=> 12
|
||||
7
Task/String-length/Emacs-Lisp/string-length-3.l
Normal file
7
Task/String-length/Emacs-Lisp/string-length-3.l
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(let ((str (apply 'string
|
||||
(mapcar (lambda (c) (decode-char 'ucs c))
|
||||
'(#x1112 #x1161 #x11ab #x1100 #x1173 #x11af)))))
|
||||
(list (length str)
|
||||
(string-bytes str)
|
||||
(string-width str)))
|
||||
=> (6 18 4) ;; in emacs 23 up
|
||||
2
Task/String-length/Gnuplot/string-length.gnuplot
Normal file
2
Task/String-length/Gnuplot/string-length.gnuplot
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print strlen("hello")
|
||||
=> 5
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
String s = "Hello, world!";
|
||||
int byteCount = s.length() * 2;
|
||||
int byteCountUTF16 = s.getBytes("UTF-16").length; // Incorrect it yield 16 that is with the BOM
|
||||
int byteCountUTF16 = s.getBytes("UTF-16LE").length; // Correct it yield 14
|
||||
int byteCountUTF8 = s.getBytes("UTF-8").length;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
String s = "Hello, world!";
|
||||
int byteCountUTF16 = s.getBytes("UTF-16").length;
|
||||
int byteCountUTF8 = s.getBytes("UTF-8").length;
|
||||
int not_really_the_length = s.length(); // XXX: does not (always) count Unicode characters (code points)!
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
String s = "Hello, world!";
|
||||
int not_really_the_length = s.length(); // XXX: does not (always) count Unicode characters (code points)!
|
||||
String str = "\uD834\uDD2A"; //U+1D12A
|
||||
int not_really__the_length = str.length(); // value is 2, which is not the length in characters
|
||||
int actual_length = str.codePointCount(0, str.length()); // value is 1, which is the length in characters
|
||||
|
|
|
|||
|
|
@ -1,3 +1,19 @@
|
|||
String str = "\uD834\uDD2A"; //U+1D12A
|
||||
int not_really__the_length = str.length(); // value is 2, which is not the length in characters
|
||||
int actual_length = str.codePointCount(0, str.length()); // value is 1, which is the length in characters
|
||||
import java.text.BreakIterator;
|
||||
|
||||
public class Grapheme {
|
||||
public static void main(String[] args) {
|
||||
printLength("møøse");
|
||||
printLength("𝔘𝔫𝔦𝔠𝔬𝔡𝔢");
|
||||
printLength("J̲o̲s̲é̲");
|
||||
}
|
||||
|
||||
public static void printLength(String s) {
|
||||
BreakIterator it = BreakIterator.getCharacterInstance();
|
||||
it.setText(s);
|
||||
int count = 0;
|
||||
while (it.next() != BreakIterator.DONE) {
|
||||
count++;
|
||||
}
|
||||
System.out.println("Grapheme length: " + count+ " " + s);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
Task/String-length/Nimrod/string-length-1.nimrod
Normal file
4
Task/String-length/Nimrod/string-length-1.nimrod
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var s: string = "Hello, world! ☺"
|
||||
echo '"',s, '"'," has byte length: ", len(s)
|
||||
|
||||
# -> "Hello, world! ☺" has unicode char length: 17
|
||||
6
Task/String-length/Nimrod/string-length-2.nimrod
Normal file
6
Task/String-length/Nimrod/string-length-2.nimrod
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import unicode
|
||||
|
||||
var s: string = "Hello, world! ☺"
|
||||
echo '"',s, '"'," has unicode char length: ", runeLen(s)
|
||||
|
||||
# -> "Hello, world! ☺" has unicode char length: 15
|
||||
11
Task/String-length/Scala/string-length.scala
Normal file
11
Task/String-length/Scala/string-length.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
object StringLength extends App {
|
||||
val s1 = "møøse"
|
||||
val s3 = List("\uD835\uDD18", "\uD835\uDD2B", "\uD835\uDD26",
|
||||
"\uD835\uDD20", "\uD835\uDD2C", "\uD835\uDD21", "\uD835\uDD22").mkString
|
||||
val s4 = "J\u0332o\u0332s\u0332e\u0301\u0332"
|
||||
|
||||
List(s1, s3, s4).foreach(s => println(
|
||||
s"The string: $s, characterlength= ${s.length} UTF8bytes= ${
|
||||
s.getBytes("UTF-8").size
|
||||
} UTF16bytes= ${s.getBytes("UTF-16LE").size}"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue