aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseivarya <[email protected]>2026-06-20 18:46:10 +0530
committerseivarya <[email protected]>2026-06-20 18:46:10 +0530
commitb5186a5a724649e9eb71fdfbaf3c2a84b36d7c9c (patch)
treeac664730e758ef50f8472831fada93c6e8f7c5d7
parent8798eafd4cc4b32c590a40c276c09b830c5d62da (diff)
[fix]: fixed incorrect rendering of words due to missing delimeters
-rw-r--r--include/reader.h2
-rw-r--r--src/main.cpp2
-rw-r--r--src/reader.cpp14
3 files changed, 8 insertions, 10 deletions
diff --git a/include/reader.h b/include/reader.h
index 8b61e6c..27b7a90 100644
--- a/include/reader.h
+++ b/include/reader.h
@@ -67,6 +67,6 @@ int get_cursor_pos(int *rows, int *cols);
int get_window_size(int *rows, int *cols);
int is_number(char *strnum);
-size_t split(const std::string &txt, std::vector<std::string> &strings, char ch);
+size_t split(const std::string &txt, std::vector<std::string> &strings, const std::string &delims);
diff --git a/src/main.cpp b/src/main.cpp
index a0c60cb..10c3df6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
fclose(fp);
std::vector<std::string> data;
- split(content, data, ' ');
+ split(content, data, " \t\r\n,;:!?");
while(1) {
for (std::string &k: data) {
diff --git a/src/reader.cpp b/src/reader.cpp
index dd293db..508205d 100644
--- a/src/reader.cpp
+++ b/src/reader.cpp
@@ -115,17 +115,15 @@ void editor_refresh_scrn(editor_cfg *cfg) {
append_buffer::instance().remove();
}
-size_t split(const std::string &txt, std::vector<std::string> &strings, char ch) {
- size_t pos = txt.find(ch);
- size_t initial_pos = 0;
+size_t split(const std::string &txt, std::vector<std::string> &strings, const std::string &delims) {
+ size_t initial_pos = txt.find_first_not_of(delims, 0);
+ size_t pos = txt.find_first_of(delims, initial_pos);
- while (pos != std::string::npos) {
+ while (initial_pos != std::string::npos) {
strings.push_back(txt.substr(initial_pos, pos - initial_pos));
- initial_pos = pos + 1;
- pos = txt.find(ch, initial_pos);
+ initial_pos = txt.find_first_not_of(delims, pos);
+ pos = txt.find_first_of(delims, initial_pos);
}
-
- strings.push_back(txt.substr(initial_pos));
return strings.size();
}