Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View 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
}
}
}

View 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

View file

@ -1 +0,0 @@
myStrVar.length()

View file

@ -0,0 +1 @@
FUNCTION BYTE-LENGTH(str)

View file

@ -0,0 +1 @@
LENGTH OF str

View file

@ -0,0 +1 @@
FUNCTION LENGTH-AN(str)

View file

@ -0,0 +1 @@
FUNCTION LENGTH(str)

View file

@ -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)

View file

@ -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)

View 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)

View file

@ -0,0 +1,2 @@
!. len !encode!utf-8 "møøse"
!. len !encode!utf-8 "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"

View file

@ -0,0 +1,2 @@
!. len "møøse"
!. len "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"

View file

@ -0,0 +1,2 @@
sizeof("Hello, world!") # gives 13
sizeof("Hellö, wørld!") # gives 15

View file

@ -0,0 +1,2 @@
length("Hello, world!") # gives 13
length("Hellö, wørld!") # gives 13

View file

@ -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)));

View file

@ -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

View file

@ -0,0 +1,2 @@
print(len("𝔘𝔫𝔦𝔠𝔬𝔡𝔢"))
# 7

View file

@ -0,0 +1,2 @@
import sys
sys.maxunicode # 1114111 on a wide build, 65535 on a narrow build

View file

@ -0,0 +1,4 @@
print(len('ascii'))
# 5
print(len('\u05d0')) # the letter Alef as unicode literal
# 1

View file

@ -0,0 +1,2 @@
print(len(b'\xd7\x90'.decode('utf-8'))) # Alef encoded as utf-8 byte sequence
# 1

View file

@ -0,0 +1,2 @@
print(hex(sys.maxunicode), len(unichr(0x1F4A9)))
# ('0x10ffff', 1)

View file

@ -0,0 +1,2 @@
print(hex(sys.maxunicode), len(unichr(0x1F4A9)))
# ('0xffff', 2)

View file

@ -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

View 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).

View file

@ -0,0 +1,2 @@
import sys
sys.maxunicode # 1114111 on a wide build, 65535 on a narrow build

View 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)

View file

@ -0,0 +1,2 @@
print hex(sys.maxunicode), len(unichr(0x1F4A9))
# ('0xffff', 2)

View file

@ -0,0 +1,2 @@
print(len(b'Hello, World!'))
# 13

View 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

View 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