From 35344263d35577b50948478126786284f875ac84 Mon Sep 17 00:00:00 2001 From: rail5 Date: Fri, 3 May 2024 18:51:04 +0800 Subject: [PATCH] General code cleanup --- edit/src/class_file.cpp | 10 +- edit/src/class_instruction.cpp | 14 +- edit/src/includes.h | 9 ++ edit/src/main.cpp | 12 +- edit/src/namespace_editor.h | 223 ++++++++++++++------------ read/src/class_file.cpp | 5 +- read/src/includes.h | 9 ++ read/src/main.cpp | 10 +- read/src/namespace_reader.h | 114 +++++++------ shared/definitions.h | 9 ++ shared/explode.cpp | 5 +- shared/file_exists.cpp | 4 + shared/file_is_writable.cpp | 4 + shared/is_directory.cpp | 6 +- shared/is_number.cpp | 7 +- shared/isolate_path_from_filename.cpp | 4 + shared/parse_block_units.cpp | 10 +- shared/parse_regex.cpp | 15 +- shared/process_bytecodes.cpp | 6 +- shared/process_escapedchars.cpp | 6 +- shared/remove_leading_whitespace.cpp | 4 + shared/string_ends_with.cpp | 4 + shared/string_starts_with.cpp | 4 + shared/to_lower.cpp | 6 +- 24 files changed, 300 insertions(+), 200 deletions(-) diff --git a/edit/src/class_file.cpp b/edit/src/class_file.cpp index 7635188..29b1ef3 100644 --- a/edit/src/class_file.cpp +++ b/edit/src/class_file.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef FILESYSTEM #define FILESYSTEM #include @@ -55,7 +59,6 @@ bool editor::file::set_file(std::string file_path) { initialized = false; return initialized; } - } /* @@ -160,7 +163,6 @@ bool editor::file::add_instruction(instruction &input_instruction) { bool end_position_is_eof = (input_instruction.get_end_position() == -1); if (start_position_is_eof) { - if (input_instruction.get_operation_type() == replace_operation) { /* REPLACE instructions are a special case with the 'END' keyword @@ -338,7 +340,6 @@ void editor::file::insert(int64_t start_position, std::string text_to_insert) { file_stream.write("\n", 1); for (int64_t i = (new_file_length - 1); i > start_position; i = (i - amount_to_store)) { - int64_t copy_to_this_position = (i - (amount_to_store - 1)) - 1; int64_t copy_from_this_position = (copy_to_this_position - insert_length); @@ -351,7 +352,6 @@ void editor::file::insert(int64_t start_position, std::string text_to_insert) { // (In the above example, 512 rather than 1024) // And set i = start_position to make sure the loop doesn't run again after this if (copy_from_this_position < start_position) { - int64_t difference = start_position - copy_from_this_position; copy_from_this_position = start_position; @@ -444,7 +444,6 @@ void editor::file::remove(int64_t start_position, int64_t end_position) { // Before EOF for (int64_t i = start_position; i < (new_file_length - 1); i = (i + amount_to_store)) { - int64_t copy_to_this_position = i; int64_t copy_from_this_position = (i + remove_length); @@ -496,7 +495,6 @@ void editor::file::remove(int64_t start_position, int64_t end_position) { } bool editor::file::execute_single_instruction(instruction instruction_to_execute) { - if (instruction_to_execute.get_operation_type() == replace_operation) { replace(instruction_to_execute.get_start_position(), instruction_to_execute.get_text()); return true; diff --git a/edit/src/class_instruction.cpp b/edit/src/class_instruction.cpp index 94ddd77..687b2ec 100644 --- a/edit/src/class_instruction.cpp +++ b/edit/src/class_instruction.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + void editor::instruction::clear_instruction() { /*** void clear_instruction(): @@ -23,7 +27,6 @@ void editor::instruction::process_special_chars() { text_input = process_bytecodes(text_input); end_position = (start_position + text_input.length()); - } bool editor::instruction::set_replace_instruction(int64_t start, std::string text) { @@ -314,7 +317,7 @@ editor::instruction parse_instruction_string(std::string instruction_string) { second_element_is_end = (second_element == "end"); - if ( ! (is_number(second_element) || (second_element_is_end)) ) { + if ( !(is_number(second_element) || (second_element_is_end)) ) { invalid_instruction.set_error_message("Invalid instruction: '" + instruction_vector[1] + "' is not a positive integer"); return invalid_instruction; } @@ -327,7 +330,7 @@ editor::instruction parse_instruction_string(std::string instruction_string) { third_element_is_end = (third_element == "end"); - if ( ! (is_number(instruction_vector[2]) || (third_element_is_end) )) { + if ( !(is_number(instruction_vector[2]) || (third_element_is_end)) ) { invalid_instruction.set_error_message("Invalid REMOVE instruction: '" + instruction_vector[2] + "' is not a positive integer"); return invalid_instruction; } @@ -341,7 +344,6 @@ editor::instruction parse_instruction_string(std::string instruction_string) { int64_t end_position; if (is_replace_instruction) { - if (second_element_is_end) { start_position = -1; } else { @@ -352,7 +354,6 @@ editor::instruction parse_instruction_string(std::string instruction_string) { } if (is_insert_instruction) { - if (second_element_is_end) { start_position = -1; } else { @@ -363,7 +364,6 @@ editor::instruction parse_instruction_string(std::string instruction_string) { } if (is_remove_instruction) { - if (second_element_is_end) { start_position = -1; } else { @@ -406,7 +406,7 @@ std::vector parse_instruction_set_string(std::string instru std::vector instruction_strings = explode(instruction_set_string, '\n'); for (std::string i : instruction_strings) { - output_instruction_set.push_back( parse_instruction_string(i) ); + output_instruction_set.push_back(parse_instruction_string(i)); } return output_instruction_set; diff --git a/edit/src/includes.h b/edit/src/includes.h index b31d875..f325da5 100644 --- a/edit/src/includes.h +++ b/edit/src/includes.h @@ -1,3 +1,10 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + +#ifndef EDIT_SRC_INCLUDES_H_ +#define EDIT_SRC_INCLUDES_H_ + /* Needed for I/O */ #ifndef IOSTREAM #define IOSTREAM @@ -128,3 +135,5 @@ #include "namespace_editor.h" #include "class_instruction.cpp" #include "class_file.cpp" + +#endif // EDIT_SRC_INCLUDES_H_ diff --git a/edit/src/main.cpp b/edit/src/main.cpp index e719737..3869503 100644 --- a/edit/src/main.cpp +++ b/edit/src/main.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #include "includes.h" #ifndef IOSTREAM @@ -11,7 +15,6 @@ #endif int main(int argc, char* argv[]) { - std::string program_name = "polonius-editor"; std::string help_string = @@ -101,8 +104,7 @@ int main(int argc, char* argv[]) { opterr = 0; int option_index = 0; - static struct option long_options[] = - { + static struct option long_options[] = { {"input", required_argument, 0, 'i'}, {"add-instruction-set", required_argument, 0, 's'}, @@ -170,7 +172,7 @@ int main(int argc, char* argv[]) { case '?': if (optopt == 'i' || optopt == 's' || optopt == 'a' || optopt == 'b') { - std::cerr << program_name << ": Option -" << (char)optopt << " requires an argument" << std::endl << "Use -h for help" << std::endl; + std::cerr << program_name << ": Option -" << static_cast(optopt) << " requires an argument" << std::endl << "Use -h for help" << std::endl; return EXIT_BADOPT; } break; @@ -199,7 +201,6 @@ int main(int argc, char* argv[]) { } for (int i = 0; i < instructions_to_add.size(); i++) { - if (interpret_special_chars) { instructions_to_add[i].process_special_chars(); } @@ -219,5 +220,4 @@ int main(int argc, char* argv[]) { /* Close file */ document.close(); return EXIT_SUCCESS; - } diff --git a/edit/src/namespace_editor.h b/edit/src/namespace_editor.h index fc0c006..e85c58b 100644 --- a/edit/src/namespace_editor.h +++ b/edit/src/namespace_editor.h @@ -1,114 +1,123 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + +#ifndef EDIT_SRC_NAMESPACE_EDITOR_H_ +#define EDIT_SRC_NAMESPACE_EDITOR_H_ + namespace editor { - enum operation_type { - no_operation, - replace_operation, - insert_operation, - remove_operation - }; +enum operation_type { + no_operation, + replace_operation, + insert_operation, + remove_operation +}; - class instruction { - private: - bool initialized = false; - - operation_type operation = no_operation; - /* - Operation types: - 0 = none - 1 = replace - 2 = insert - 3 = remove - */ - - int64_t start_position = -1; - int64_t end_position = -1; - std::string text_input = ""; - - std::string error_message = ""; - public: - void clear_instruction(); - void process_special_chars(); - bool set_replace_instruction(int64_t start, std::string text); - bool set_insert_instruction(int64_t start, std::string text); - bool set_remove_instruction(int64_t start, int64_t end); - void set_error_message(std::string message); - - std::string get_error_message(); +class instruction { + private: + bool initialized = false; + + operation_type operation = no_operation; + /* + Operation types: + 0 = none + 1 = replace + 2 = insert + 3 = remove + */ + + int64_t start_position = -1; + int64_t end_position = -1; + std::string text_input = ""; + + std::string error_message = ""; - void update_start_position(int64_t start); - void update_end_position(int64_t end); - - bool is_initialized(); - int get_operation_type(); - int64_t get_start_position(); - int64_t get_end_position(); - std::string get_text(); + public: + void clear_instruction(); + void process_special_chars(); + bool set_replace_instruction(int64_t start, std::string text); + bool set_insert_instruction(int64_t start, std::string text); + bool set_remove_instruction(int64_t start, int64_t end); + void set_error_message(std::string message); + + std::string get_error_message(); - }; - - instruction create_replace_instruction(int64_t start_position, std::string text); - instruction create_insert_instruction(int64_t start_position, std::string text); - instruction create_remove_instruction(int64_t start_position, int64_t end_position); - - instruction parse_instruction_string(std::string instruction_string); - - std::vector parse_instruction_set_string(std::string instruction_set); + void update_start_position(int64_t start); + void update_end_position(int64_t end); + + bool is_initialized(); + int get_operation_type(); + int64_t get_start_position(); + int64_t get_end_position(); + std::string get_text(); +}; - class file { - private: - bool initialized = false; - - std::string file_name; - std::string file_directory; - - int64_t file_length = 0; - - std::fstream file_stream; - FILE* c_type_file; - int file_descriptor; - - int block_size = 10240; - - std::vector instruction_set; - int64_t file_length_after_last_instruction = 0; - - std::string error_message = ""; - - bool verbose = false; - public: - bool set_file(std::string file_path); - - void set_block_size(int specified_blocksize); - - void replace(int64_t start_position, std::string replacement_text); - void insert(int64_t start_position, std::string text_to_insert); - void remove(int64_t start_position, int64_t end_position); - - bool add_instruction(instruction &input_instruction); - - bool execute_single_instruction(instruction instruction_to_execute); - - bool execute_instructions(); - - bool is_initialized(); - - std::string get_file_name(); - std::string get_file_directory(); - - int get_block_size(); - - int64_t get_file_length(); - - std::vector get_instruction_set(); - - std::string get_error_message(); - - void close(); - - /* - Constructor - */ - file(std::string path, int blocksize = 10240, bool verbose_mode = false); - }; +instruction create_replace_instruction(int64_t start_position, std::string text); +instruction create_insert_instruction(int64_t start_position, std::string text); +instruction create_remove_instruction(int64_t start_position, int64_t end_position); -} +instruction parse_instruction_string(std::string instruction_string); + +std::vector parse_instruction_set_string(std::string instruction_set); + +class file { + private: + bool initialized = false; + + std::string file_name; + std::string file_directory; + + int64_t file_length = 0; + + std::fstream file_stream; + FILE* c_type_file; + int file_descriptor; + + int block_size = 10240; + + std::vector instruction_set; + int64_t file_length_after_last_instruction = 0; + + std::string error_message = ""; + + bool verbose = false; + + public: + bool set_file(std::string file_path); + + void set_block_size(int specified_blocksize); + + void replace(int64_t start_position, std::string replacement_text); + void insert(int64_t start_position, std::string text_to_insert); + void remove(int64_t start_position, int64_t end_position); + + bool add_instruction(instruction &input_instruction); + + bool execute_single_instruction(instruction instruction_to_execute); + + bool execute_instructions(); + + bool is_initialized(); + + std::string get_file_name(); + std::string get_file_directory(); + + int get_block_size(); + + int64_t get_file_length(); + + std::vector get_instruction_set(); + + std::string get_error_message(); + + void close(); + + /* + Constructor + */ + explicit file(std::string path, int blocksize = 10240, bool verbose_mode = false); +}; +} // namespace editor + +#endif // EDIT_SRC_NAMESPACE_EDITOR_H_ diff --git a/read/src/class_file.cpp b/read/src/class_file.cpp index 223a668..5367324 100644 --- a/read/src/class_file.cpp +++ b/read/src/class_file.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef FSTREAM #define FSTREAM #include @@ -38,7 +42,6 @@ bool reader::file::init(std::string path) { } std::string reader::file::read(int64_t start_position, int64_t length) { - std::ifstream file_stream(file_name, std::ifstream::binary); // allocate memory diff --git a/read/src/includes.h b/read/src/includes.h index d4bfe45..0f49423 100644 --- a/read/src/includes.h +++ b/read/src/includes.h @@ -1,3 +1,10 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + +#ifndef READ_SRC_INCLUDES_H_ +#define READ_SRC_INCLUDES_H_ + /* Needed for I/O */ #ifndef IOSTREAM #define IOSTREAM @@ -103,3 +110,5 @@ /* Contains the 'meat' of the program */ #include "namespace_reader.h" #include "class_file.cpp" + +#endif // READ_SRC_INCLUDES_H_ diff --git a/read/src/main.cpp b/read/src/main.cpp index 8f17823..23cbfef 100644 --- a/read/src/main.cpp +++ b/read/src/main.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #include "includes.h" #ifndef IOSTREAM @@ -11,7 +15,6 @@ #endif int main(int argc, char* argv[]) { - std::string program_name = "polonius-reader"; std::string help_string = @@ -111,8 +114,7 @@ int main(int argc, char* argv[]) { opterr = 0; int option_index = 0; - static struct option long_options[] = - { + static struct option long_options[] = { {"input", required_argument, 0, 'i'}, {"start", required_argument, 0, 's'}, {"length", required_argument, 0, 'l'}, @@ -190,7 +192,7 @@ int main(int argc, char* argv[]) { case '?': if (optopt == 'i' || optopt == 's' || optopt == 'l') { - std::cerr << program_name << ": Option -" << (char)optopt << " requires an argument" << std::endl << "Use -h for help" << std::endl; + std::cerr << program_name << ": Option -" << static_cast(optopt) << " requires an argument" << std::endl << "Use -h for help" << std::endl; return EXIT_BADOPT; } break; diff --git a/read/src/namespace_reader.h b/read/src/namespace_reader.h index e1f12d4..75f8a3c 100644 --- a/read/src/namespace_reader.h +++ b/read/src/namespace_reader.h @@ -1,58 +1,66 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + +#ifndef READ_SRC_NAMESPACE_READER_H_ +#define READ_SRC_NAMESPACE_READER_H_ + namespace reader { - enum job_type { - read_job, - search_job - }; +enum job_type { + read_job, + search_job +}; - enum search_type { - t_normal_search, - t_regex_search - }; +enum search_type { + t_normal_search, + t_regex_search +}; - class file { - - private: - bool initialized = false; - std::string file_name; - std::string init_error_message = "unknown"; - int64_t file_length = 0; - - bool just_outputting_positions = false; - int64_t start_position = 0; - int64_t amount_to_read = -1; - - int64_t end_position = -1; - - int block_size = 10240; - - std::string search_query = ""; - search_type query_type = t_normal_search; - - job_type job = read_job; - - bool do_read_job(); - bool do_search_job(); - - bool do_normal_search(); - bool do_regex_search(); +class file { + private: + bool initialized = false; + std::string file_name; + std::string init_error_message = "unknown"; + int64_t file_length = 0; - public: - bool init(std::string path); - - std::string read(int64_t start_position, int64_t length); - - std::string get_init_error_message(); - int64_t get_file_length(); - - bool do_job(); - - void set_start_position(int64_t position); - void set_amount_to_read(int64_t amount); - void set_just_outputting_positions(bool flag); - void set_block_size(int size); - void set_search_query(std::string query); - void set_search_type(search_type normal_or_regex); - void set_job_type(job_type input_job); - }; -} + bool just_outputting_positions = false; + int64_t start_position = 0; + int64_t amount_to_read = -1; + + int64_t end_position = -1; + + int block_size = 10240; + + std::string search_query = ""; + search_type query_type = t_normal_search; + + job_type job = read_job; + + bool do_read_job(); + bool do_search_job(); + + bool do_normal_search(); + bool do_regex_search(); + + public: + bool init(std::string path); + + std::string read(int64_t start_position, int64_t length); + + std::string get_init_error_message(); + int64_t get_file_length(); + + bool do_job(); + + void set_start_position(int64_t position); + void set_amount_to_read(int64_t amount); + void set_just_outputting_positions(bool flag); + void set_block_size(int size); + void set_search_query(std::string query); + void set_search_type(search_type normal_or_regex); + void set_job_type(job_type input_job); +}; +} // namespace reader + +#endif // READ_SRC_NAMESPACE_READER_H_ diff --git a/shared/definitions.h b/shared/definitions.h index 7a0784c..9d6e7f5 100644 --- a/shared/definitions.h +++ b/shared/definitions.h @@ -1,3 +1,10 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + +#ifndef SHARED_DEFINITIONS_H_ +#define SHARED_DEFINITIONS_H_ + // Basic info: #include "version.h" #define program_author "rail5" @@ -20,3 +27,5 @@ // This might(?) mean that we can't open >2GB files on 32-bit systems which use clang/llvm // Testing is needed #endif + +#endif // SHARED_DEFINITIONS_H_ diff --git a/shared/explode.cpp b/shared/explode.cpp index 051b86e..1049788 100644 --- a/shared/explode.cpp +++ b/shared/explode.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef SSTREAM #define SSTREAM #include @@ -40,7 +44,6 @@ std::vector explode(std::string const &input, char delimiter, int m // If maximum_number_of_elements is set, we want to recombine any splits after the maximum if (maximum_number_of_elements > 0) { - // Set the highest index (counting from zero) we want the vector to have int last_permissible_element = maximum_number_of_elements - 1; diff --git a/shared/file_exists.cpp b/shared/file_exists.cpp index 2c63648..919ba82 100644 --- a/shared/file_exists.cpp +++ b/shared/file_exists.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef UNISTD_H #define UNISTD_H #include diff --git a/shared/file_is_writable.cpp b/shared/file_is_writable.cpp index 800418f..d8c96bd 100644 --- a/shared/file_is_writable.cpp +++ b/shared/file_is_writable.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef FILESYSTEM #define FILESYSTEM #include diff --git a/shared/is_directory.cpp b/shared/is_directory.cpp index 61b1f4e..b70b3db 100644 --- a/shared/is_directory.cpp +++ b/shared/is_directory.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef SYS_STAT #define SYS_STAT #include @@ -11,4 +15,4 @@ inline bool is_directory(std::string path) { // Error return false; } -} \ No newline at end of file +} diff --git a/shared/is_number.cpp b/shared/is_number.cpp index fc610e3..dcc178f 100644 --- a/shared/is_number.cpp +++ b/shared/is_number.cpp @@ -1,10 +1,13 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef ALGORITHM #define ALGORITHM #include #endif -inline bool is_number(const std::string &s) -{ +inline bool is_number(const std::string &s) { return !s.empty() && std::find_if(s.begin(), s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end(); } diff --git a/shared/isolate_path_from_filename.cpp b/shared/isolate_path_from_filename.cpp index e7bd83f..f6e6870 100644 --- a/shared/isolate_path_from_filename.cpp +++ b/shared/isolate_path_from_filename.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef FILESYSTEM #define FILESYSTEM #include diff --git a/shared/parse_block_units.cpp b/shared/parse_block_units.cpp index 688cd53..ab9ed45 100644 --- a/shared/parse_block_units.cpp +++ b/shared/parse_block_units.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef FN_IS_NUMBER #define FN_IS_NUMBER #include "is_number.cpp" @@ -21,12 +25,12 @@ inline int parse_block_units(const std::string &user_input) { } if (last_character == "K" || last_character == "k") { - int blocksize = (int)stoi(all_but_last_character); + int blocksize = stoi(all_but_last_character); return (blocksize * 1024); } if (last_character == "M" || last_character == "m") { - int blocksize = (int)stoi(all_but_last_character); + int blocksize = stoi(all_but_last_character); return (blocksize * 1024 * 1024); } @@ -38,5 +42,5 @@ inline int parse_block_units(const std::string &user_input) { if (!is_number(user_input)) { return -1; } - return (int)stol(user_input); + return static_cast(stol(user_input)); } diff --git a/shared/parse_regex.cpp b/shared/parse_regex.cpp index 3bcc70d..86666d1 100644 --- a/shared/parse_regex.cpp +++ b/shared/parse_regex.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef REGEX #define REGEX #include @@ -32,7 +36,7 @@ caret = false; \ backslash_b = false; \ backslash_capital_b = false; \ - or_operator = false; + or_operator = false; std::vector parse_regex(std::string expression) { /*** @@ -318,7 +322,7 @@ std::vector parse_regex(std::string expression) { // Push each of the characters we had been saving for the buffer // Back into the output vector one by one - for (int i=0; i create_sub_expressions(std::string expression) { std::vector output; - for (int i=0; i create_sub_expressions(std::string expression) { } output.push_back(sub_expression); - } return output; -} \ No newline at end of file +} diff --git a/shared/process_bytecodes.cpp b/shared/process_bytecodes.cpp index b2d4df8..b312afd 100644 --- a/shared/process_bytecodes.cpp +++ b/shared/process_bytecodes.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef REGEX #define REGEX #include @@ -33,4 +37,4 @@ std::string process_bytecodes(std::string input) { } return input; -} \ No newline at end of file +} diff --git a/shared/process_escapedchars.cpp b/shared/process_escapedchars.cpp index 0fe8d24..f01b01d 100644 --- a/shared/process_escapedchars.cpp +++ b/shared/process_escapedchars.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef VECTOR #define VECTOR #include @@ -22,4 +26,4 @@ std::string process_escapedchars(std::string input) { } return input; -} \ No newline at end of file +} diff --git a/shared/remove_leading_whitespace.cpp b/shared/remove_leading_whitespace.cpp index c1d2994..74e969b 100644 --- a/shared/remove_leading_whitespace.cpp +++ b/shared/remove_leading_whitespace.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + std::string remove_leading_whitespace(const std::string &input) { const std::string whitespace_chars = " \n\r\t\f\v"; diff --git a/shared/string_ends_with.cpp b/shared/string_ends_with.cpp index d978a72..57931e9 100644 --- a/shared/string_ends_with.cpp +++ b/shared/string_ends_with.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + inline bool string_ends_with(std::string const &haystack, std::string const &needle) { /* Return true if 'haystack' ends with 'needle' */ if (haystack.length() >= needle.length()) { diff --git a/shared/string_starts_with.cpp b/shared/string_starts_with.cpp index 8fb0931..a8c6d9d 100644 --- a/shared/string_starts_with.cpp +++ b/shared/string_starts_with.cpp @@ -1,3 +1,7 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + inline bool string_starts_with(std::string const &haystack, std::string const &needle) { /* Return true if 'haystack' starts with 'needle' */ return (!haystack.find(needle)); diff --git a/shared/to_lower.cpp b/shared/to_lower.cpp index 0706844..a7af2ee 100644 --- a/shared/to_lower.cpp +++ b/shared/to_lower.cpp @@ -1,9 +1,13 @@ +/*** + * Copyright (C) 2024 rail5 +*/ + #ifndef ALGORITHM #define ALGORITHM #include #endif -inline std::string to_lower(std::string &input) { +inline std::string to_lower(const std::string& input) { std::string output = input; std::transform(output.begin(), output.end(), output.begin(), [](unsigned char c){ return std::tolower(c); });