File tree 5 files changed +44
-8
lines changed
5 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ add_library(
7
7
src/page_rank.cpp
8
8
src/inverted_index.cpp
9
9
src/preprocessing/stemmer.cpp
10
+ src/exceptions/invalid_pointer_exception.cpp
10
11
)
11
12
12
13
target_include_directories (search_engine PUBLIC include )
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 11
11
#include < unordered_map>
12
12
#include < vector>
13
13
14
+ #include " exceptions/invalid_pointer_exception.h"
15
+
14
16
namespace stemmer {
15
17
16
18
/* *
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -199,14 +199,18 @@ std::string RSPL::removeAccents(const std::string& input) {
199
199
}
200
200
201
201
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
+ }
210
214
}
211
215
212
216
bool RSPL::applyRules (std::string& word, const std::vector<StepRule>& rules) {
You can’t perform that action at this time.
0 commit comments