Parma Polyhedra Library requirements
Byte-oriented text wrapping

Byte-oriented text wrapping

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-001577
PPL-SPEC-001577
Text-wrapping separators, widths and indentation

wrap_string shall format the source byte prefix preceding its first NUL, leaving the source unchanged. That prefix length shall be less than std::numeric_limits<unsigned>::max() so its byte indices and the separator sentinel remain distinct. Preferred widths shall count source bytes, excluding inserted indentation, and shall guide separator selection rather than impose a maximum word length. The first output line shall use the first preferred width; subsequent lines shall use the continuation width.

For each remaining prefix, a NUL or newline at or before the preferred boundary shall terminate the line. Otherwise, the last comma strictly before the boundary shall take priority and remain on the preceding line; absent such a comma, the last start of a whitespace run at or before the boundary shall be the split. Without either separator, the word shall extend to NUL, whitespace, or a comma, retaining that comma. Whitespace classification shall use the unsigned byte in the current C character locale; newline shall retain its explicit line-separator role.

The selected prefix shall be copied unchanged. At a split, one whitespace separator and any immediately following ordinary spaces shall be discarded. A nonempty continuation prefix shall receive exactly indent_depth ordinary spaces. Output lines shall be joined by newlines only while more source bytes remain; a final consumed newline shall add no trailing newline. Zero widths, empty lines and unbroken words shall be admitted. Exceptions from constructing the result shall propagate without modifying the input.

Byte-oriented diagnostic wrapping needs stable separator rules, including the distinction between preferred widths and forced word breaks.

APPROVED
LIBRARY_WIDE
IF_CPP
Test, Analysis, Inspection

Check literal expected strings for each separator priority and boundary, independent first/continuation widths, zero/maximum widths, embedded NUL, explicit newlines, space runs, preserved prefix whitespace, unbroken words and high bytes under a saved/restored C locale. Exercise the helper independently of any numerical domain.

src/wrap_string.hh; src/wrap_string.cc; tests/wrapstringspec1.cc.

CPP
Public

Defining header: wrap_string.hh. Namespace: Parma_Polyhedra_Library::IO_Operators.

std::string wrap_string(const std::string&, unsigned indent_depth,
                       unsigned preferred_first_line_length,
                       unsigned preferred_line_length);