#[ allow(unused_imports) ]
use strs_tools :: *;
fn main()
{
println!( "=== Text Indentation Examples ===" );
basic_indentation();
code_generation_example();
nested_structure_formatting();
custom_line_processing();
}
fn basic_indentation()
{
println!( "\n--- Basic Text Indentation ---" );
#[ cfg( all( feature = "string_indentation", not( feature = "no_std" ) ) ) ]
{
let original_text = "First line\nSecond line\nThird line";
println!( "Original text: " );
println!( "{original_text}" );
let indented = string ::indentation ::indentation( " ", original_text, "" );
println!( "\nWith 2-space indentation: " );
println!( "{indented}" );
let lines: Vec< &str > = indented.lines().collect();
for line in &lines
{
assert!( line.starts_with( " " ), "Line should start with 2 spaces: '{line}'" );
}
println!( "✓ All lines properly indented" );
}
}
fn code_generation_example()
{
println!( "\n--- Code Generation Example ---" );
#[ cfg( all( feature = "string_indentation", not( feature = "no_std" ) ) ) ]
{
let mut generated_code = String ::new();
generated_code.push_str( "fn example_function()" );
generated_code.push( '\n' );
generated_code.push( '{' );
generated_code.push( '\n' );
let function_body = "let x = 42;\nlet y = x * 2;\nif y > 50 {\n println!(\"Large value:{}\", y);\n}";
let indented_body = string ::indentation ::indentation( " ", function_body, "" );
generated_code.push_str( &indented_body );
generated_code.push( '\n' );
generated_code.push( '}' );
println!( "Generated Rust code: " );
println!( "{generated_code}" );
let lines: Vec< &str > = generated_code.lines().collect();
assert!( lines[ 0 ].starts_with( "fn " ) );
assert!( lines[ 2 ].starts_with( " let x" ) ); assert!( lines[ 4 ].starts_with( " if " ) );
println!( "✓ Code properly structured with indentation" );
}
}
fn nested_structure_formatting()
{
println!( "\n--- Nested Structure Formatting ---" );
#[ cfg( all( feature = "string_indentation", not( feature = "no_std" ) ) ) ]
{
let mut document = String ::new();
document.push_str( "Configuration: \n" );
let level1_content = "database: \nlogging: \nserver: ";
let level1_indented = string ::indentation ::indentation( " ", level1_content, "" );
document.push_str( &level1_indented );
document.push( '\n' );
let db_config = "host: localhost\nport: 5432\nname: myapp_db";
let db_indented = string ::indentation ::indentation( " ", db_config, "" );
let lines: Vec< &str > = document.lines().collect();
let mut final_doc = String ::new();
for line in lines.iter()
{
final_doc.push_str( line );
final_doc.push( '\n' );
if line.trim() == "database: "
{
final_doc.push_str( &db_indented );
final_doc.push( '\n' );
}
}
println!( "Nested configuration document: " );
println!( "{final_doc}" );
let final_lines: Vec< &str > = final_doc.lines().collect();
let host_line = final_lines.iter().find( | line | line.contains( "host: " ) ).unwrap();
assert!( host_line.starts_with( " " ), "Database config should have 4-space indent" );
println!( "✓ Nested structure properly formatted" );
}
}
fn custom_line_processing()
{
println!( "\n--- Custom Line Processing ---" );
#[ cfg( all( feature = "string_indentation", not( feature = "no_std" ) ) ) ]
{
let documentation = "This is a function that processes data.\nIt takes input and returns output.\nUsed in data processing pipelines.";
println!( "Original documentation: " );
println!( "{documentation}" );
let rust_docs = string ::indentation ::indentation( "/// ", documentation, "" );
println!( "\nAs Rust documentation: " );
println!( "{rust_docs}" );
let c_comments = string ::indentation ::indentation( " * ", documentation, "" );
let c_block = format!( "/*\n{c_comments}\n */" );
println!( "\nAs C-style block comment: " );
println!( "{c_block}" );
let boxed_content = string ::indentation ::indentation( "│ ", documentation, " │" );
let boxed_comment = format!( "┌─{}─┐\n{}\n└─{}─┘",
"─".repeat( 50 ),
boxed_content,
"─".repeat( 50 ) );
println!( "\nAs boxed comment: " );
println!( "{boxed_comment}" );
let doc_lines: Vec< &str > = rust_docs.lines().collect();
for line in doc_lines
{
assert!( line.starts_with( "/// " ), "Rust doc line should start with '/// '" );
}
println!( "✓ Custom line processing formats applied successfully" );
}
}