Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/src/safe_text_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
11 changes: 11 additions & 0 deletions test/profanity_filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
Loading