-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Type Independent String Functions #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
40f016f
54b5c00
ae1b7e4
3f20233
39d92e8
ec3194a
714b89c
4793904
23d424c
1f47341
48028ce
ebca31a
66a0559
932eb6f
1648192
1a75cdf
15ccce7
6868c71
a307291
9e4206c
2ace38b
f570f18
dfdfde2
0999ea8
fb24ebc
8b9db75
2f027b7
3639e7a
dc3cfda
dd349fb
5b8012b
f3bf4f6
b0ea58a
6fcbf6e
2d2477a
b2cbcb5
ded5e5d
8453786
c6ff5e4
a2269f9
6e61be7
6294dd4
4dc263e
17dc853
b8d1995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ const os = std.os; | |
const warn = std.debug.warn; | ||
const mem = std.mem; | ||
const assert = std.debug.assert; | ||
const string = std.string; | ||
|
||
const max_doc_file_size = 10 * 1024 * 1024; | ||
|
||
|
@@ -309,7 +310,7 @@ const Node = union(enum) { | |
const Toc = struct { | ||
nodes: []Node, | ||
toc: []u8, | ||
urls: std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8), | ||
urls: std.HashMap([]const u8, Token, string.hashStr, string.strEql), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this hash map is hashing bytes, not strings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this shows a problem with the way its done because the hash_slice_u8 for example and hashStr would be identical and that leads to a singular name meaning two different things, I guess how would you approach this because in situations where it is hashing strings not bytes it leads to this same problem? I would either declare aliases or just live with one of them. |
||
}; | ||
|
||
const Action = enum { | ||
|
@@ -318,7 +319,7 @@ const Action = enum { | |
}; | ||
|
||
fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc { | ||
var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator); | ||
var urls = std.HashMap([]const u8, Token, string.hashStr, string.strEql).init(allocator); | ||
errdefer urls.deinit(); | ||
|
||
var header_stack_size: usize = 0; | ||
|
@@ -600,7 +601,7 @@ const TermState = enum { | |
test "term color" { | ||
const input_bytes = "A\x1b[32;1mgreen\x1b[0mB"; | ||
const result = try termColor(std.debug.global_allocator, input_bytes); | ||
assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B")); | ||
assert(mem.eql(u8, result, "A<span class=\"t32_1\">green</span>B")); | ||
} | ||
|
||
fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 { | ||
|
@@ -718,7 +719,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var | |
warn("docgen example code {}/{}...", code_progress_index, tokenizer.code_node_count); | ||
|
||
const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end]; | ||
const trimmed_raw_source = mem.trim(u8, raw_source, " \n"); | ||
const trimmed_raw_source = mem.trim(u8, raw_source, " \n", mem.Side.BOTH); | ||
const escaped_source = try escapeHtml(allocator, trimmed_raw_source); | ||
if (!code.is_inline) { | ||
try out.print("<p class=\"file\">{}.zig</p>", code.name); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't changed my mind about this since the last PR comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need more clarification about what specifically you dislike :). Is it the call name ? Like is it just because it is not called
string.split
or is it the fact it uses generics behind the scene?Again i'm happy to remove the type independent stuff if need be :)