From 4153dbcd6b1c361c44e632e7a42eb3e67fbbaf4d Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 7 Nov 2025 09:13:46 -0500 Subject: [PATCH] remove redundant logic from text normalization function --- .../choreographer/utils/normalize_text.dart | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/pangea/choreographer/utils/normalize_text.dart b/lib/pangea/choreographer/utils/normalize_text.dart index 96eee9422..d510a71ca 100644 --- a/lib/pangea/choreographer/utils/normalize_text.dart +++ b/lib/pangea/choreographer/utils/normalize_text.dart @@ -7,10 +7,8 @@ import 'package:fluffychat/pangea/common/utils/error_handler.dart'; // We would like esta = está, hello! = Hello, etc. String normalizeString(String input, String languageCode) { try { - String normalized = input; - // Step 1: Convert to lowercase (works for all Unicode scripts) - normalized = normalized.toLowerCase(); + String normalized = input.toLowerCase(); // Step 2: Apply language-specific normalization rules normalized = _applyLanguageSpecificNormalization(normalized, languageCode); @@ -23,19 +21,13 @@ String normalizeString(String input, String languageCode) { // Step 4: Remove punctuation (including Unicode punctuation) // This removes ASCII and Unicode punctuation while preserving letters, numbers, and spaces - normalized = - normalized.replaceAll(RegExp(r'[\p{P}\p{S}]', unicode: true), ''); + normalized = normalized.replaceAll( + RegExp(r'[\p{P}\p{S}]', unicode: true), + '', + ); // Step 5: Normalize whitespace (collapse multiple spaces, trim) - normalized = normalized.replaceAll(RegExp(r'\s+'), ' ').trim(); - - // Step 6: Handle edge case where result becomes empty - if (normalized.isEmpty) { - // If normalization results in empty string, return empty string - return ''; - } - - return normalized; + return normalized.replaceAll(RegExp(r'\s+'), ' ').trim(); } catch (e, s) { ErrorHandler.logError( e: e,