Browse Source

Fix generation of text blocks using NewLineKind.IfNotEmpty.

instantiate-types-nested-templates
Joao Matos 5 years ago committed by João Matos
parent
commit
39ce0255b5
  1. 23
      src/Generator/Utils/BlockGenerator.cs

23
src/Generator/Utils/BlockGenerator.cs

@ -125,33 +125,17 @@ namespace CppSharp
var builder = new StringBuilder(); var builder = new StringBuilder();
Block previousBlock = null; Block previousBlock = null;
var previousBlockEmpty = false;
var blockIndex = 0;
foreach (var childBlock in Blocks) foreach (var childBlock in Blocks)
{ {
var childText = childBlock.Generate(); var childText = childBlock.Generate();
var nextBlock = (++blockIndex < Blocks.Count)
? Blocks[blockIndex]
: null;
var skipBlock = false;
if (nextBlock != null)
{
var nextText = nextBlock.Generate();
if (nextText.Length == 0 &&
childBlock.NewLineKind == NewLineKind.IfNotEmpty)
skipBlock = true;
}
if (skipBlock)
continue;
if (childText.Length == 0) if (childText.Length == 0)
continue; continue;
if (previousBlock != null && if (previousBlock != null &&
previousBlock.NewLineKind == NewLineKind.BeforeNextBlock) (previousBlock.NewLineKind == NewLineKind.BeforeNextBlock ||
(previousBlock.NewLineKind == NewLineKind.IfNotEmpty && !previousBlockEmpty)))
builder.AppendLine(); builder.AppendLine();
builder.Append(childText); builder.Append(childText);
@ -160,6 +144,7 @@ namespace CppSharp
builder.AppendLine(); builder.AppendLine();
previousBlock = childBlock; previousBlock = childBlock;
previousBlockEmpty = childText.Length == 0;
} }
if (Text.StringBuilder.Length != 0) if (Text.StringBuilder.Length != 0)

Loading…
Cancel
Save