You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: book/src/datatypes.md
+33-4
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,42 @@
1
1
# Datatypes
2
2
3
+
## Strings
4
+
### STRING
5
+
rusty treats `STRING`s as byte-arrays storing UTF-8 character bytes with a Null-terminator (0-byte) at the end.
6
+
So a String of size n requres n+1 bytes to account for the Null-terminator.
7
+
A `STRING` literal is surrounded by single-ticks `'`.
8
+
9
+
A String has a well defined length which can be defined similar to the array-syntax. A String-variable
10
+
`myVariable: STRING[20]` declares a byte array of length 21, to store 20 utf8 character bytes. When
11
+
declaring a `STRING`, the length-attribute is optional. The default length is 80.
12
+
13
+
Examples
14
+
-`s1 : STRING;` - declares a String of length 80
15
+
-`s2 : STRING[20];` - declares a String of length 20
16
+
-`s3 : STRING := 'Hello World';` - declares and initializes a String of length 80, and initializes it with the utf8 characters and a null-terminator at the end
17
+
-`s4 : STRING[55] := 'Foo Baz';` - declares and initializes a String of length 55 and initializes it with the utf8 characters and a null-terminator at the end.
18
+
19
+
### WSTRING (Wide Strings)
20
+
rusty treats `WSTRING`s as byte-arrays storing UTF-16 character bytes with two Null-terminator bytes at the end. The bytes are stored in Little Endian encoding. A Wide-String of size n requres 2 * (n+1) bytes to account for the 2 byes per utf16 character and the Null-terminators. A `WSTRING` literal is surrounded by doubly-ticks `"`.
21
+
22
+
A `WSTRING` has a well defined length which can be defined similar to the array-syntax. A `WSTRING`-variable
23
+
`myVariable: WSTRING[20]` declares a byte array of length 42, to store 20 utf16 character bytes. When
24
+
declaring a `WSTRING`, the length-attribute is optional. The default length is 80.
25
+
26
+
Examples
27
+
-`ws1 : WSTRING;` - declares a Wide-String of length 80
28
+
-`ws2 : WSTRING[20];` - declares a Wide-String of length 20
29
+
-`ws3 : WSTRING := "Hello World";` - declares and initializes a Wide-String of length 80, and initializes it with the utf16 characters and a utf16-null-terminator at the end
30
+
-`ws4 : WSTRING[55] := "Foo Baz";` - declares and initializes a Wide-String of length 55 and initializes it with the utf8 characters and a utf16-null-terminator at the end.
31
+
3
32
## Date and Time
4
33
### DATE
5
34
The `DATE` datatype is used to represent a Date in the Gregorian Calendar. Such a value is
6
35
stored as an i64 with a precision in milliseconds and denotes the number of milliseconds
7
36
that have elapsed since January 1, 1970 UTC not counting leap seconds. DATE literals start
8
37
with `DATE#` or `D#` followed by a date in the format of `yyyy-mm-dd`.
9
38
10
-
Example literals
39
+
Examples
11
40
-`d1 : DATE := DATE#2021-05-02;`
12
41
-`d2 : DATE := DATE#1-12-24;`
13
42
-`d3 : DATE := D#2000-1-1;`
@@ -21,7 +50,7 @@ format of `yyyy-mm-dd-hh:mm:ss`.
21
50
22
51
Note that only the seconds-segment can have a fraction denoting the milliseconds.
0 commit comments