Skip to content

Commit 7963909

Browse files
committed
Document indent
1 parent df37f91 commit 7963909

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lrpar/src/lib/ctbuilder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,16 @@ where
15341534
}
15351535
}
15361536

1537+
/// Indents a multi-line string and trims any trailing newline.
1538+
/// This currently assumes that indentation on blank lines does not matter.
1539+
///
1540+
/// The algorithm used by this function is:
1541+
/// 1. Prefix `s` with the indentation, indenting the first line.
1542+
/// 2. Trim any trailing newlines.
1543+
/// 3. Replace all newlines with `\n{indent}`` to indent all lines after the first.
1544+
///
1545+
/// It is plausible that we should a step 4, but currently do not:
1546+
/// 4. Replace all `\n{indent}\n` with `\n\n`
15371547
fn indent(s: &str, indent: &str) -> String {
15381548
format!("{indent}{}\n", s.trim_end_matches('\n')).replace('\n', &format!("\n{}", indent))
15391549
}

nimbleparse/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ fn read_file<P: AsRef<Path>>(path: P) -> String {
5353
s
5454
}
5555

56+
/// Indents a multi-line string and trims any trailing newline.
57+
/// This currently assumes that indentation on blank lines does not matter.
58+
///
59+
/// The algorithm used by this function is:
60+
/// 1. Prefix `s` with the indentation, indenting the first line.
61+
/// 2. Trim any trailing newlines.
62+
/// 3. Replace all newlines with `\n{indent}`` to indent all lines after the first.
63+
///
64+
/// It is plausible that we should a step 4, but currently do not:
65+
/// 4. Replace all `\n{indent}\n` with `\n\n`
5666
fn indent(s: &str, indent: &str) -> String {
5767
format!("{indent}{}\n", s.trim_end_matches('\n')).replace('\n', &format!("\n{}", indent))
5868
}

0 commit comments

Comments
 (0)