Skip to content

Commit

Permalink
Minor revisions to StringView helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Valakor committed Feb 27, 2025
1 parent e86012a commit 6d81924
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions vendor/wgpu/wgpu.odin
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,29 @@ StringView :: struct {

STRLEN :: max(uint)

STRINGVIEW_NIL :: StringView{nil, STRLEN}
STRINGVIEW_EMPTY :: StringView{nil, 0}

StringView_CreateCString :: proc(str: cstring) -> StringView {
return {str, STRLEN}
}

StringView_CreateString :: proc(str: string) -> StringView {
return {strings.unsafe_string_to_cstring(str), len(str)}
}

StringView_Create :: proc {
StringView_CreateCString,
StringView_CreateString,
}

StringView_Formatter :: proc(fi: ^fmt.Info, arg: any, verb: rune) -> bool {
v := cast(^StringView)arg.data
switch verb {
case 'v', 's', 'q':
case 'v', 'w', 's', 'q':
switch {
case v^ == StringView_CreateNil():
fmt.fmt_string(fi, "nil", verb)
case v^ == STRINGVIEW_NIL:
fmt.fmt_string(fi, "<nil>", verb)

case v.length == 0:
fmt.fmt_string(fi, "", verb)
Expand All @@ -132,27 +148,6 @@ StringView_Formatter :: proc(fi: ^fmt.Info, arg: any, verb: rune) -> bool {
}
}

StringView_CreateNil :: proc() -> StringView {
return {nil, STRLEN}
}

StringView_CreateEmpty :: proc() -> StringView {
return {nil, 0}
}

StringView_CreateCString :: proc(str: cstring) -> StringView {
return {str, STRLEN}
}

StringView_CreateString :: proc(str: string) -> StringView {
return {strings.unsafe_string_to_cstring(str), len(str)}
}

StringView_Create :: proc {
StringView_CreateCString,
StringView_CreateString,
}

Adapter :: distinct rawptr
BindGroup :: distinct rawptr
BindGroupLayout :: distinct rawptr
Expand Down

0 comments on commit 6d81924

Please sign in to comment.