text
stringlengths
0
2.2M
state->column() = 0;
// Step 2: Update the ID of 'state'.
if (StateId::e_IN_TAG == state->id()) {
state->id() = StateId::e_FIRST_DATA_BETWEEN_TAGS;
}
return stream;
}
bsl::ostream& Formatter_CompactImplUtil::addComment(
bsl::ostream& stream,
State *state,
const bsl::string_view& comment,
bool)
{
const bsl::string_view openMarker = "<!-- ";
const bsl::string_view closeMarker = " -->";
addCommentImpl(stream, state, comment, openMarker, closeMarker);
return stream;
}
bsl::ostream& Formatter_CompactImplUtil::addHeader(
bsl::ostream& stream,
State *state,
const bsl::string_view& encoding)
{
BSLS_ASSERT(StateId::e_AT_START == state->id());
// Step 1: Print a sequence of conditional tokens to 'stream' and update
// the column number and indentation level of 'state'.
const bsl::string_view startHeader = "<?xml version=\"1.0\" encoding=\"";
const bsl::string_view endHeader = "\" ?>";
stream << startHeader << encoding << endHeader;
state->column() += static_cast<int>(
startHeader.length() + encoding.length() + endHeader.length());
// Step 2: Update the ID of 'state'.
state->id() = StateId::e_FIRST_DATA_BETWEEN_TAGS;
return stream;
}
bsl::ostream& Formatter_CompactImplUtil::addNewline(bsl::ostream& stream,
State *state)
{
// Step 1: Print a sequence of conditional tokens to 'stream' and update
// the column number and indentation level of 'state'.
if (StateId::e_IN_TAG == state->id()) {
stream << '>';
state->column() += 1;
}
stream << '\n';
state->column() = 0;
// Step 2: Update the ID of 'state'.
if (StateId::e_IN_TAG == state->id()) {
state->id() = StateId::e_FIRST_DATA_BETWEEN_TAGS;
}
return stream;
}
int Formatter_CompactImplUtil::addValidComment(
bsl::ostream& stream,
State *state,
const bsl::string_view& comment,
bool,
bool omitEnclosingWhitespace)
{
const char doubleHyphen[] = "--";
// The string "--" (double-hyphen) must not occur within comments. Also
// the grammar does not allow a comment ending in "--->".
if (comment.end() != bsl::search(comment.begin(),
comment.end(),
doubleHyphen,
doubleHyphen + sizeof doubleHyphen - 1) ||
(omitEnclosingWhitespace && !comment.empty() &&
'-' == *comment.rbegin())) {
return 1; // RETURN
}
const bsl::string_view openMarker =
omitEnclosingWhitespace ? "<!--" : "<!-- ";
const bsl::string_view closeMarker =
omitEnclosingWhitespace ? "-->" : " -->";
addCommentImpl(stream, state, comment, openMarker, closeMarker);
return 0;
}