diff --git a/src/meta_plugin/text.rs b/src/meta_plugin/text.rs index 5d3b060..e7f9828 100644 --- a/src/meta_plugin/text.rs +++ b/src/meta_plugin/text.rs @@ -100,6 +100,66 @@ impl TextMetaPlugin { } } } + + /// Helper method to perform binary detection and return appropriate metadata + /// Returns (metadata, should_finalize) tuple + fn perform_binary_detection(&mut self, buffer: &[u8]) -> (Vec, bool) { + let mut metadata = Vec::new(); + let is_binary_result = is_binary(buffer); + self.is_binary_content = Some(is_binary_result); + + // Output text and binary status + let text_value = if is_binary_result { "false".to_string() } else { "true".to_string() }; + let binary_value = if is_binary_result { "true".to_string() } else { "false".to_string() }; + + // Use process_metadata_outputs to handle output mapping + if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( + "text", + text_value, + self.base.outputs() + ) { + metadata.push(meta_data); + } + + if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( + "binary", + binary_value, + self.base.outputs() + ) { + metadata.push(meta_data); + } + + (metadata, is_binary_result) + } + + /// Helper method to output word and line counts + fn output_word_line_counts(&mut self) -> Vec { + let mut metadata = Vec::new(); + + // Process any remaining data in utf8_buffer + if !self.utf8_buffer.is_empty() { + self.count_text_stats(&[]); + } + + // Output word and line counts + if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( + "text_word_count", + self.word_count.to_string(), + self.base.outputs() + ) { + metadata.push(meta_data); + } + + if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( + "text_line_count", + self.line_count.to_string(), + self.base.outputs() + ) { + metadata.push(meta_data); + } + + metadata + } } impl MetaPlugin for TextMetaPlugin { @@ -227,66 +287,6 @@ impl MetaPlugin for TextMetaPlugin { } } - /// Helper method to perform binary detection and return appropriate metadata - /// Returns (metadata, should_finalize) tuple - fn perform_binary_detection(&mut self, buffer: &[u8]) -> (Vec, bool) { - let mut metadata = Vec::new(); - let is_binary_result = is_binary(buffer); - self.is_binary_content = Some(is_binary_result); - - // Output text and binary status - let text_value = if is_binary_result { "false".to_string() } else { "true".to_string() }; - let binary_value = if is_binary_result { "true".to_string() } else { "false".to_string() }; - - // Use process_metadata_outputs to handle output mapping - if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( - "text", - text_value, - self.base.outputs() - ) { - metadata.push(meta_data); - } - - if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( - "binary", - binary_value, - self.base.outputs() - ) { - metadata.push(meta_data); - } - - (metadata, is_binary_result) - } - - /// Helper method to output word and line counts - fn output_word_line_counts(&mut self) -> Vec { - let mut metadata = Vec::new(); - - // Process any remaining data in utf8_buffer - if !self.utf8_buffer.is_empty() { - self.count_text_stats(&[]); - } - - // Output word and line counts - if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( - "text_word_count", - self.word_count.to_string(), - self.base.outputs() - ) { - metadata.push(meta_data); - } - - if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( - "text_line_count", - self.line_count.to_string(), - self.base.outputs() - ) { - metadata.push(meta_data); - } - - metadata - } - fn meta_name(&self) -> String { self.base.meta_name.clone() }