diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-06-29 10:52:31 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-06-29 10:52:31 +0300 |
commit | 66d48b272e6379acb5ee5f1df532e472e1b142fd (patch) | |
tree | ad84265cdd84a88ed65ec149aa9ecdd84f506b04 /source/blender/gpu/intern | |
parent | ee0c3081b08ab2c97dd86215cb9e444d16c2e19a (diff) |
Cleanup: GPU Shader Log Parsing.
- Added functions to check if the cursor is at a number.
- Added function to parse a number.
- Joined skip_separator functions.
- Added function to check if cursor is at any given set of characters.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_log.cc | 31 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_private.hh | 7 |
2 files changed, 35 insertions, 3 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_log.cc b/source/blender/gpu/intern/gpu_shader_log.cc index 5859afb7fbf..12459b4b721 100644 --- a/source/blender/gpu/intern/gpu_shader_log.cc +++ b/source/blender/gpu/intern/gpu_shader_log.cc @@ -177,14 +177,41 @@ char *GPULogParser::skip_severity(char *log_line, return log_line; } -char *GPULogParser::skip_separators(char *log_line, char sep1, char sep2, char sep3) const +char *GPULogParser::skip_separators(char *log_line, const StringRef separators) const { - while (ELEM(log_line[0], sep1, sep2, sep3)) { + while (at_any(log_line, separators)) { log_line++; } return log_line; } +char *GPULogParser::skip_until(char *log_line, char stop_char) const +{ + char *cursor = log_line; + while (!ELEM(cursor[0], '\n', '\0')) { + if (cursor[0] == stop_char) { + return cursor; + } + cursor++; + } + return log_line; +} + +bool GPULogParser::at_number(const char *log_line) const +{ + return log_line[0] >= '0' && log_line[0] <= '9'; +} + +bool GPULogParser::at_any(const char *log_line, const StringRef chars) const +{ + return chars.find(log_line[0]) != StringRef::not_found; +} + +int GPULogParser::parse_number(const char *log_line, char **r_new_position) const +{ + return (int)strtol(log_line, r_new_position, 10); +} + /** \} */ } // namespace blender::gpu diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh index ebdfc3478f8..65720e457d8 100644 --- a/source/blender/gpu/intern/gpu_shader_private.hh +++ b/source/blender/gpu/intern/gpu_shader_private.hh @@ -21,6 +21,7 @@ #pragma once #include "BLI_span.hh" +#include "BLI_string_ref.hh" #include "GPU_shader.h" #include "gpu_shader_interface.hh" @@ -123,7 +124,11 @@ class GPULogParser { GPULogItem &log_item, const char *error_msg, const char *warning_msg) const; - char *skip_separators(char *log_line, char sep1, char sep2, char sep3) const; + char *skip_separators(char *log_line, const StringRef separators) const; + char *skip_until(char *log_line, char stop_char) const; + bool at_number(const char *log_line) const; + bool at_any(const char *log_line, const StringRef chars) const; + int parse_number(const char *log_line, char **r_new_position) const; MEM_CXX_CLASS_ALLOC_FUNCS("GPULogParser"); }; |