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
30use log::debug;
31
32/// Analyzes text content to determine its line endings and splits it into a
33/// vector of lines.
34///
35/// # Arguments
36/// * `TextContent` - The text content to analyze
37///
38/// # Returns
39/// Tuple containing (`Vec<String>` of lines, String of detected EOL)
40///
41/// # Behavior
42/// - Detects CRLF ("\r\n") or LF ("\n") line endings
43/// - Splits text into lines vector using detected EOL
44/// - Returns LF as default if text doesn't contain CRLF
45pub fn AnalyzeTextLinesAndEOL(TextContent:&str) -> (Vec<String>, String) {
46	let detected_eol = if TextContent.contains("\r\n") {
47		debug!("[AnalyzeTextLinesAndEOL] Detected CRLF line endings");
48		"\r\n"
49	} else {
50		debug!("[AnalyzeTextLinesAndEOL] Detected LF line endings");
51		"\n"
52	};
53
54	let lines:Vec<String> = TextContent.split(detected_eol).map(String::from).collect();
55
56	debug!(
57		"[AnalyzeTextLinesAndEOL] Analyzed {} lines with EOL: {:?}",
58		lines.len(),
59		detected_eol
60	);
61
62	(lines, detected_eol.to_string())
63}