@@ -166,115 +166,240 @@ float fossil_io_soap_politeness_score(const char *text);
166166}
167167
168168#include < string>
169+ #include < memory>
169170
170171/* *
171172 * C++ wrapper for the SOAP API.
172173 */
173174namespace fossil {
174-
175- /* *
176- * Namespace for I/O operations.
177- */
178175 namespace io {
176+
179177 /* *
180- * SOAP API for sanitizing strings.
178+ * @brief SOAP API for sanitizing and analyzing user text input.
179+ *
180+ * Provides C++ wrappers for detecting, transforming, or correcting slang, tone, sentiment,
181+ * clickbait, and other language features with a focus on clarity and safety.
181182 */
182183 class Soap {
183184 public:
185+
184186 /* *
185- * Sanitize input text by removing or replacing " rot-brain" and meme-based language .
186- *
187- * @param text The input text to sanitize .
188- * @return A dynamically allocated sanitized string (must be freed by the caller) .
187+ * @brief Sanitize input by replacing meme/ rot-brain terms with standard alternatives .
188+ *
189+ * @param text The input string .
190+ * @return A cleaned-up version of the text .
189191 */
190192 static std::string sanitize (const std::string &text) {
191- return fossil_io_soap_sanitize (text.c_str ());
193+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_sanitize (text.c_str ()), free);
194+ return ptr ? std::string (ptr.get ()) : std::string{};
192195 }
193196
194197 /* *
195- * Suggest proper alternatives for rot-brain words or grammar fixes .
198+ * @brief Sanitize input text (C-style) .
196199 *
197- * @param text The input text.
198- * @param format_type Custom format for output (e.g., "*" or "#").
199- * @return A dynamically allocated string with suggestions (must be freed by the caller).
200+ * @param text The input string.
201+ * @return A heap-allocated cleaned-up version (must be freed manually).
202+ */
203+ static char * sanitize (const char * text) {
204+ return fossil_io_soap_sanitize (text);
205+ }
206+
207+ /* *
208+ * @brief Suggest alternative expressions for slang or incorrect grammar.
209+ *
210+ * @param text The input string.
211+ * @return A string with suggested improvements.
200212 */
201213 static std::string suggest (const std::string &text) {
202- return fossil_io_soap_suggest (text.c_str ());
214+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_suggest (text.c_str ()), free);
215+ return ptr ? std::string (ptr.get ()) : std::string{};
203216 }
204217
205218 /* *
206- * Add a custom word or phrase to the filter.
207- *
208- * @param phrase The phrase to add.
219+ * @brief Suggest improvements (C-style).
220+ *
221+ * @param text The input string.
222+ * @return A heap-allocated suggestion (must be freed manually).
223+ */
224+ static char * suggest (const char * text) {
225+ return fossil_io_soap_suggest (text);
226+ }
227+
228+ /* *
229+ * @brief Add a custom slang or flagged phrase to the filter.
230+ *
231+ * @param phrase The custom phrase.
209232 * @return 0 on success, nonzero on failure.
210233 */
211234 static int add_custom_filter (const std::string &phrase) {
212235 return fossil_io_soap_add_custom_filter (phrase.c_str ());
213236 }
214237
215238 /* *
216- * Clear all custom filters.
239+ * @brief Add a custom slang or flagged phrase to the filter (C-style).
240+ *
241+ * @param phrase The custom phrase.
242+ * @return 0 on success, nonzero on failure.
243+ */
244+ static int add_custom_filter (const char * phrase) {
245+ return fossil_io_soap_add_custom_filter (phrase);
246+ }
247+
248+ /* *
249+ * @brief Clear all user-added custom filters.
217250 */
218251 static void clear_custom_filters () {
219252 fossil_io_soap_clear_custom_filters ();
220253 }
221254
222255 /* *
223- * Detect the tone of a sentence .
224- *
225- * @param text The input text .
226- * @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.) .
256+ * @brief Detect tone of the input (e.g., "sarcastic", "formal") .
257+ *
258+ * @param text The input string .
259+ * @return A tone descriptor string .
227260 */
228261 static std::string detect_tone (const std::string &text) {
229- return fossil_io_soap_detect_tone (text.c_str ());
262+ return std::string ( fossil_io_soap_detect_tone (text.c_str () ));
230263 }
231264
232265 /* *
233- * Sanitize input text by removing or replacing "rot-brain" and meme-based language .
234- *
235- * @param text The input text to sanitize .
236- * @return A dynamically allocated sanitized string (must be freed by the caller) .
266+ * @brief Detect tone of the input (C-style) .
267+ *
268+ * @param text The input string .
269+ * @return A tone descriptor string.
237270 */
238- static char * sanitize (const char * text) {
239- return fossil_io_soap_sanitize (text);
271+ static const char * detect_tone (const char * text) {
272+ return fossil_io_soap_detect_tone (text);
240273 }
241274
242275 /* *
243- * Suggest proper alternatives for rot-brain words or grammar fixes.
244- *
245- * @param text The input text.
246- * @param format_type Custom format for output (e.g., "*" or "#").
247- * @return A dynamically allocated string with suggestions (must be freed by the caller).
276+ * @brief Analyze sentiment in the input ("positive", "neutral", "negative").
277+ *
278+ * @param text The input string.
279+ * @return Sentiment label.
248280 */
249- static char * suggest (const char * text) {
250- return fossil_io_soap_suggest ( text);
281+ static std::string detect_sentiment (const std::string & text) {
282+ return std::string ( fossil_io_soap_detect_sentiment ( text. c_str ()) );
251283 }
252284
253285 /* *
254- * Add a custom word or phrase to the filter .
255- *
256- * @param phrase The phrase to add .
257- * @return 0 on success, nonzero on failure .
286+ * @brief Analyze sentiment (C-style) .
287+ *
288+ * @param text The input string .
289+ * @return Sentiment label string .
258290 */
259- static int add_custom_filter (const char * phrase ) {
260- return fossil_io_soap_add_custom_filter (phrase );
291+ static const char * detect_sentiment (const char * text ) {
292+ return fossil_io_soap_detect_sentiment (text );
261293 }
262294
263295 /* *
264- * Detect the tone of a sentence .
265- *
266- * @param text The input text .
267- * @return A string representing the detected tone ("formal", "casual", "sarcastic", etc.) .
296+ * @brief Check for harmful or inappropriate content .
297+ *
298+ * @param text The input string .
299+ * @return true if flagged, false otherwise .
268300 */
269- static const char * detect_tone (const char * text) {
270- return fossil_io_soap_detect_tone (text) ;
301+ static bool is_harmful (const std::string & text) {
302+ return fossil_io_soap_detect_harmful_content (text. c_str ()) != 0 ;
271303 }
272304
273- };
305+ /* *
306+ * @brief Check if the input contains exaggerated or hyperbolic language.
307+ *
308+ * @param text The input string.
309+ * @return true if exaggerated, false otherwise.
310+ */
311+ static bool is_exaggerated (const std::string &text) {
312+ return fossil_io_soap_detect_exaggeration (text.c_str ()) != 0 ;
313+ }
274314
275- }
315+ /* *
316+ * @brief Check if the input uses clickbait language.
317+ *
318+ * @param text The input string.
319+ * @return true if clickbait detected, false otherwise.
320+ */
321+ static bool is_clickbait (const std::string &text) {
322+ return fossil_io_soap_detect_clickbait (text.c_str ()) != 0 ;
323+ }
276324
277- }
325+ /* *
326+ * @brief Normalize slang and internet abbreviations.
327+ *
328+ * @param text The input string.
329+ * @return A cleaned version of the input text.
330+ */
331+ static std::string normalize_slang (const std::string &text) {
332+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_normalize_slang (text.c_str ()), free);
333+ return ptr ? std::string (ptr.get ()) : std::string{};
334+ }
335+
336+ /* *
337+ * @brief Fix common grammar errors in input text.
338+ *
339+ * @param text The input string.
340+ * @return A corrected version of the input.
341+ */
342+ static std::string correct_grammar (const std::string &text) {
343+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_correct_grammar (text.c_str ()), free);
344+ return ptr ? std::string (ptr.get ()) : std::string{};
345+ }
346+
347+ /* *
348+ * @brief Replace offensive language with neutral alternatives.
349+ *
350+ * @param text The input string.
351+ * @return A sanitized version with offensive terms filtered out.
352+ */
353+ static std::string filter_offensive (const std::string &text) {
354+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_filter_offensive (text.c_str ()), free);
355+ return ptr ? std::string (ptr.get ()) : std::string{};
356+ }
357+
358+ /* *
359+ * @brief Attempt to identify logical fallacies in the input.
360+ *
361+ * @param text The input string.
362+ * @return Description of detected fallacy or empty string.
363+ */
364+ static std::string detect_fallacy (const std::string &text) {
365+ const char * result = fossil_io_soap_detect_fallacy (text.c_str ());
366+ return result ? std::string (result) : std::string{};
367+ }
368+
369+ /* *
370+ * @brief Generate a brief summary of the key idea in the input.
371+ *
372+ * @param text The input string.
373+ * @return Summary string.
374+ */
375+ static std::string summarize (const std::string &text) {
376+ std::unique_ptr<char , decltype (&free)> ptr (fossil_io_soap_summarize (text.c_str ()), free);
377+ return ptr ? std::string (ptr.get ()) : std::string{};
378+ }
379+
380+ /* *
381+ * @brief Return a readability score (e.g., Flesch-Kincaid).
382+ *
383+ * @param text The input string.
384+ * @return Readability score as a float.
385+ */
386+ static float readability_score (const std::string &text) {
387+ return fossil_io_soap_evaluate_readability (text.c_str ());
388+ }
389+
390+ /* *
391+ * @brief Compute a politeness score (0.0 = rude, 1.0 = very polite).
392+ *
393+ * @param text The input string.
394+ * @return Politeness score.
395+ */
396+ static float politeness_score (const std::string &text) {
397+ return fossil_io_soap_politeness_score (text.c_str ());
398+ }
399+ };
400+
401+ } // namespace io
402+ } // namespace fossil
278403
279404#endif
280405
0 commit comments