From 9dec568a3f5b8a65f3887a60f2819aed35a8771d Mon Sep 17 00:00:00 2001 From: Kharec Date: Tue, 11 Nov 2025 20:46:24 +0100 Subject: [PATCH] style: clang-format --- main.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index 95050ce..e095695 100644 --- a/main.cpp +++ b/main.cpp @@ -24,14 +24,15 @@ const map morse_map = { bool should_exit = false; bool is_exit(const string &s) { - return s.length() == 4 && tolower(s[0]) == 'e' && tolower(s[1]) == 'x' && + return s.length() == 4 && tolower(s[0]) == 'e' && tolower(s[1]) == 'x' && tolower(s[2]) == 'i' && tolower(s[3]) == 't'; } string read_input(const string &prompt) { cout << prompt; string line; - if (!getline(cin, line) || line.empty()) return ""; + if (!getline(cin, line) || line.empty()) + return ""; if (is_exit(line)) { should_exit = true; return ""; @@ -72,7 +73,7 @@ public: string sequence; sequence.reserve(text.length() * 5); bool need_space = false; - + for (char c : text) { if (c == ' ') { sequence += " / "; @@ -80,7 +81,8 @@ public: } else { string morse = encode(c); if (!morse.empty()) { - if (need_space) sequence += " "; + if (need_space) + sequence += " "; sequence += morse; need_space = true; } @@ -110,12 +112,15 @@ void decode_mode() { while (!should_exit) { string input = read_input("Enter morse sequence: "); - if (input.empty()) continue; - - if (tolower(input[0]) == 'e') return; + if (input.empty()) + continue; + + if (tolower(input[0]) == 'e') + return; size_t start = input.find_first_not_of(" \t"); - if (start == string::npos) continue; + if (start == string::npos) + continue; size_t end = input.find_last_not_of(" \t"); string decoded_message; @@ -139,7 +144,8 @@ void decode_mode() { decode_and_add(); in_separator = true; } - if (c == '/') needs_word_separator = true; + if (c == '/') + needs_word_separator = true; } else if (c == '.' || c == '-') { if (in_separator) { if (needs_word_separator && !decoded_message.empty()) { @@ -155,7 +161,8 @@ void decode_mode() { } } - if (!current_morse.empty()) decode_and_add(); + if (!current_morse.empty()) + decode_and_add(); if (has_invalid_chars) { cout << "\nWarning: Invalid characters were ignored.\n"; @@ -172,9 +179,11 @@ void encode_mode() { while (!should_exit) { string input = read_input("Enter text to encode: "); - if (input.empty()) continue; - - if (tolower(input[0]) == 'd') return; + if (input.empty()) + continue; + + if (tolower(input[0]) == 'd') + return; cout << "\n"; encoder.print_morse_pattern(input); @@ -191,7 +200,8 @@ int main() { decode ? decode_mode() : encode_mode(); if (!should_exit) { decode = !decode; - cout << "\nSwitched to " << (decode ? "decode" : "encode") << " mode.\n\n"; + cout << "\nSwitched to " << (decode ? "decode" : "encode") + << " mode.\n\n"; } }