mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 00:47:28 +01:00
Add single-quoted strings
This commit is contained in:
1 parent
3bfed6d812
commit
9e50918718
14 files changed
+273
-84
No files matched your search
@@ -16,6 +16,7 @@
|
||||
- Added `WUFFS_BASE__PIXEL_FORMAT__BGR_565`.
|
||||
- Added interfaces.
|
||||
- Added preprocessor.
|
||||
- Added single-quoted strings.
|
||||
- Added tokens.
|
||||
- Changed `gif.decoder_workbuf_len_max_incl_worst_case` from 1 to 0.
|
||||
- Made `wuffs_base__pixel_format` a struct.
|
||||
|
||||
@@ -22,9 +22,6 @@ Minor features or restrictions include:
|
||||
- [Iterate loops](/doc/note/iterate-loops.md).
|
||||
- Public vs private API is marked with the `pub` and `pri` keywords. Visibility
|
||||
boundaries are at the package level, unlike C++ or Java's type level.
|
||||
- No string type, only [slices](/doc/note/slices-arrays-and-tables.md) of
|
||||
`base.u8`. Literals like `"#bad checksum"` are actually
|
||||
[statuses](/doc/note/statuses.md).
|
||||
- No variable shadowing. All local variables must be declared before any other
|
||||
statements in a function body.
|
||||
- Like Go, semi-colons can be omitted. Similarly, the `()` parentheses around
|
||||
@@ -88,6 +85,34 @@ definition, these never overflow.
|
||||
The `as` operator, e.g. `x as T`, converts an expression `x` to the type `T`.
|
||||
|
||||
|
||||
## Strings
|
||||
|
||||
There is no string type. There are [arrays and
|
||||
slices](/doc/note/slices-arrays-and-tables.md) of bytes (`base.u8`s), but bear
|
||||
in mind that Wuffs code cannot [allocate or free
|
||||
memory](/doc/note/memory-safety.md).
|
||||
|
||||
Double-quoted literals like `"#bad checksum"` are actually
|
||||
[statuses](/doc/note/statuses.md), [axiom names](/doc/note/assertions.md) or a
|
||||
`use "std/foo"` package name.
|
||||
|
||||
Single-quoted literals are actually numerical constants. For example, `'A'` and
|
||||
`'\t'` are equivalent to `0x41` and `0x09`. These literals are not restricted
|
||||
to a single ASCII byte or even a single Unicode code point, and can decode to
|
||||
multiple bytes when finished with a `be` or `le` endianness suffix. For
|
||||
example, `'\x01\x02'be` is equivalent to `0x0102`. Similarly, `'\u0394?'le`
|
||||
(which can also be written `'Δ?'le`) is equivalent to `0x3F94CE`, because the
|
||||
UTF-8 encodings of U+0394 GREEK CAPITAL LETTER DELTA and U+003F QUESTION MARK
|
||||
(the ASCII `?`) is `(0xCE, 0x94)` and `(0x3F)`.
|
||||
|
||||
Double-quoted literals cannot contain backslashes, as they'd be an unnecessary
|
||||
complication. Single-quoted literals can contain backslash-escapes, as they are
|
||||
often compared with arbitrary binary data. For example, where other programming
|
||||
languages would check if JPEG data starts with the magic _string_ `"\xFF\xD8"`,
|
||||
Wuffs would check if its opening 2 bytes, read as a little-endian `base.u16`,
|
||||
is a _number_ that equals `'\xFF\xD8'le`.
|
||||
|
||||
|
||||
## Introductory Example
|
||||
|
||||
A simple Wuffs the Language program, unrelated to Wuffs the Library, is
|
||||
|
||||
Reference in new issue
Block a user