2222#include <stdlib.h>
2323
2424// List of offensive words and phrases (super hard to mainting thisw list as GitHub Copilot doesnt wanna help with this part of the SOAP API)
25- static const char * offensive_words [] = {
25+ static const char * FOSSIL_SOAP_OFFENSIVE [] = {
2626 "curse1" ,
2727 "curse2" ,
2828 "racist_phrase1" ,
@@ -55,7 +55,18 @@ static const char *offensive_words[] = {
5555 // Support for other languages can be added via PR to this repository
5656};
5757
58- static inline char * _custom_fossil_strdup (const char * str ) {
58+ // garbage words and phrases
59+ // (slightly easier to maintain since it's just slang from social media spoken from people who need to touch grass)
60+ static const char * FOSSIL_SOAP_ROTBRAIN [] = {
61+ "rizz" , "skibidi" , "yeet" , "sus" , "vibe" , "lit" , "no cap" , "bet" , "fam" , "bruh" ,
62+ "flex" , "ghost" , "goat" , "gucci" , "hype" , "janky" , "lowkey" , "mood" , "salty" , "shade" ,
63+ "slay" , "snatched" , "stan" , "tea" , "thirsty" , "woke" , "yolo" , "zaddy" , "drip" , "fire" ,
64+ "lol" , "omg" , "brb" , "sus"
65+
66+ // Support for other terms can be added via PR to this repository
67+ };
68+
69+ static inline char * custom_strdup (const char * str ) {
5970 if (!str ) return NULL ; // Handle NULL pointer gracefully
6071
6172 size_t len = 0 ;
@@ -90,7 +101,7 @@ static char *custom_strcasestr(const char *haystack, const char *needle) {
90101// Function to replace a substring in a string (case-insensitive)
91102static void replace_substring_case_insensitive (char * str , const char * old_substr , const char * new_substr ) {
92103 char * position = custom_strcasestr (str , old_substr );
93- if (position != NULL ) {
104+ while (position != NULL ) {
94105 size_t old_len = strlen (old_substr );
95106 size_t new_len = strlen (new_substr );
96107 size_t tail_len = strlen (position + old_len );
@@ -100,28 +111,33 @@ static void replace_substring_case_insensitive(char *str, const char *old_substr
100111 memmove (position + new_len , position + old_len , tail_len + 1 );
101112 } else {
102113 memmove (position + new_len , position + old_len , tail_len + 1 );
103- memcpy (position , new_substr , new_len );
104114 }
115+ memcpy (position , new_substr , new_len );
116+
117+ // Find the next occurrence
118+ position = custom_strcasestr (position + new_len , old_substr );
105119 }
106120}
107121
108122void fossil_soap_sanitize (char * input ) {
109123 if (input == NULL || * input == '\0' ) return ;
110124
111125 // Perform single-threaded sanitization
112- for (size_t i = 0 ; i < sizeof (offensive_words ) / sizeof (offensive_words [0 ]); ++ i ) {
113- while (custom_strcasestr (input , offensive_words [i ]) != NULL ) {
114- replace_substring_case_insensitive (input , offensive_words [i ], "***" );
115- }
126+ for (size_t i = 0 ; i < sizeof (FOSSIL_SOAP_OFFENSIVE ) / sizeof (FOSSIL_SOAP_OFFENSIVE [0 ]); ++ i ) {
127+ replace_substring_case_insensitive (input , FOSSIL_SOAP_OFFENSIVE [i ], "***" );
128+ }
129+
130+ for (size_t i = 0 ; i < sizeof (FOSSIL_SOAP_ROTBRAIN ) / sizeof (FOSSIL_SOAP_ROTBRAIN [0 ]); ++ i ) {
131+ replace_substring_case_insensitive (input , FOSSIL_SOAP_ROTBRAIN [i ], "***" );
116132 }
117133}
118134
119135// Function to check if a word is an offensive word or phrase
120136int32_t fossil_soap_is_offensive (const char * word ) {
121137 if (word == NULL || * word == '\0' ) return EXIT_SUCCESS ;
122138
123- for (size_t i = 0 ; i < sizeof (offensive_words ) / sizeof (offensive_words [0 ]); ++ i ) {
124- if (strcasecmp (word , offensive_words [i ]) == 0 ) {
139+ for (size_t i = 0 ; i < sizeof (FOSSIL_SOAP_OFFENSIVE ) / sizeof (FOSSIL_SOAP_OFFENSIVE [0 ]); ++ i ) {
140+ if (strcasecmp (word , FOSSIL_SOAP_OFFENSIVE [i ]) == 0 ) {
125141 return EXIT_FAILURE ;
126142 }
127143 }
@@ -133,15 +149,44 @@ int32_t fossil_soap_count_offensive(const char *input) {
133149 if (input == NULL || * input == '\0' ) return 0 ;
134150
135151 int count = 0 ;
136- char * copy = _custom_fossil_strdup (input );
152+ char * copy = custom_strdup (input );
137153 if (copy == NULL ) return EXIT_SUCCESS ;
138154
139- char * token = strtok (copy , " " ); // Tokenize the string by space
155+ char * token = strtok (copy , " ,.!?;: " ); // Tokenize the string by space and punctuation
140156 while (token != NULL ) {
141157 if (fossil_soap_is_offensive (token )) {
142158 count ++ ;
143159 }
144- token = strtok (NULL , " " );
160+ token = strtok (NULL , " ,.!?;:" );
161+ }
162+ free (copy ); // Free the memory allocated for the copy
163+ return count ;
164+ }
165+
166+ int32_t fossil_soap_is_rotbrain (const char * word ) {
167+ if (word == NULL || * word == '\0' ) return EXIT_SUCCESS ;
168+
169+ for (size_t i = 0 ; i < sizeof (FOSSIL_SOAP_ROTBRAIN ) / sizeof (FOSSIL_SOAP_ROTBRAIN [0 ]); ++ i ) {
170+ if (strcasecmp (word , FOSSIL_SOAP_ROTBRAIN [i ]) == 0 ) {
171+ return EXIT_FAILURE ;
172+ }
173+ }
174+ return EXIT_SUCCESS ;
175+ }
176+
177+ int32_t fossil_soap_count_rotbrain (const char * input ) {
178+ if (input == NULL || * input == '\0' ) return 0 ;
179+
180+ int count = 0 ;
181+ char * copy = custom_strdup (input );
182+ if (copy == NULL ) return EXIT_SUCCESS ;
183+
184+ char * token = strtok (copy , " ,.!?;:" ); // Tokenize the string by space and punctuation
185+ while (token != NULL ) {
186+ if (fossil_soap_is_rotbrain (token )) {
187+ count ++ ;
188+ }
189+ token = strtok (NULL , " ,.!?;:" );
145190 }
146191 free (copy ); // Free the memory allocated for the copy
147192 return count ;
0 commit comments