/* * [Together.java] * * Summary: Regenerates parameter keeping it together all on one line. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2009-01-14 */ package com.mindprod.htmlmacros.macro; import com.mindprod.htmlmacros.support.Tools; import java.io.File; import static java.lang.System.*; /** * Regenerates parameter keeping it together all on one line. *

* Parm can have HTML, but not embedded macros. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2009-01-14 * @see com.mindprod.htmlmacros.macro.Qualified * @since 2009-01-14 */ @SuppressWarnings( { "UnusedDeclaration" } ) public final class Together extends Macro { /** * how to use the macro */ private static final String USAGE = "\nTogether macro needs {line-parm}"; /** * guts of Together macro expansion * * @param line line to keep together * @param fileBeingProcessed File being processed that contains the macro to be expanded. * @return line all in * one piece * * @return html expansion for the macro */ private static String expand( String line, File fileBeingProcessed ) { final int origLen = line.length(); final int estLen = origLen * 11 / 5; // leave as StringBuilder final StringBuilder sb = new StringBuilder( estLen ); boolean inHtml = false; for ( int i = 0; i < origLen; i++ ) { final char c = line.charAt( i ); switch ( c ) { case '<': sb.append( c ); inHtml = true; break; case '>': sb.append( c ); inHtml = false; break; case ' ': case '\n': if ( inHtml ) { sb.append( ' ' ); } else { // would be more efficient to use