Mountain/ApplicationState/Internal/TextProcessing/AnalyzeTextLinesAndEOL.rs
1//! # AnalyzeTextLinesAndEOL Module (Internal)
2//!
3//! ## RESPONSIBILITIES
4//! Analyzes text content to determine its line endings and splits it into a
5//! vector of lines for document state management.
6//!
7//! ## ARCHITECTURAL ROLE
8//! AnalyzeTextLinesAndEOL is part of the **Internal::TextProcessing** module,
9//! providing text analysis utilities.
10//!
11//! ## KEY COMPONENTS
12//! - AnalyzeTextLinesAndEOL: Function to analyze text lines and EOL
13//!
14//! ## ERROR HANDLING
15//! - Detects both CRLF and LF line endings
16//! - Returns safe defaults for empty text
17//!
18//! ## LOGGING
19//! Operations are logged at appropriate levels (debug).
20//!
21//! ## PERFORMANCE CONSIDERATIONS
22//! - Efficient line splitting
23//! - EOL detection
24//!
25//! ## TODO
26//! - [ ] Add encoding detection
27//! - [ ] Implement line ending normalization
28//! - [ ] Add performance metrics
29
30/// Analyzes text content to determine its line endings and splits it into a
31/// vector of lines.
32///
33/// # Arguments
34/// * `TextContent` - The text content to analyze
35///
36/// # Returns
37/// Tuple containing (`Vec<String>` of lines, String of detected EOL)
38///
39/// # Behavior
40/// - Detects CRLF ("\r\n") or LF ("\n") line endings
41/// - Splits text into lines vector using detected EOL
42/// - Returns LF as default if text doesn't contain CRLF
43pub fn AnalyzeTextLinesAndEOL(TextContent:&str) -> (Vec<String>, String) {
44 let detected_eol = if TextContent.contains("\r\n") {
45 dev_log!("model", "[AnalyzeTextLinesAndEOL] Detected CRLF line endings");
46 "\r\n"
47 } else {
48 dev_log!("model", "[AnalyzeTextLinesAndEOL] Detected LF line endings");
49 "\n"
50 };
51
52 let lines:Vec<String> = TextContent.split(detected_eol).map(String::from).collect();
53
54 dev_log!(
55 "model",
56 "[AnalyzeTextLinesAndEOL] Analyzed {} lines with EOL: {:?}",
57 lines.len(),
58 detected_eol
59 );
60
61 (lines, detected_eol.to_string())
62}
63use crate::dev_log;