From 75b8adbbb428c55b3a0684e1ea7c9ac3329a7baa Mon Sep 17 00:00:00 2001 From: Ronit Rameja Date: Thu, 6 Aug 2026 17:34:42 +0530 Subject: [PATCH 1/3] added option for resetting the trie --- lib/src/safe_text_filter.dart | 10 ++++++++++ test/profanity_filter_test.dart | 11 +++++++++++ 2 files changed, 21 insertions(+) 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); + }); }); } From 7ba521d17ea0c984589c224b3572f17f021fa357 Mon Sep 17 00:00:00 2001 From: Ronit Rameja Date: Thu, 6 Aug 2026 17:36:35 +0530 Subject: [PATCH 2/3] updated version to 2.1.7 --- CHANGELOG.md | 14 ++++++++++++++ README.md | 15 +++++++++++++++ pubspec.yaml | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d2e4b..ff75780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 2.1.7 + +### Added +- **Package Lifecycle API**: + - `SafeTextFilter.isInitialized` getter — check whether word lists have been loaded and the Trie is built. + - `SafeTextFilter.reset()` method — clear loaded Trie word lists and reset initialization state, useful when dynamically switching languages or releasing memory. + +## 2.1.6 + +### Documentation +- Rewrote the pub.dev package description and keywords with terms developers actually search for, to improve discoverability. +- Removed the stale "What's New in 2.0.0" section from the README — already covered by Features/How it Works and the CHANGELOG. +- Added a pub.dev like / GitHub star callout to the README. + ## 2.1.5 ### Data diff --git a/README.md b/README.md index 9384674..ce3fece 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,21 @@ await SafeTextFilter.init(language: Language.all); > **Note:** If neither parameter is provided, the filter defaults to `Language.english`. +### `SafeTextFilter.isInitialized` & `SafeTextFilter.reset` + +Check initialization status or reset loaded word lists dynamically (e.g., when switching languages): + +```dart +// Check if initialized +if (!SafeTextFilter.isInitialized) { + await SafeTextFilter.init(language: Language.english); +} + +// Reset state to reload with a different language +SafeTextFilter.reset(); +await SafeTextFilter.init(language: Language.spanish); +``` + --- ### `SafeTextFilter.filterText` diff --git a/pubspec.yaml b/pubspec.yaml index 37a5e60..b0cd5f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: safe_text description: A fast Flutter profanity & swear word filter with phone number detection, powered by Aho-Corasick. Supports 80+ languages and 55,000+ curated bad words. -version: 2.1.5 +version: 2.1.7 homepage: https://github.com/master-wayne7/safe_text repository: https://github.com/master-wayne7/safe_text issue_tracker: https://github.com/master-wayne7/safe_text/issues From 6d689f00b0b4f2d1aec46d27625167bd86e44337 Mon Sep 17 00:00:00 2001 From: Ronit Rameja Date: Thu, 6 Aug 2026 17:38:05 +0530 Subject: [PATCH 3/3] updated version in readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f31685b..ba75c17 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ A high-performance Flutter package for filtering offensive language (profanity) - [Quick Start](#quick-start) - [API Reference](#api-reference) - [`SafeTextFilter.init`](#safetextfilterinit) + - [`SafeTextFilter.isInitialized` \& `SafeTextFilter.reset`](#safetextfilterisinitialized--safetextfilterreset) - [`SafeTextFilter.filterText`](#safetextfilterfiltertext) - [Masking Strategies](#masking-strategies) - [`SafeTextFilter.containsBadWord`](#safetextfiltercontainsbadword) @@ -67,7 +68,7 @@ Or manually add it to your `pubspec.yaml`: ```yaml dependencies: - safe_text: ^2.1.6 + safe_text: ^2.1.7 ``` Then run: