Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
34
Task/String-length/ActionScript/string-length-1.as
Normal file
34
Task/String-length/ActionScript/string-length-1.as
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package {
|
||||
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class StringByteLength extends Sprite {
|
||||
|
||||
public function StringByteLength() {
|
||||
if ( stage ) _init();
|
||||
else addEventListener(Event.ADDED_TO_STAGE, _init);
|
||||
}
|
||||
|
||||
private function _init(e:Event = null):void {
|
||||
var s1:String = "The quick brown fox jumps over the lazy dog";
|
||||
var s2:String = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
var s3:String = "José";
|
||||
|
||||
var b:ByteArray = new ByteArray();
|
||||
b.writeUTFBytes(s1);
|
||||
trace(b.length); // 43
|
||||
|
||||
b.clear();
|
||||
b.writeUTFBytes(s2);
|
||||
trace(b.length); // 28
|
||||
|
||||
b.clear();
|
||||
b.writeUTFBytes(s3);
|
||||
trace(b.length); // 5
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
4
Task/String-length/ActionScript/string-length-2.as
Normal file
4
Task/String-length/ActionScript/string-length-2.as
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var s1:String = "The quick brown fox jumps over the lazy dog";
|
||||
var s2:String = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
|
||||
var s3:String = "José";
|
||||
trace(s1.length, s2.length, s3.length); // 43, 14, 4
|
||||
|
|
@ -1 +0,0 @@
|
|||
myStrVar.length()
|
||||
1
Task/String-length/COBOL/string-length-1.cobol
Normal file
1
Task/String-length/COBOL/string-length-1.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION BYTE-LENGTH(str)
|
||||
1
Task/String-length/COBOL/string-length-2.cobol
Normal file
1
Task/String-length/COBOL/string-length-2.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
LENGTH OF str
|
||||
1
Task/String-length/COBOL/string-length-3.cobol
Normal file
1
Task/String-length/COBOL/string-length-3.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION LENGTH-AN(str)
|
||||
1
Task/String-length/COBOL/string-length-4.cobol
Normal file
1
Task/String-length/COBOL/string-length-4.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION LENGTH(str)
|
||||
|
|
@ -1,2 +1,8 @@
|
|||
(count (.getBytes "Hello, world!")) ; 13 bytes
|
||||
(count (.getBytes "π")) ; two bytes
|
||||
(def utf-8-octet-length #(-> % (.getBytes "UTF-8") count))
|
||||
(map utf-8-octet-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (7 28 14)
|
||||
|
||||
(def utf-16-octet-length (comp (partial * 2) count))
|
||||
(map utf-16-octet-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (10 28 18)
|
||||
|
||||
(def code-unit-length count)
|
||||
(map code-unit-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 14 9)
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
(count "Hello, world!")
|
||||
(def character-length #(.codePointCount % 0 (count %)))
|
||||
(map character-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 7 9)
|
||||
|
|
|
|||
8
Task/String-length/Clojure/string-length-3.clj
Normal file
8
Task/String-length/Clojure/string-length-3.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(def grapheme-length
|
||||
#(->> (doto (java.text.BreakIterator/getCharacterInstance)
|
||||
(.setText %))
|
||||
(partial (memfn next))
|
||||
repeatedly
|
||||
(take-while (partial not= java.text.BreakIterator/DONE))
|
||||
count))
|
||||
(map grapheme-length ["møøse" "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" "J\u0332o\u0332s\u0332e\u0301\u0332"]) ; (5 7 4)
|
||||
2
Task/String-length/Deja-Vu/string-length-1.djv
Normal file
2
Task/String-length/Deja-Vu/string-length-1.djv
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
!. len !encode!utf-8 "møøse"
|
||||
!. len !encode!utf-8 "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
2
Task/String-length/Deja-Vu/string-length-2.djv
Normal file
2
Task/String-length/Deja-Vu/string-length-2.djv
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
!. len "møøse"
|
||||
!. len "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
2
Task/String-length/Julia/string-length-1.julia
Normal file
2
Task/String-length/Julia/string-length-1.julia
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
sizeof("Hello, world!") # gives 13
|
||||
sizeof("Hellö, wørld!") # gives 15
|
||||
2
Task/String-length/Julia/string-length-2.julia
Normal file
2
Task/String-length/Julia/string-length-2.julia
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
length("Hello, world!") # gives 13
|
||||
length("Hellö, wørld!") # gives 13
|
||||
|
|
@ -4,4 +4,4 @@ put skip list ('Byte length=', size(WS));
|
|||
|
||||
declare SM graphic (13) initial ('Hello world');
|
||||
put ('Character length=', length(SM));
|
||||
put skip list ('Byte length=', size(trim(SM));
|
||||
put skip list ('Byte length=', size(trim(SM)));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,2 @@
|
|||
#!/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
s = u"møøse"
|
||||
assert len(s) == 5
|
||||
assert len(s.encode('UTF-8')) == 7
|
||||
assert len(s.encode('UTF-16')) == 12 # The extra character is probably a leading Unicode byte-order mark (BOM).
|
||||
print len('ascii')
|
||||
# 5
|
||||
|
|
|
|||
2
Task/String-length/Python/string-length-10.py
Normal file
2
Task/String-length/Python/string-length-10.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(len("𝔘𝔫𝔦𝔠𝔬𝔡𝔢"))
|
||||
# 7
|
||||
2
Task/String-length/Python/string-length-11.py
Normal file
2
Task/String-length/Python/string-length-11.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import sys
|
||||
sys.maxunicode # 1114111 on a wide build, 65535 on a narrow build
|
||||
4
Task/String-length/Python/string-length-12.py
Normal file
4
Task/String-length/Python/string-length-12.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
print(len('ascii'))
|
||||
# 5
|
||||
print(len('\u05d0')) # the letter Alef as unicode literal
|
||||
# 1
|
||||
2
Task/String-length/Python/string-length-13.py
Normal file
2
Task/String-length/Python/string-length-13.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(len(b'\xd7\x90'.decode('utf-8'))) # Alef encoded as utf-8 byte sequence
|
||||
# 1
|
||||
2
Task/String-length/Python/string-length-14.py
Normal file
2
Task/String-length/Python/string-length-14.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(hex(sys.maxunicode), len(unichr(0x1F4A9)))
|
||||
# ('0x10ffff', 1)
|
||||
2
Task/String-length/Python/string-length-15.py
Normal file
2
Task/String-length/Python/string-length-15.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(hex(sys.maxunicode), len(unichr(0x1F4A9)))
|
||||
# ('0xffff', 2)
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
#!/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
s = "møøse"
|
||||
assert len(s) == 5
|
||||
assert len(s.encode('UTF-8')) == 7
|
||||
assert len(s.encode('UTF-16')) == 12 # The extra character is probably a leading Unicode byte-order mark (BOM).
|
||||
# The letter Alef
|
||||
print len(u'\u05d0'.encode('utf-8'))
|
||||
# 2
|
||||
print len(u'\u05d0'.encode('iso-8859-8'))
|
||||
# 1
|
||||
|
|
|
|||
6
Task/String-length/Python/string-length-3.py
Normal file
6
Task/String-length/Python/string-length-3.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
s = u"møøse"
|
||||
assert len(s) == 5
|
||||
assert len(s.encode('UTF-8')) == 7
|
||||
assert len(s.encode('UTF-16-BE')) == 10 # There are 3 different UTF-16 encodings: LE and BE are little endian and big endian respectively, the third one (without suffix) adds 2 extra leading bytes: the byte-order mark (BOM).
|
||||
2
Task/String-length/Python/string-length-4.py
Normal file
2
Task/String-length/Python/string-length-4.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import sys
|
||||
sys.maxunicode # 1114111 on a wide build, 65535 on a narrow build
|
||||
8
Task/String-length/Python/string-length-5.py
Normal file
8
Task/String-length/Python/string-length-5.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
print len('ascii')
|
||||
# 5
|
||||
print len(u'\u05d0') # the letter Alef as unicode literal
|
||||
# 1
|
||||
print len('\xd7\x90'.decode('utf-8')) # Same encoded as utf-8 string
|
||||
# 1
|
||||
print hex(sys.maxunicode), len(unichr(0x1F4A9))
|
||||
# ('0x10ffff', 1)
|
||||
2
Task/String-length/Python/string-length-6.py
Normal file
2
Task/String-length/Python/string-length-6.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print hex(sys.maxunicode), len(unichr(0x1F4A9))
|
||||
# ('0xffff', 2)
|
||||
2
Task/String-length/Python/string-length-7.py
Normal file
2
Task/String-length/Python/string-length-7.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(len(b'Hello, World!'))
|
||||
# 13
|
||||
5
Task/String-length/Python/string-length-8.py
Normal file
5
Task/String-length/Python/string-length-8.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# The letter Alef
|
||||
print(len('\u05d0'.encode())) # the default encoding is utf-8 in Python3
|
||||
# 2
|
||||
print(len('\u05d0'.encode('iso-8859-8')))
|
||||
# 1
|
||||
9
Task/String-length/Python/string-length-9.py
Normal file
9
Task/String-length/Python/string-length-9.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/env python
|
||||
# -*- coding: UTF-8 -*-
|
||||
s = "møøse"
|
||||
assert len(s) == 5
|
||||
assert len(s.encode('UTF-8')) == 7
|
||||
assert len(s.encode('UTF-16-BE')) == 10 # There are 3 different UTF-16 encodings: LE and BE are little endian and big endian respectively, the third one (without suffix) adds 2 extra leading bytes: the byte-order mark (BOM).
|
||||
u="𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
assert len(u.encode()) == 28
|
||||
assert len(u.encode('UTF-16-BE')) == 28
|
||||
Loading…
Add table
Add a link
Reference in a new issue