Skip to content

Commit

Permalink
std.uni: use hex strings for TrieEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jan 25, 2024
1 parent 64457e8 commit 17b4f46
Show file tree
Hide file tree
Showing 6 changed files with 9,294 additions and 72 deletions.
1,604 changes: 1,600 additions & 4 deletions std/internal/unicode_comp.d

Large diffs are not rendered by default.

1,532 changes: 1,528 additions & 4 deletions std/internal/unicode_decomp.d

Large diffs are not rendered by default.

542 changes: 528 additions & 14 deletions std/internal/unicode_grapheme.d

Large diffs are not rendered by default.

458 changes: 450 additions & 8 deletions std/internal/unicode_norm.d

Large diffs are not rendered by default.

5,192 changes: 5,155 additions & 37 deletions std/internal/unicode_tables.d

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions tools/unicode_table_generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ struct UnicodeProperty
struct TrieEntry(T...)
{
size_t[] offsets;
size_t[] sizes;
size_t[] data;
immutable(size_t)[] offsets;
immutable(size_t)[] sizes;
immutable(size_t)[] data;
}
`;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ void writeCompositionTable(File sink)
{
writeln("enum composeIdxMask = (1 << 11) - 1, composeCntShift = 11;");
write("enum compositionJumpTrieEntries = TrieEntry!(ushort, 12, 9)(");
triT.store(sink.lockingTextWriter());
triT.storeTrie(sink.lockingTextWriter());
writeln(");");
writeDstringTable(sink, "compositionTable", dupletes.map!(x => only(x.expand)).joiner.array);
}
Expand Down Expand Up @@ -1428,8 +1428,36 @@ template createPrinter(Params...)
foreach (lvl; Params[0..$])
sink.writef(", %d", lvl);
sink.write(")(");
trie.store(sink.lockingTextWriter());
trie.storeTrie(sink.lockingTextWriter());
sink.writeln(");");
};
}
}

void storeTrie(T, O)(T trie, O sink)
{
import std.format.write : formattedWrite;
void store(size_t[] arr)
{
formattedWrite(sink, "cast(immutable size_t[]) x\"");
foreach (i; 0 .. arr.length)
{
static if (size_t.sizeof == 8)
{
formattedWrite(sink, (i % 6) == 0 ? "\n" : " ");
formattedWrite(sink, "%016X", arr[i]);
}
else
{
formattedWrite(sink, (i % 12) == 0 ? "\n" : " ");
formattedWrite(sink, "%08X", arr[i]);
}
}
formattedWrite(sink, "\",\n");
}
// Access private members
auto table = __traits(getMember, trie, "_table");
store(__traits(getMember, table, "offsets"));
store(__traits(getMember, table, "sz"));
store(__traits(getMember, table, "storage"));
}

0 comments on commit 17b4f46

Please sign in to comment.