Skip to content

In compound formats, add special delimiters for the last pair #10946

@Bolpat

Description

@Bolpat

The compound format has two forms: %(…%) and %(…%|…%), the latter allowing to specify the delimiter precisely. However, rather commonly, the delimiter must be different for the last pair of elements. Let’s allow for 2 or 3 delimiters to handle the last pair, i.e. %(…%|d₀%|d₁%) and %(…%|d₀%|d₁%|d₂%) such that d is used between all elements but the last pair. For the last pair, use d if it’s the only pair, otherwise use d. If d isn’t given, it’s as if it were identical to d.

Example:

foreach (friends; [["John", "Nancy"], ["Amy", "Joe", "Taylor"]])
{
    writefln("My friends are %-(%s%|, %).", friends);
    // My friends are John, Nancy.
    // My friends are Amy, Joe, Taylor.

    writefln("My friends are %-(%s%| and %).", friends);
    // My friends are John and Nancy.
    // My friends are Amy and Joe and Taylor.

    // Proposed: Two %|
    writefln("My friends are %-(%s%|, %| and %).", friends);
    // My friends are John and Nancy.
    // My friends are Amy, Joe and Taylor.

    // Proposed: Three %|
    writefln("My friends are %-(%s%|, %|, and %| and %).", friends);
    // My friends are John and Nancy.
    // My friends are Amy, Joe, and Taylor.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions