Struct StringCache
The string cache is used for string interning.
struct StringCache
;
It will only store a single copy of any string that it is asked to hold. Interned strings can be compared for equality by comparing their .ptr field.
Default and postbilt constructors are disabled. When a StringCache goes out of scope, the memory held by it is freed.
Constructors
Name | Description |
---|---|
this
()
|
|
this
(bucketCount)
|
Methods
Name | Description |
---|---|
intern
(str)
|
Caches a string. |
See also
Example
Test \x char sequence
auto toks = (string s) => byToken(cast(ubyte[])s);
// valid
immutable hex = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F'];
auto source = "";
foreach (h1; hex)
foreach (h2; hex)
source ~= "'\\x" ~ h1 ~ h2 ~ "'";
assert (toks(source) .filter!(t => t .type != tok!"characterLiteral") .empty);
// invalid
assert (toks(`'\x'`) .messages[0] == DLexer .Message(1,4,"Error: 2 hex digits expected.",true));
assert (toks(`'\x_'`) .messages[0] == DLexer .Message(1,4,"Error: 2 hex digits expected.",true));
assert (toks(`'\xA'`) .messages[0] == DLexer .Message(1,5,"Error: 2 hex digits expected.",true));
assert (toks(`'\xAY'`) .messages[0] == DLexer .Message(1,5,"Error: 2 hex digits expected.",true));
assert (toks(`'\xXX'`) .messages[0] == DLexer .Message(1,4,"Error: 2 hex digits expected.",true));