From 86c651625c573c929453715d8f7b39ca52b30992 Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 23 Jan 2014 16:59:24 +0000 Subject: [PATCH] Added a new block policy to only generate a block if the following is not empty. --- src/Generator/Generators/Template.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/Template.cs b/src/Generator/Generators/Template.cs index 16f6348c..e0827000 100644 --- a/src/Generator/Generators/Template.cs +++ b/src/Generator/Generators/Template.cs @@ -10,7 +10,8 @@ namespace CppSharp.Generators { Never, Always, - BeforeNextBlock + BeforeNextBlock, + IfNotEmpty } public class BlockKind @@ -87,10 +88,27 @@ namespace CppSharp.Generators uint totalIndent = 0; Block previousBlock = null; + var blockIndex = 0; foreach (var childBlock in Blocks) { var childText = childBlock.Generate(options); + var nextBlock = (++blockIndex < Blocks.Count) + ? Blocks[blockIndex] + : null; + + var skipBlock = false; + if (nextBlock != null) + { + var nextText = nextBlock.Generate(options); + if (string.IsNullOrEmpty(nextText) && + childBlock.NewLineKind == NewLineKind.IfNotEmpty) + skipBlock = true; + } + + if (skipBlock) + continue; + if (string.IsNullOrEmpty(childText)) continue;