Skip to content

Commit 10f6670

Browse files
authored
Merge pull request #45 from BianchTech/43-feat/centralized-exception-cpp
feat(exceptions): Including a new file that standardizes the output
2 parents 747515d + 20a758c commit 10f6670

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_library(
77
src/page_rank.cpp
88
src/inverted_index.cpp
99
src/preprocessing/stemmer.cpp
10+
src/exceptions/invalid_pointer_exception.cpp
1011
)
1112

1213
target_include_directories(search_engine PUBLIC include)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef INVALID_POINTER_H
2+
#define INVALID_POINTER_H
3+
4+
#include <exception>
5+
#include <string>
6+
7+
namespace exceptions {
8+
class invalid_pointer_exception : public std::exception {
9+
public:
10+
invalid_pointer_exception();
11+
12+
const char* what() const noexcept override;
13+
};
14+
} // namespace exceptions
15+
16+
#endif

lib/include/preprocessing/stemmer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <unordered_map>
1212
#include <vector>
1313

14+
#include "exceptions/invalid_pointer_exception.h"
15+
1416
namespace stemmer {
1517

1618
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "exceptions/invalid_pointer_exception.h"
2+
3+
namespace exceptions {
4+
5+
// Definição do construtor com mensagem padrão
6+
invalid_pointer_exception::invalid_pointer_exception() {}
7+
8+
// Definição do método what(), retornando a mensagem padrão
9+
const char* invalid_pointer_exception::what() const noexcept {
10+
return "Invalid pointer exception occurred.";
11+
}
12+
13+
} // namespace exceptions

lib/src/preprocessing/stemmer.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,18 @@ std::string RSPL::removeAccents(const std::string& input) {
199199
}
200200

201201
void RSPL::shrinkString(std::string* input) {
202-
if (!input)
203-
return; // Verifica se o ponteiro é válido
204-
205-
icu::UnicodeString ustr(input->c_str(), "UTF-8");
206-
ustr.toLower();
207-
std::string result;
208-
ustr.toUTF8String(result);
209-
*input = result;
202+
try {
203+
if (!input)
204+
throw exceptions::invalid_pointer_exception();
205+
206+
icu::UnicodeString ustr(input->c_str(), "UTF-8");
207+
ustr.toLower();
208+
std::string result;
209+
ustr.toUTF8String(result);
210+
*input = result;
211+
} catch (const std::exception& e) {
212+
std::cerr << e.what() << '\n';
213+
}
210214
}
211215

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

0 commit comments

Comments
 (0)