Skip to content

Commit 93cf7f7

Browse files
rewrite soap to focus on brain rot detection
1 parent f091a3d commit 93cf7f7

File tree

2 files changed

+391
-384
lines changed

2 files changed

+391
-384
lines changed

code/logic/fossil/io/soap.h

Lines changed: 76 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,49 @@
1515
#define FOSSIL_IO_SOAP_H
1616

1717
#include <stdint.h>
18+
#include <stddef.h>
1819

1920
#ifdef __cplusplus
2021
extern "C" {
2122
#endif
2223

2324
/**
24-
* Setup soap to have a preloaded list of words for use in the sanitize step.
25-
*/
26-
void fossil_io_soap_create(void);
27-
28-
/**
29-
* Sanitize a string by replacing curse words with asterisks.
30-
* This function scans the input string for offensive words and replaces them with asterisks,
31-
* thereby making the string suitable for use in contexts where offensive language is not allowed.
32-
* The input string is modified in place.
25+
* @brief Sanitize input text by removing or replacing "rot-brain" and meme-based language.
3326
*
34-
* @param input The input string to be sanitized in-place.
35-
* @return The sanitized string.
27+
* @param text The input text to sanitize.
28+
* @return A dynamically allocated sanitized string (must be freed by the caller).
3629
*/
37-
char *fossil_io_soap_sanitize(const char *input);
30+
char *fossil_io_soap_sanitize(const char *text);
3831

3932
/**
40-
* Check if a word is an offensive word or phrase.
41-
* Returns EXIT_FAILURE if the word is considered offensive, EXIT_SUCCESS otherwise.
42-
*/
43-
int32_t fossil_io_soap_is_offensive(const char *word);
44-
45-
/**
46-
* Check if a word is meme speak.
47-
* Returns EXIT_FAILURE if the word is considered meme speak, EXIT_SUCCESS otherwise.
33+
* @brief Suggest proper alternatives for rot-brain words or grammar fixes.
34+
*
35+
* @param text The input text.
36+
* @param format_type Custom format for output (e.g., "*" or "#").
37+
* @return A dynamically allocated string with suggestions (must be freed by the caller).
4838
*/
49-
int32_t fossil_io_soap_is_rotbrain(const char *word);
39+
char *fossil_io_soap_suggest(const char *text, char format_type);
5040

5141
/**
52-
* Count offensive words in a string.
53-
* Returns the number of offensive words found in the input string.
42+
* @brief Add a custom word or phrase to the filter.
43+
*
44+
* @param phrase The phrase to add.
45+
* @return 0 on success, nonzero on failure.
5446
*/
55-
int32_t fossil_io_soap_count_offensive(const char *input);
47+
int fossil_io_soap_add_custom_filter(const char *phrase);
5648

5749
/**
58-
* Count meme speak words in a string.
59-
* Returns the number of meme speak words found in the input string.
50+
* @brief Clear all custom filters.
6051
*/
61-
int32_t fossil_io_soap_count_rotbrain(const char *input);
52+
void fossil_io_soap_clear_custom_filters(void);
6253

6354
/**
64-
* Count positive words in a string.
65-
* Returns the number of positive words found in the input string.
55+
* @brief Detect the tone of a sentence.
56+
*
57+
* @param text The input text.
58+
* @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.).
6659
*/
67-
int32_t fossil_io_soap_count_positive(const char *input);
60+
const char *fossil_io_soap_detect_tone(const char *text);
6861

6962
#ifdef __cplusplus
7063
}
@@ -86,119 +79,94 @@ namespace fossil {
8679
class Soap {
8780
public:
8881
/**
89-
* Setup soap to have a preloaded list of words for use in the sanitize step.
90-
*/
91-
Soap() {
92-
fossil_io_soap_create();
93-
}
94-
95-
/**
96-
* Destructor.
97-
*/
98-
~Soap() = default;
99-
100-
/**
101-
* Sanitize a string by replacing curse words with asterisks.
102-
* This function scans the input string for offensive words and replaces them with asterisks,
103-
* thereby making the string suitable for use in contexts where offensive language is not allowed.
104-
* The input string is modified in place.
82+
* Sanitize input text by removing or replacing "rot-brain" and meme-based language.
10583
*
106-
* @param input The input string to be sanitized in-place.
84+
* @param text The input text to sanitize.
85+
* @param censor_char Character to use for censoring (default: '*').
86+
* @return A dynamically allocated sanitized string (must be freed by the caller).
10787
*/
108-
static void sanitize(std::string &input) {
109-
fossil_io_soap_sanitize(&input[0]);
88+
static std::string sanitize(const std::string &text, char censor_char = '*') {
89+
return fossil_io_soap_sanitize(text.c_str());
11090
}
11191

11292
/**
113-
* Sanitize a C string by replacing curse words with asterisks.
114-
* This function scans the input string for offensive words and replaces them with asterisks,
115-
* thereby making the string suitable for use in contexts where offensive language is not allowed.
116-
* The input string is modified in place.
93+
* Suggest proper alternatives for rot-brain words or grammar fixes.
11794
*
118-
* @param input The input C string to be sanitized in-place.
119-
*/
120-
static void sanitize(char *input) {
121-
fossil_io_soap_sanitize(input);
122-
}
123-
124-
/**
125-
* Check if a word is an offensive word or phrase.
126-
* Returns EXIT_FAILURE if the word is considered offensive, EXIT_SUCCESS otherwise.
95+
* @param text The input text.
96+
* @param format_type Custom format for output (e.g., "*" or "#").
97+
* @return A dynamically allocated string with suggestions (must be freed by the caller).
12798
*/
128-
static int32_t is_offensive(const std::string &word) {
129-
return fossil_io_soap_is_offensive(word.c_str());
99+
static std::string suggest(const std::string &text, char format_type = '*') {
100+
return fossil_io_soap_suggest(text.c_str(), format_type);
130101
}
131102

132103
/**
133-
* Check if a C string word is an offensive word or phrase.
134-
* Returns EXIT_FAILURE if the word is considered offensive, EXIT_SUCCESS otherwise.
135-
*/
136-
static int32_t is_offensive(const char *word) {
137-
return fossil_io_soap_is_offensive(word);
138-
}
139-
140-
/**
141-
* Check if a word is meme speak.
142-
* Returns EXIT_FAILURE if the word is considered meme speak, EXIT_SUCCESS otherwise.
143-
*/
144-
static int32_t is_rotbrain(const std::string &word) {
145-
return fossil_io_soap_is_rotbrain(word.c_str());
146-
}
147-
148-
/**
149-
* Check if a C string word is meme speak.
150-
* Returns EXIT_FAILURE if the word is considered meme speak, EXIT_SUCCESS otherwise.
104+
* Add a custom word or phrase to the filter.
105+
*
106+
* @param phrase The phrase to add.
107+
* @return 0 on success, nonzero on failure.
151108
*/
152-
static int32_t is_rotbrain(const char *word) {
153-
return fossil_io_soap_is_rotbrain(word);
109+
static int add_custom_filter(const std::string &phrase) {
110+
return fossil_io_soap_add_custom_filter(phrase.c_str());
154111
}
155112

156113
/**
157-
* Count offensive words in a string.
158-
* Returns the number of offensive words found in the input string.
114+
* Clear all custom filters.
159115
*/
160-
static int32_t count_offensive(const std::string &input) {
161-
return fossil_io_soap_count_offensive(input.c_str());
116+
static void clear_custom_filters() {
117+
fossil_io_soap_clear_custom_filters();
162118
}
163119

164120
/**
165-
* Count offensive words in a C string.
166-
* Returns the number of offensive words found in the input string.
121+
* Detect the tone of a sentence.
122+
*
123+
* @param text The input text.
124+
* @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.).
167125
*/
168-
static int32_t count_offensive(const char *input) {
169-
return fossil_io_soap_count_offensive(input);
126+
static std::string detect_tone(const std::string &text) {
127+
return fossil_io_soap_detect_tone(text.c_str());
170128
}
171129

172130
/**
173-
* Count meme speak words in a string.
174-
* Returns the number of meme speak words found in the input string.
131+
* Sanitize input text by removing or replacing "rot-brain" and meme-based language.
132+
*
133+
* @param text The input text to sanitize.
134+
* @param censor_char Character to use for censoring (default: '*').
135+
* @return A dynamically allocated sanitized string (must be freed by the caller).
175136
*/
176-
static int32_t count_rotbrain(const std::string &input) {
177-
return fossil_io_soap_count_rotbrain(input.c_str());
137+
static char* sanitize(const char* text, char censor_char = '*') {
138+
return fossil_io_soap_sanitize(text);
178139
}
179140

180141
/**
181-
* Count meme speak words in a C string.
182-
* Returns the number of meme speak words found in the input string.
142+
* Suggest proper alternatives for rot-brain words or grammar fixes.
143+
*
144+
* @param text The input text.
145+
* @param format_type Custom format for output (e.g., "*" or "#").
146+
* @return A dynamically allocated string with suggestions (must be freed by the caller).
183147
*/
184-
static int32_t count_rotbrain(const char *input) {
185-
return fossil_io_soap_count_rotbrain(input);
148+
static char* suggest(const char* text, char format_type = '*') {
149+
return fossil_io_soap_suggest(text, format_type);
186150
}
187151

188152
/**
189-
* Count positive words in a string.
190-
* Returns the number of positive words found in the input string.
153+
* Add a custom word or phrase to the filter.
154+
*
155+
* @param phrase The phrase to add.
156+
* @return 0 on success, nonzero on failure.
191157
*/
192-
static int32_t count_positive(const std::string &input) {
193-
return fossil_io_soap_count_positive(input.c_str());
158+
static int add_custom_filter(const char* phrase) {
159+
return fossil_io_soap_add_custom_filter(phrase);
194160
}
195161

196162
/**
197-
* Count positive words in a C string.
198-
* Returns the number of positive words found in the input string.
163+
* Detect the tone of a sentence.
164+
*
165+
* @param text The input text.
166+
* @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.).
199167
*/
200-
static int32_t count_positive(const char *input) {
201-
return fossil_io_soap_count_positive(input);
168+
static const char* detect_tone(const char* text) {
169+
return fossil_io_soap_detect_tone(text);
202170
}
203171

204172
};

0 commit comments

Comments
 (0)