Skip to content

Rose::StringUtility::joinEnglish

Join strings as if they were English prose.

Synopsis

Declared in <src/Rose/StringUtility/SplitJoin.h>

[[visibility]]
std::string
joinEnglish(
    std::vector<std::string> const& phrases,
    std::string const& separator = ",",
    std::string const& finalIntro = "and");

Description

This is useful when generating documentation strings.

If the input is empty, the output is the empty string. I.e., () => ""

If the input is one phrase, the output is that phrase. E.g., ("foo") => "foo"

If the input is two phrases, the output will be those two phrases separated by "and" (the finalIntro). E.g., ("foo", "bar") => "foo and bar"

If the input is three or more phrases, they will be separated from one another by commas (the separator) and the last item will also be introduced with "and" (the finalIntro). E.g., ("foo", "bar", "baz") => "foo, bar, and baz"

No transformations are performed on the input phrases. Space characters are inserted after each separator and finalIntro. A space is also inserted before the finalIntro when the input is two phrases.

Return Value

Joined string.

Parameters

Name

Description

phrases

Input phrases.

separator

Separator between items.

finalIntro

Intro before the final item.

Created with MrDocs