Improve WidthDb documentation
This commit is contained in:
parent
2dee39c03c
commit
e3365fdc02
1 changed files with 12 additions and 4 deletions
|
|
@ -40,8 +40,8 @@ impl WidthDb {
|
||||||
///
|
///
|
||||||
/// If the grapheme is a tab, the column is used to determine its width.
|
/// If the grapheme is a tab, the column is used to determine its width.
|
||||||
///
|
///
|
||||||
/// If the width has not been measured yet, it is estimated using the
|
/// If the width has not been measured yet or measurements are turned off,
|
||||||
/// Unicode Standard Annex #11.
|
/// it is estimated using the Unicode Standard Annex #11.
|
||||||
pub fn grapheme_width(&mut self, grapheme: &str, col: usize) -> u8 {
|
pub fn grapheme_width(&mut self, grapheme: &str, col: usize) -> u8 {
|
||||||
assert_eq!(Some(grapheme), grapheme.graphemes(true).next());
|
assert_eq!(Some(grapheme), grapheme.graphemes(true).next());
|
||||||
if grapheme == "\t" {
|
if grapheme == "\t" {
|
||||||
|
|
@ -62,8 +62,8 @@ impl WidthDb {
|
||||||
///
|
///
|
||||||
/// If a grapheme is a tab, its column is used to determine its width.
|
/// If a grapheme is a tab, its column is used to determine its width.
|
||||||
///
|
///
|
||||||
/// If the width of a grapheme has not been measured yet, it is estimated
|
/// If the width of a grapheme has not been measured yet or measurements are
|
||||||
/// using the Unicode Standard Annex #11.
|
/// turned off, it is estimated using the Unicode Standard Annex #11.
|
||||||
pub fn width(&mut self, s: &str) -> usize {
|
pub fn width(&mut self, s: &str) -> usize {
|
||||||
let mut total: usize = 0;
|
let mut total: usize = 0;
|
||||||
for grapheme in s.graphemes(true) {
|
for grapheme in s.graphemes(true) {
|
||||||
|
|
@ -72,6 +72,14 @@ impl WidthDb {
|
||||||
total
|
total
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Perform primitive word wrapping with the specified maximum width.
|
||||||
|
///
|
||||||
|
/// Returns the byte offsets at which the string should be split into lines.
|
||||||
|
/// An offset of 1 would mean the first line contains only a single byte.
|
||||||
|
/// These offsets lie on grapheme boundaries.
|
||||||
|
///
|
||||||
|
/// This function does not support bidirectional script. It assumes the
|
||||||
|
/// entire text has the same direction.
|
||||||
pub fn wrap(&mut self, text: &str, width: usize) -> Vec<usize> {
|
pub fn wrap(&mut self, text: &str, width: usize) -> Vec<usize> {
|
||||||
wrap::wrap(self, text, width)
|
wrap::wrap(self, text, width)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue