Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exceptions): Including a new file that standardizes the output #45

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(
src/page_rank.cpp
src/inverted_index.cpp
src/preprocessing/stemmer.cpp
src/exceptions/invalid_pointer_exception.cpp
)

target_include_directories(search_engine PUBLIC include)
Expand Down
16 changes: 16 additions & 0 deletions lib/include/exceptions/invalid_pointer_exception.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef INVALID_POINTER_H
#define INVALID_POINTER_H

#include <exception>
#include <string>

namespace exceptions {
class invalid_pointer_exception : public std::exception {
public:
invalid_pointer_exception();

const char* what() const noexcept override;
};
} // namespace exceptions

#endif
2 changes: 2 additions & 0 deletions lib/include/preprocessing/stemmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <unordered_map>
#include <vector>

#include "exceptions/invalid_pointer_exception.h"

namespace stemmer {

/**
Expand Down
13 changes: 13 additions & 0 deletions lib/src/exceptions/invalid_pointer_exception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "exceptions/invalid_pointer_exception.h"

namespace exceptions {

// Definição do construtor com mensagem padrão
invalid_pointer_exception::invalid_pointer_exception() {}

// Definição do método what(), retornando a mensagem padrão
const char* invalid_pointer_exception::what() const noexcept {
return "Invalid pointer exception occurred.";
}

} // namespace exceptions
20 changes: 12 additions & 8 deletions lib/src/preprocessing/stemmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,18 @@ std::string RSPL::removeAccents(const std::string& input) {
}

void RSPL::shrinkString(std::string* input) {
if (!input)
return; // Verifica se o ponteiro é válido

icu::UnicodeString ustr(input->c_str(), "UTF-8");
ustr.toLower();
std::string result;
ustr.toUTF8String(result);
*input = result;
try {
if (!input)
throw exceptions::invalid_pointer_exception();

icu::UnicodeString ustr(input->c_str(), "UTF-8");
ustr.toLower();
std::string result;
ustr.toUTF8String(result);
*input = result;
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
}
}

bool RSPL::applyRules(std::string& word, const std::vector<StepRule>& rules) {
Expand Down
Loading