diff --git a/lib/src/safe_text_filter.dart b/lib/src/safe_text_filter.dart index 62680aa..216e382 100644 --- a/lib/src/safe_text_filter.dart +++ b/lib/src/safe_text_filter.dart @@ -11,6 +11,16 @@ class SafeTextFilter { static AhoCorasick? _trie; static bool _isInitialized = false; + /// Whether [SafeTextFilter] has been initialized via [init]. + static bool get isInitialized => _isInitialized; + + /// Resets the internal state of [SafeTextFilter], clearing the loaded Trie + /// word lists. Useful when dynamically switching languages or freeing memory. + static void reset() { + _trie = null; + _isInitialized = false; + } + /// Matches any Unicode letter or digit (covers all scripts: Latin, Arabic, /// Devanagari, CJK, Hangul, Cyrillic, Hebrew, Thai, etc.) static final RegExp _unicodeLetterOrDigit = diff --git a/test/profanity_filter_test.dart b/test/profanity_filter_test.dart index 7913d3b..08630e7 100644 --- a/test/profanity_filter_test.dart +++ b/test/profanity_filter_test.dart @@ -347,5 +347,16 @@ void main() { expect(acTime, isNotNull); }); + + test('will correctly reflect initialization status via isInitialized and reset state via reset()', () async { + SafeTextFilter.reset(); + expect(SafeTextFilter.isInitialized, false); + + await SafeTextFilter.init(language: Language.english); + expect(SafeTextFilter.isInitialized, true); + + SafeTextFilter.reset(); + expect(SafeTextFilter.isInitialized, false); + }); }); }