mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Sort enum entities; Remove sprint* from fmt.odin
This commit is contained in:
+39
-69
@@ -2,30 +2,6 @@
|
||||
|
||||
PRINT_BUF_SIZE :: 1<<12
|
||||
|
||||
bprint :: proc(buf: ^[]byte, args: ..any) {
|
||||
prev_string := false
|
||||
|
||||
for i := 0; i < args.count; i++ {
|
||||
arg := args[i]
|
||||
is_string := arg.data != null && type_info_is_string(arg.type_info)
|
||||
if i > 0 && !is_string && !prev_string {
|
||||
print_space_to_buffer(buf)
|
||||
}
|
||||
print_any_to_buffer(buf, arg)
|
||||
prev_string = is_string;
|
||||
}
|
||||
}
|
||||
|
||||
bprintln :: proc(buf: ^[]byte, args: ..any) {
|
||||
for i := 0; i < args.count; i++ {
|
||||
if i > 0 {
|
||||
append(buf, #rune " ")
|
||||
}
|
||||
print_any_to_buffer(buf, args[i])
|
||||
}
|
||||
print_nl_to_buffer(buf)
|
||||
}
|
||||
|
||||
fprint :: proc(f: ^os.File, args: ..any) {
|
||||
data: [PRINT_BUF_SIZE]byte
|
||||
buf := data[:0]
|
||||
@@ -57,31 +33,6 @@ printf :: proc(fmt: string, args: ..any) {
|
||||
fprintf(os.stdout, fmt, ..args)
|
||||
}
|
||||
|
||||
sprint :: proc(args: ..any) -> string {
|
||||
data: [PRINT_BUF_SIZE]byte
|
||||
buf := data[:0]
|
||||
bprint(^buf, ..args)
|
||||
s := new_slice(byte, buf.count)
|
||||
copy(s, buf)
|
||||
return s as string
|
||||
}
|
||||
sprintln :: proc(args: ..any) -> string {
|
||||
data: [PRINT_BUF_SIZE]byte
|
||||
buf := data[:0]
|
||||
bprintln(^buf, ..args)
|
||||
s := new_slice(byte, buf.count)
|
||||
copy(s, buf)
|
||||
return s as string
|
||||
}
|
||||
sprintf :: proc(fmt: string, args: ..any) -> string {
|
||||
data: [PRINT_BUF_SIZE]byte
|
||||
buf := data[:0]
|
||||
bprintf(^buf, fmt, ..args)
|
||||
s := new_slice(byte, buf.count)
|
||||
copy(s, buf)
|
||||
return s as string
|
||||
}
|
||||
|
||||
|
||||
|
||||
fprint_type :: proc(f: ^os.File, info: ^Type_Info) {
|
||||
@@ -578,26 +529,6 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {
|
||||
}
|
||||
}
|
||||
|
||||
type_info_is_string :: proc(info: ^Type_Info) -> bool {
|
||||
using Type_Info
|
||||
if info == null {
|
||||
return false
|
||||
}
|
||||
|
||||
for {
|
||||
match type i : info {
|
||||
case Named:
|
||||
info = i.base
|
||||
continue
|
||||
case String:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) {
|
||||
is_digit :: proc(r: rune) -> bool #inline {
|
||||
@@ -661,3 +592,42 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) {
|
||||
|
||||
print_string_to_buffer(buf, fmt[prev:])
|
||||
}
|
||||
|
||||
|
||||
bprint :: proc(buf: ^[]byte, args: ..any) {
|
||||
is_type_string :: proc(info: ^Type_Info) -> bool {
|
||||
using Type_Info
|
||||
info = type_info_base(info)
|
||||
if info == null {
|
||||
return false
|
||||
}
|
||||
|
||||
match type i : info {
|
||||
case String:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
prev_string := false
|
||||
for i := 0; i < args.count; i++ {
|
||||
arg := args[i]
|
||||
is_string := arg.data != null && is_type_string(arg.type_info)
|
||||
if i > 0 && !is_string && !prev_string {
|
||||
print_space_to_buffer(buf)
|
||||
}
|
||||
print_any_to_buffer(buf, arg)
|
||||
prev_string = is_string;
|
||||
}
|
||||
}
|
||||
|
||||
bprintln :: proc(buf: ^[]byte, args: ..any) {
|
||||
for i := 0; i < args.count; i++ {
|
||||
if i > 0 {
|
||||
append(buf, #rune " ")
|
||||
}
|
||||
print_any_to_buffer(buf, args[i])
|
||||
}
|
||||
print_nl_to_buffer(buf)
|
||||
}
|
||||
|
||||
+5
-8
@@ -64,6 +64,9 @@ Type_Info :: union {
|
||||
}
|
||||
|
||||
type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
|
||||
if info == null {
|
||||
return null
|
||||
}
|
||||
for {
|
||||
match type i : info {
|
||||
case Type_Info.Named:
|
||||
@@ -355,17 +358,11 @@ __default_allocator :: proc() -> Allocator {
|
||||
|
||||
|
||||
__enum_to_string :: proc(info: ^Type_Info, value: i64) -> string {
|
||||
for {
|
||||
match type i : info {
|
||||
case Type_Info.Named:
|
||||
info = i.base
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
info = type_info_base(info)
|
||||
|
||||
match type ti : info {
|
||||
case Type_Info.Enum:
|
||||
// TODO(bill): Search faster than linearly
|
||||
for i := 0; i < ti.values.count; i++ {
|
||||
if ti.values[i] == value {
|
||||
return ti.names[i]
|
||||
|
||||
Reference in New Issue
Block a user