diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-07-24 16:05:48 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-07-24 16:27:20 -0400 |
| commit | 042f6de478b67b2a19fc5acaa4999d54700f6db8 (patch) | |
| tree | ee3c2683f94747c0bd25832bfbb6fe2034f7e21c | |
| parent | c52a8a5f86707eeb71bcb44e2f691c67c9383500 (diff) | |
Remove printing facilities for `Regular_Expression`
The `original_pattern` introduced a tenuous dependency to the expression
value as a whole, and after some consideration, I decided that it would
be better for the developer to manage their own pattern strings.
In the event you need to print the text representation of a pattern,
it's usually better that you manage the memory of it as well.
| -rw-r--r-- | core/fmt/fmt.odin | 16 | ||||
| -rw-r--r-- | core/text/regex/regex.odin | 2 | ||||
| -rw-r--r-- | tests/benchmark/text/regex/benchmark_regex.odin | 8 | ||||
| -rw-r--r-- | tests/core/text/regex/test_core_text_regex.odin | 22 |
4 files changed, 4 insertions, 44 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 22ac1cc36..9aa9c99dc 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -9,7 +9,6 @@ import "core:io" import "core:reflect" import "core:strconv" import "core:strings" -import "core:text/regex" import "core:time" import "core:unicode/utf8" @@ -2406,21 +2405,6 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named) write_padded_number(fi, (ns), 9) io.write_string(fi.writer, " +0000 UTC", &fi.n) return - - case regex.Regular_Expression: - io.write_byte(fi.writer, '/') - for r in a.original_pattern { - if r == '/' { - io.write_string(fi.writer, `\/`) - } else { - io.write_rune(fi.writer, r) - } - } - io.write_byte(fi.writer, '/') - for flag in a.flags { - io.write_byte(fi.writer, regex.Flag_To_Letter[flag]) - } - return } } diff --git a/core/text/regex/regex.odin b/core/text/regex/regex.odin index 1736f2305..0bb0b7824 100644 --- a/core/text/regex/regex.odin +++ b/core/text/regex/regex.odin @@ -30,7 +30,6 @@ Capture :: struct { } Regular_Expression :: struct { - original_pattern: string, flags: Flags, class_data: []virtual_machine.Rune_Class_Data, program: []virtual_machine.Opcode `fmt:"-"`, @@ -92,7 +91,6 @@ create :: proc( // allocator so everything can be tightly packed. context.allocator = permanent_allocator - result.original_pattern = pattern result.flags = flags if len(class_data) > 0 { diff --git a/tests/benchmark/text/regex/benchmark_regex.odin b/tests/benchmark/text/regex/benchmark_regex.odin index cd9812b08..8d29888a3 100644 --- a/tests/benchmark/text/regex/benchmark_regex.odin +++ b/tests/benchmark/text/regex/benchmark_regex.odin @@ -111,7 +111,7 @@ global_capture_end_word :: proc(t: ^testing.T) { } defer regex.destroy(rex) - report := fmt.tprintf("Matching %v over a block of random ASCII text.", rex) + report := fmt.tprintf("Matching %q over a block of random ASCII text.", EXPR) for size in sizes { data := make([]u8, size) @@ -151,7 +151,7 @@ global_capture_end_word_unicode :: proc(t: ^testing.T) { } defer regex.destroy(rex) - report := fmt.tprintf("Matching %v over a block of random Unicode text.", rex) + report := fmt.tprintf("Matching %q over a block of random Unicode text.", EXPR) for size in sizes { data := make([]u8, size) @@ -191,7 +191,7 @@ alternations :: proc(t: ^testing.T) { } defer regex.destroy(rex) - report := fmt.tprintf("Matching %v over a text block of only `a`s.", rex) + report := fmt.tprintf("Matching %q over a text block of only `a`s.", EXPR) for size in sizes { data := make([]u8, size) @@ -225,7 +225,7 @@ classes :: proc(t: ^testing.T) { } defer regex.destroy(rex) - report := fmt.tprintf("Matching %v over a string of spaces with %q at the end.", rex, NEEDLE) + report := fmt.tprintf("Matching %q over a string of spaces with %q at the end.", EXPR, NEEDLE) for size in sizes { data := make([]u8, size) diff --git a/tests/core/text/regex/test_core_text_regex.odin b/tests/core/text/regex/test_core_text_regex.odin index 74a0b8cf7..8ecf6cef2 100644 --- a/tests/core/text/regex/test_core_text_regex.odin +++ b/tests/core/text/regex/test_core_text_regex.odin @@ -681,28 +681,6 @@ test_optional_inside_optional :: proc(t: ^testing.T) { check_expression(t, EXPR, "", "") } -@test -test_printing :: proc(t: ^testing.T) { - rex, err := regex.create(`^/a$`, { - .Global, - .Multiline, - .Case_Insensitive, - .Unicode, - .Ignore_Whitespace, - .No_Optimization, - .No_Capture, - }) - if !testing.expect_value(t, err, nil) { - return - } - defer regex.destroy(rex) - - str := fmt.tprint(rex) - str_hash := fmt.tprintf("%#v", rex) - testing.expect_value(t, str, `/^\/a$/gmixun-`) - testing.expect_value(t, str_hash, `/^\/a$/gmixun-`) -} - @test |