• Home
  • Raw
  • Download

Lines Matching full:wrap

9 /// Wrap a line of text at a given width.
21 /// use textwrap::wrap;
23 /// let lines = wrap("Memory safety without garbage collection.", 15);
35 /// use textwrap::{wrap, Options};
40 /// let lines = wrap("Memory safety without garbage collection.", &options);
51 /// By default, `wrap` will try to ensure an even right margin by
58 /// As an example, using the first-fit algorithm to wrap the famous
63 /// # use textwrap::{WrapAlgorithm::FirstFit, Options, wrap};
65 /// # let lines = wrap("To be, or not to be: that is the question",
87 /// # use textwrap::{Options, WrapAlgorithm, wrap};
89 /// # let lines = wrap(
114 /// use textwrap::{wrap, Options};
117 /// let lines = wrap("Wrapping text all day long.", &options);
153 /// use textwrap::wrap;
155 /// assert_eq!(wrap("Foo bar baz", 10), vec!["Foo bar", "baz"]);
156 /// assert_eq!(wrap("Foo bar baz", 8), vec!["Foo", "bar baz"]);
175 /// use textwrap::wrap;
177 /// assert_eq!(wrap(" foo bar", 8), vec![" foo", "bar"]);
178 /// assert_eq!(wrap(" foo bar", 4), vec!["", "foo", "bar"]);
180 pub fn wrap<'a, Opt>(text: &str, width_or_options: Opt) -> Vec<Cow<'_, str>> in wrap() function
212 /// Wrap a single line of text.
245 let wrapped_words = options.wrap_algorithm.wrap(&broken_words, &line_widths); in wrap_single_line_slow_path()
304 assert_eq!(wrap("foo", 10), vec!["foo"]); in no_wrap()
309 assert_eq!(wrap("foo bar baz", 5), vec!["foo", "bar", "baz"]); in wrap_simple()
315 wrap( in to_be_or_not()
325 assert_eq!(wrap("foo bar baz", 10), vec!["foo bar", "baz"]); in multiple_words_on_first_line()
330 assert_eq!(wrap("foo", 0), vec!["f", "o", "o"]); in long_word()
335 assert_eq!(wrap("foo bar", 0), vec!["f", "o", "o", "b", "a", "r"]); in long_words()
340 assert_eq!(wrap("foo bar", usize::MAX), vec!["foo bar"]); in max_width()
344 assert_eq!(wrap(text, usize::MAX), vec![text]); in max_width()
349 assert_eq!(wrap(" foo bar", 6), vec![" foo", "bar"]); in leading_whitespace()
358 assert_eq!(wrap(" foobar baz", 6), vec!["", "foobar", "baz"]); in leading_whitespace_empty_first_line()
366 assert_eq!(wrap("foo bar baz ", 5), vec!["foo", "bar", "baz"]); in trailing_whitespace()
374 wrap("aaabbbccc x yyyzzzwww", 9), in issue_99()
384 assert_eq!(wrap("x – x", options), vec!["x", "–", "x"]); in issue_129()
389 assert_eq!(wrap("Hello, World!", 15), vec!["Hello, World!"]); in wide_character_handling()
391 wrap( in wide_character_handling()
402 wrap( in wide_character_handling()
417 assert_eq!(wrap("", &options), vec!["!!!"]); in indent_empty_line()
423 assert_eq!(wrap("foo", &options), vec![">>>foo"]); in indent_single_line()
430 wrap("x x x x x x x x x x x x x", &options), in indent_first_emoji()
439 wrap("foo bar baz", &options), in indent_multiple_lines()
447 assert_eq!(wrap("foo\nbar\nbaz", &options), vec![" foo", "bar", "baz"]); in only_initial_indent_multiple_lines()
454 wrap("foo\nbar\nbaz", &options), in only_subsequent_indent_multiple_lines()
462 assert_eq!(wrap("foobarbaz", &options), vec!["* foo", " bar", " baz"]); in indent_break_words()
472 assert_eq!(wrap("foobarbaz", &options), vec!["-->", "fooba", "rbaz"]); in initial_indent_break_words()
477 assert_eq!(wrap("foo-bar", 5), vec!["foo-", "bar"]); in hyphens()
483 assert_eq!(wrap("foobar-", &options), vec!["foobar-"]); in trailing_hyphen()
488 assert_eq!(wrap("foo-bar-baz", 5), vec!["foo-", "bar-", "baz"]); in multiple_hyphens()
495 wrap("The --foo-bar flag.", &options), in hyphens_flag()
503 assert_eq!(wrap("foo--bar", &options), vec!["foo--bar"]); in repeated_hyphens()
508 assert_eq!(wrap("Na2-CH4", 5), vec!["Na2-", "CH4"]); in hyphens_alphanumeric()
514 assert_eq!(wrap("foo(-)bar", &options), vec!["foo(-)bar"]); in hyphens_non_alphanumeric()
519 assert_eq!(wrap("foo-bar-baz", 9), vec!["foo-bar-", "baz"]); in multiple_splits()
525 assert_eq!(wrap("foobar-baz", &options), vec!["foobar-", "baz"]); in forced_split()
532 wrap("small large tiny", &options), in multiple_unbroken_words_issue_193()
536 wrap("small large tiny", &options), in multiple_unbroken_words_issue_193()
544 assert_eq!(wrap("fooo x y", &options), vec!["fooo", "x", "y"]); in very_narrow_lines_issue_193()
545 assert_eq!(wrap("fooo x y", &options), vec!["fooo", "x", "y"]); in very_narrow_lines_issue_193()
551 assert_eq!(wrap("foo bar-baz", &options), vec!["foo bar-", "baz"]); in simple_hyphens()
557 assert_eq!(wrap("foo bar-baz", &options), vec!["foo", "bar-baz"]); in no_hyphenation()
566 wrap("Internationalization", &options), in auto_hyphenation_double_hyphenation()
572 wrap("Internationalization", &options), in auto_hyphenation_double_hyphenation()
583 wrap("participation is the key to success", &options), in auto_hyphenation_issue_158()
589 wrap("participation is the key to success", &options), in auto_hyphenation_issue_158()
602 wrap("garbage collection", &options), in split_len_hyphenation()
615 let lines = wrap("Internationalization", &options); in borrowed_lines()
634 wrap("over-caffinated", &options), in auto_hyphenation_with_hyphen()
640 wrap("over-caffinated", &options), in auto_hyphenation_with_hyphen()
647 assert_eq!(wrap("foobarbaz", 3), vec!["foo", "bar", "baz"]); in break_words()
655 assert_eq!(wrap("Hello", options), vec!["He", "ll", "o"]); in break_words_wide_characters()
660 assert_eq!(wrap("foobar", 0), vec!["f", "o", "o", "b", "a", "r"]); in break_words_zero_width()
665 assert_eq!(wrap("testx y", 4), vec!["test", "x y"]); in break_long_first_word()
670 assert_eq!(wrap(" ", 80), vec![""]); in wrap_preserves_line_breaks_trims_whitespace()
671 assert_eq!(wrap(" \n ", 80), vec!["", ""]); in wrap_preserves_line_breaks_trims_whitespace()
672 assert_eq!(wrap(" \n \n \n ", 80), vec!["", "", "", ""]); in wrap_preserves_line_breaks_trims_whitespace()
682 wrap(&format!("{} {}", green_hello, blue_world), 6), in wrap_colored_text()