summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-05-31 15:08:22 +0100
committerLinus Groh <mail@linusgroh.de>2021-05-31 17:43:54 +0100
commitdac0554fa05fa35de0f3ccbbb8f68c4125739d6f (patch)
tree8deaf1c890fd2b48052d637f8f6c9a6d72e441a4 /Userland
parent81b7b2f49e32c9f85f32461d6ec2311424998e09 (diff)
downloadserenity-dac0554fa05fa35de0f3ccbbb8f68c4125739d6f.zip
LibRegex: Replace fprintf()/printf() with warnln()/outln()/dbgln()
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibRegex/RegexByteCode.cpp4
-rw-r--r--Userland/Libraries/LibRegex/RegexDebug.h25
-rw-r--r--Userland/Libraries/LibRegex/RegexLexer.cpp4
-rw-r--r--Userland/Libraries/LibRegex/RegexMatcher.cpp8
-rw-r--r--Userland/Libraries/LibRegex/RegexParser.cpp6
5 files changed, 20 insertions, 27 deletions
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp
index a85b6e87db..68009575e0 100644
--- a/Userland/Libraries/LibRegex/RegexByteCode.cpp
+++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp
@@ -362,7 +362,7 @@ ALWAYS_INLINE ExecutionResult OpCode_SaveRightNamedCaptureGroup::execute(const M
map.set(capture_group_name, { view, input.line, start_position, input.global_offset + start_position }); // take view to original string
}
} else {
- fprintf(stderr, "Didn't find corresponding capture group match for name=%s, match_index=%lu\n", capture_group_name.to_string().characters(), input.match_index);
+ warnln("Didn't find corresponding capture group match for name={}, match_index={}", capture_group_name.to_string(), input.match_index);
}
return ExecutionResult::Continue;
@@ -490,7 +490,7 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(const MatchInput& input, M
return ExecutionResult::Failed_ExecuteLowPrioForks;
} else {
- fprintf(stderr, "Undefined comparison: %i\n", (int)compare_type);
+ warnln("Undefined comparison: {}", (int)compare_type);
VERIFY_NOT_REACHED();
break;
}
diff --git a/Userland/Libraries/LibRegex/RegexDebug.h b/Userland/Libraries/LibRegex/RegexDebug.h
index 7ac77d38a8..821870242b 100644
--- a/Userland/Libraries/LibRegex/RegexDebug.h
+++ b/Userland/Libraries/LibRegex/RegexDebug.h
@@ -27,7 +27,7 @@ public:
auto& bytecode = regex.parser_result.bytecode;
size_t index { 0 };
for (auto& value : bytecode) {
- fprintf(m_file, "OpCode i=%3lu [0x%02X]\n", index, (u32)value);
+ outln(m_file, "OpCode i={:3} [{:#02X}]", index, (u32)value);
++index;
}
}
@@ -46,7 +46,7 @@ public:
}
print_opcode("PrintBytecode", *opcode, state);
- fprintf(m_file, "%s", m_debug_stripline.characters());
+ out(m_file, "{}", m_debug_stripline);
if (is<OpCode_Exit>(*opcode))
break;
@@ -59,19 +59,18 @@ public:
void print_opcode(const String& system, OpCode& opcode, MatchState& state, size_t recursion = 0, bool newline = true) const
{
- fprintf(m_file, "%-15s | %-5lu | %-9lu | %-35s | %-30s | %-20s%s",
+ out(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}",
system.characters(),
state.instruction_position,
recursion,
opcode.to_string().characters(),
opcode.arguments_string().characters(),
- String::formatted("ip: {:3}, sp: {:3}", state.instruction_position, state.string_position).characters(),
- newline ? "\n" : "");
-
+ String::formatted("ip: {:3}, sp: {:3}", state.instruction_position, state.string_position));
+ if (newline)
+ outln();
if (newline && is<OpCode_Compare>(opcode)) {
- for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_string()) {
- fprintf(m_file, "%-15s | %-5s | %-9s | %-35s | %-30s | %-20s%s", "", "", "", "", line.characters(), "", "\n");
- }
+ for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_string())
+ outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", line, "");
}
}
@@ -88,15 +87,15 @@ public:
builder.appendff(", next ip: {}", state.instruction_position + opcode.size());
}
- fprintf(m_file, " | %-20s\n", builder.to_string().characters());
+ out(m_file, " | {:20}", builder.to_string());
if (is<OpCode_Compare>(opcode)) {
for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_string(input)) {
- fprintf(m_file, "%-15s | %-5s | %-9s | %-35s | %-30s | %-20s%s", "", "", "", "", line.characters(), "", "\n");
+ outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", line, "");
}
}
- fprintf(m_file, "%s", m_debug_stripline.characters());
+ out(m_file, "{}", m_debug_stripline);
}
void print_header()
@@ -110,7 +109,7 @@ public:
auto str = builder.to_string();
VERIFY(!str.is_empty());
- fprintf(m_file, "%s\n", str.characters());
+ outln(m_file, "{}", str);
fflush(m_file);
builder.clear();
diff --git a/Userland/Libraries/LibRegex/RegexLexer.cpp b/Userland/Libraries/LibRegex/RegexLexer.cpp
index bd7ac684f6..f22778c0f2 100644
--- a/Userland/Libraries/LibRegex/RegexLexer.cpp
+++ b/Userland/Libraries/LibRegex/RegexLexer.cpp
@@ -7,6 +7,7 @@
#include "RegexLexer.h"
#include <AK/Assertions.h>
#include <AK/Debug.h>
+#include <AK/Format.h>
#include <stdio.h>
namespace regex {
@@ -130,8 +131,7 @@ Token Lexer::next()
case '\\':
return 2;
default:
- if constexpr (REGEX_DEBUG)
- fprintf(stderr, "[LEXER] Found invalid escape sequence: \\%c (the parser will have to deal with this!)\n", peek(1));
+ dbgln_if(REGEX_DEBUG, "[LEXER] Found invalid escape sequence: \\{:c} (the parser will have to deal with this!)", peek(1));
return 0;
}
};
diff --git a/Userland/Libraries/LibRegex/RegexMatcher.cpp b/Userland/Libraries/LibRegex/RegexMatcher.cpp
index e416ebe6e4..d294a01c83 100644
--- a/Userland/Libraries/LibRegex/RegexMatcher.cpp
+++ b/Userland/Libraries/LibRegex/RegexMatcher.cpp
@@ -363,16 +363,12 @@ ALWAYS_INLINE Optional<bool> Matcher<Parser>::execute_low_prio_forks(const Match
for (auto& state : states) {
state.instruction_position = state.fork_at_position;
-#if REGEX_DEBUG
- fprintf(stderr, "Forkstay... ip = %lu, sp = %lu\n", state.instruction_position, state.string_position);
-#endif
+ dbgln_if(REGEX_DEBUG, "Forkstay... ip = {}, sp = {}", state.instruction_position, state.string_position);
auto success = execute(input, state, output, recursion_level);
if (!success.has_value())
return {};
if (success.value()) {
-#if REGEX_DEBUG
- fprintf(stderr, "Forkstay succeeded... ip = %lu, sp = %lu\n", state.instruction_position, state.string_position);
-#endif
+ dbgln_if(REGEX_DEBUG, "Forkstay succeeded... ip = {}, sp = {}", state.instruction_position, state.string_position);
original_state = state;
return true;
}
diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp
index decbb8bbb1..7c5c34cf85 100644
--- a/Userland/Libraries/LibRegex/RegexParser.cpp
+++ b/Userland/Libraries/LibRegex/RegexParser.cpp
@@ -148,8 +148,7 @@ Parser::Result Parser::parse(Optional<AllOptions> regex_options)
else
set_error(Error::InvalidPattern);
- if constexpr (REGEX_DEBUG)
- fprintf(stderr, "[PARSER] Produced bytecode with %lu entries (opcodes + arguments)\n", m_parser_state.bytecode.size());
+ dbgln_if(REGEX_DEBUG, "[PARSER] Produced bytecode with {} entries (opcodes + arguments)", m_parser_state.bytecode.size());
return {
move(m_parser_state.bytecode),
move(m_parser_state.capture_groups_count),
@@ -460,8 +459,7 @@ ALWAYS_INLINE bool PosixExtendedParser::parse_sub_expression(ByteCode& stack, si
if (match(TokenType::EscapeSequence)) {
length = 1;
Token t = consume();
- if constexpr (REGEX_DEBUG)
- printf("[PARSER] EscapeSequence with substring %s\n", String(t.value()).characters());
+ dbgln_if(REGEX_DEBUG, "[PARSER] EscapeSequence with substring {}", t.value());
bytecode.insert_bytecode_compare_values({ { CharacterCompareType::Char, (u32)t.value().characters_without_null_termination()[1] } });
should_parse_repetition_symbol = true;