This commit is contained in:
Ingy döt Net 2013-04-10 16:57:12 -07:00
parent 518da4a923
commit 764da6cbbb
6144 changed files with 83610 additions and 11 deletions

View file

@ -0,0 +1,2 @@
"string"
(coerce (#\s #\t #\r #\i #\n #\g) 'string)

View file

@ -0,0 +1 @@
(defvar *string* "string")

View file

@ -0,0 +1 @@
(equal "string" "string")

View file

@ -0,0 +1 @@
(copy-seq "string")

View file

@ -0,0 +1,4 @@
(defun string-empty-p (string)
(cond
((= 0 (length string))t)
(nil)))

View file

@ -0,0 +1 @@
(concatenate 'string "string" "b")

View file

@ -0,0 +1,2 @@
(subseq "string" 1 6)
"ring"

View file

@ -0,0 +1,45 @@
import std.array: empty;
import std.string: replace;
void main() {
// String creation (destruction is usually handled by
// the garbage collector)
ubyte[] str1;
// String assignments
str1 = cast(ubyte[])"blah";
// hex string, same as "\x00\xFB\xCD\x32\xFD\x0A"
// whitespace and newlines are ignored
str1 = cast(ubyte[])x"00 FBCD 32FD 0A";
// String comparison
ubyte[] str2;
if (str1 == str2) {} // strings equal
// String cloning and copying
str2 = str1.dup; // copy entire string or array
// Check if a string is empty
if (str1.empty) {} // string empty
if (str1.length) {} // string not empty
if (!str1.length) {} // string empty
// Append a ubyte to a string
str1 ~= x"0A";
str1 ~= 'a';
// Extract a substring from a string
str1 = cast(ubyte[])"blork";
// this takes off the first and last bytes and
// assigns them to the new ubyte string
// This is just a light slice, no string data copied
ubyte[] substr = str1[1 .. $-1];
// Replace every occurrence of a ubyte (or a string)
// in a string with another string
str1 = cast(ubyte[])"blah";
replace(cast(char[])str1, "la", "al");
// Join strings
ubyte[] str3 = str1 ~ str2;
}

View file

@ -0,0 +1,2 @@
? def int8 := <type:java.lang.Byte>
# value: int8

View file

@ -0,0 +1,8 @@
? def bstr := [].diverge(int8)
# value: [].diverge()
? def bstr1 := [1,2,3].diverge(int8)
# value: [1, 2, 3].diverge()
? def bstr2 := [-0x7F,0x2,0x3].diverge(int8)
# value: [-127, 2, 3].diverge()

View file

@ -0,0 +1,2 @@
? bstr1.snapshot() < bstr2.snapshot()
# value: false

View file

@ -0,0 +1,5 @@
? bstr1.size().isZero()
# value: false
? bstr.size().isZero()
# value: true

View file

@ -0,0 +1,3 @@
? bstr.push(0)
? bstr
# value: [0].diverge()

View file

@ -0,0 +1,6 @@
? bstr1(1, 2)
# value: [2]
? bstr.replace(0, bstr.size(), bstr2, 1, 3)
? bstr
# value: [2, 3].diverge()

View file

@ -0,0 +1,3 @@
? for i => byte ? (byte == 2) in bstr2 { bstr2[i] := -1 }
? bstr2
# value: [-127, -1, 3].diverge()

View file

@ -0,0 +1,3 @@
? bstr1.append(bstr2)
? bstr1
# value: [1, 2, 3, -127, 2, 3].diverge()