Append an affix to the given StringBuffer.

@param buf
buffer to append to
@param isNegative
@param isPrefix
@param fieldPosition
@param parseAttr
181037
private int appendAffix(StringBuffer buf, boolean isNegative, boolean isPrefix,
                            FieldPosition fieldPosition,
                            boolean parseAttr) {
        if (currencyChoice != null) {
            String affixPat = null;
            if (isPrefix) {
                affixPat = isNegative ? negPrefixPattern : posPrefixPattern;
            } else {
                affixPat = isNegative ? negSuffixPattern : posSuffixPattern;
            }
            StringBuffer affixBuf = new StringBuffer();
            expandAffix(affixPat, null, affixBuf);
            buf.append(affixBuf);
            return affixBuf.length();
        }

        String affix = null;
        String pattern;
        if (isPrefix) {
            affix = isNegative ? negativePrefix : positivePrefix;
            pattern = isNegative ? negPrefixPattern : posPrefixPattern;
        } else {
            affix = isNegative ? negativeSuffix : positiveSuffix;
            pattern = isNegative ? negSuffixPattern : posSuffixPattern;
        }
        // [Spark/CDL] Invoke formatAffix2Attribute to add attributes for affix
        if (parseAttr) {
            // Updates for Ticket 11805.
            int offset = affix.indexOf(symbols.getCurrencySymbol());
            if (offset > -1) {
                formatAffix2Attribute(isPrefix, Field.CURRENCY, buf, offset,
                        symbols.getCurrencySymbol().length());
            }
            offset = affix.indexOf(symbols.getMinusSignString());
            if (offset > -1) {
                formatAffix2Attribute(isPrefix, Field.SIGN, buf, offset,
                        symbols.getMinusSignString().length());
            }
            offset = affix.indexOf(symbols.getPercentString());
            if (offset > -1) {
                formatAffix2Attribute(isPrefix, Field.PERCENT, buf, offset,
                        symbols.getPercentString().length());
            }
            offset = affix.indexOf(symbols.getPerMillString());
            if (offset > -1) {
                formatAffix2Attribute(isPrefix, Field.PERMILLE, buf, offset,
                        symbols.getPerMillString().length());
            }
            offset = pattern.indexOf("¤¤¤");
            if (offset > -1) {
                formatAffix2Attribute(isPrefix, Field.CURRENCY, buf, offset,
                        affix.length() - offset);
            }
        }

        // Look for SIGN, PERCENT, PERMILLE in the formatted affix.
        if (fieldPosition.getFieldAttribute() == NumberFormat.Field.SIGN) {
            String sign = isNegative ? symbols.getMinusSignString() : symbols.getPlusSignString();
            int firstPos = affix.indexOf(sign);
            if (firstPos > -1) {
                int startPos = buf.length() + firstPos;
                fieldPosition.setBeginIndex(startPos);
                fieldPosition.setEndIndex(startPos + sign.length());
            }
        } else if (fieldPosition.getFieldAttribute() == NumberFormat.Field.PERCENT) {
            int firstPos = affix.indexOf(symbols.getPercentString());
            if (firstPos > -1) {
                int startPos = buf.length() + firstPos;
                fieldPosition.setBeginIndex(startPos);
                fieldPosition.setEndIndex(startPos + symbols.getPercentString().length());
            }
        } else if (fieldPosition.getFieldAttribute() == NumberFormat.Field.PERMILLE) {
            int firstPos = affix.indexOf(symbols.getPerMillString());
            if (firstPos > -1) {
                int startPos = buf.length() + firstPos;
                fieldPosition.setBeginIndex(startPos);
                fieldPosition.setEndIndex(startPos + symbols.getPerMillString().length());
            }
        } else
        // If CurrencySymbol or InternationalCurrencySymbol is in the affix, check for currency symbol.
        // Get spelled out name if "¤¤¤" is in the pattern.
        if (fieldPosition.getFieldAttribute() == NumberFormat.Field.CURRENCY) {
            if (affix.indexOf(symbols.getCurrencySymbol()) > -1) {
                String aff = symbols.getCurrencySymbol();
                int firstPos = affix.indexOf(aff);
                int start = buf.length() + firstPos;
                int end = start + aff.length();
                fieldPosition.setBeginIndex(start);
                fieldPosition.setEndIndex(end);
            } else if (affix.indexOf(symbols.getInternationalCurrencySymbol()) > -1) {
                String aff = symbols.getInternationalCurrencySymbol();
                int firstPos = affix.indexOf(aff);
                int start = buf.length() + firstPos;
                int end = start + aff.length();
                fieldPosition.setBeginIndex(start);
                fieldPosition.setEndIndex(end);
            } else if (pattern.indexOf("¤¤¤") > -1) {
                // It's a plural, and we know where it is in the pattern.
                int firstPos = pattern.indexOf("¤¤¤");
                int start = buf.length() + firstPos;
                int end = buf.length() + affix.length(); // This seems clunky and wrong.
                fieldPosition.setBeginIndex(start);
                fieldPosition.setEndIndex(end);
            }
        }

        buf.append(affix);
        return affix.length();
    }
1076669
private static <T> StringBuilder appendAllTo(final StringBuilder buf, final String sep, final T... types) {
        Assert.requireNonNullEntries(types, "types");
        Assert.requireNotEmpty(types, "types");
        if (types.length > 0) {
            buf.append(toString(types[0]));
            for (int i = 1; i < types.length; i++) {
                buf.append(sep).append(toString(types[i]));
            }
        }
        return buf;
    }
163291
private void insertAfter(final URI hrefValue, final StringBuffer parentResult, final CharSequence tmpContent) {
        int insertpoint = parentResult.lastIndexOf("</");
        final int end = parentResult.indexOf(">", insertpoint);

        if (insertpoint == -1 || end == -1) {
            logger.error(MessageUtils.getMessage("DOTJ033E", hrefValue.toString()).toString());
        } else {
            if (ELEMENT_NAME_DITA.equals(parentResult.substring(insertpoint, end).trim())) {
                insertpoint = parentResult.lastIndexOf("</", insertpoint - 1);
            }
            parentResult.insert(insertpoint, tmpContent);
        }
    }
38499
private static <T> StringBuilder appendAllTo(final StringBuilder buf, final String sep, final T... types) {
        Validate.notEmpty(Validate.noNullElements(types));
        if (types.length > 0) {
            buf.append(toString(types[0]));
            for (int i = 1; i < types.length; i++) {
                buf.append(sep).append(toString(types[i]));
            }
        }
        return buf;
    }
1178365
private void render(StringBuilder buf, int key, String undef, boolean expanded) {
    boolean force = key != VARIANT && (key == LANGUAGE || expanded);
    String value = fields[key];
    if (value != null || force) {
      if (buf.length() > 0) {
        buf.append(SEP);
      }
      buf.append(value == null ? undef : value);
    }
  }
1110634
private void initPrefixStatsField(String field) {
    if (!singlePositionPrefix.containsKey(field)) {
      singlePositionPrefix.put(field, new HashSet<String>());
    }
    if (!multiplePositionPrefix.containsKey(field)) {
      multiplePositionPrefix.put(field, new HashSet<String>());
    }
    if (!setPositionPrefix.containsKey(field)) {
      setPositionPrefix.put(field, new HashSet<String>());
    }
  }
1158547
public static void formatForConsole(StringBuilder buf, int width, Collection<TrackedParameter> options) {
    for(TrackedParameter pair : options) {
      Parameter<?> par = pair.getParameter();
      println(buf//
          .append(SerializedParameterization.OPTION_PREFIX).append(par.getOptionID().getName()) //
          .append(' ').append(par.getSyntax()).append(FormatUtil.NEWLINE), //
          width, getFullDescription(par));
    }
  }
157167
public void toRSL(StringBuffer buf, boolean explicitConcat) {
	buf.append("$(");
	buf.append( value );

	if (defValue != null) {
	    buf.append(" ");
	    defValue.toRSL(buf, explicitConcat);
	}

	buf.append(")");

	if (concatValue == null) return;

	if (explicitConcat) buf.append(" # ");

	concatValue.toRSL(buf, explicitConcat);
    }
288120
private void appendCauses(StringBuilder buf, Throwable thrown) {
    buf.append(thrown.toString()).append(OutputStreamLogger.NEWLINE);
    StackTraceElement[] stack = thrown.getStackTrace();
    int end = stack.length - 1;
    prune: for(; end >= 0; end--) {
      String cn = stack[end].getClassName();
      for(String pat : PRUNE) {
        if(cn.startsWith(pat)) {
          continue prune;
        }
      }
      break;
    }
    if(end <= 0) {
      end = stack.length - 1;
    }
    for(int i = 0; i <= end; i++) {
      buf.append("\tat ").append(stack[i]).append(OutputStreamLogger.NEWLINE);
    }
    if(end < stack.length - 1) {
      buf.append("\tat [...]").append(OutputStreamLogger.NEWLINE);
    }
    if(thrown.getCause() != null) {
      buf.append("Caused by: ");
      appendCauses(buf, thrown.getCause());
    }
  }
1368958
private static void _smartAppend(StringBuilder buf, char c) {
        if (buf.length() != 0 &&
            buf.charAt(buf.length() - 1) != c) {
            buf.append(c);
        }
    }
228339
public static boolean isPrefix(ByteBuffer prefix, ByteBuffer value)
    {
        if (prefix.remaining() > value.remaining())
            return false;

        int diff = value.remaining() - prefix.remaining();
        return prefix.equals(value.duplicate().limit(value.remaining() - diff));
    }
1130714
private Expression handleThisSuffix(Java7Parser.PrimaryContext primaryContext, AdapterParameters adapterParameters) {
        /*
            thisSuffix
            locals [int operationType]
                :   (LBRACKET expression RBRACKET)+                     {$operationType = 1;}
                |   arguments                                           {$operationType = 2;}
                |   DOT nonWildcardTypeArguments Identifier arguments   {$operationType = 3;}
                |   innerCreator                                        {$operationType = 4;}
                ;


        //this.m.m.m[].class;        // 0 :   (LBRACKET RBRACKET)+ DOT CLASS                      // ClassOrInterfaceType ClassOrInterfaceType ClassOrInterfaceType ReferenceType ClassExpr
        this.m.m.m[1];             // 1 |   (LBRACKET expression RBRACKET)+                     // NameExpr FieldAccessExpr FieldAccessExpr ArrayAccessExpr
        this.m.m.m("");            // 2 |   arguments                                           // NameExpr FieldAccessExpr MethodCallExpr
        //this.m.m.m.class;          // 3 |   DOT CLASS                                           // ClassOrInterfaceType ClassOrInterfaceType ClassOrInterfaceType ReferenceType ClassExpr
        this.m.m.<T>m("");         // 4 |   DOT nonWildcardTypeArguments Identifier arguments   // NameExpr FieldAccessExpr MethodCallExpr
        this.m.m.m.this;           // 5 |   DOT THIS                                            // NameExpr FieldAccessExpr FieldAccessExpr ThisExpr
        //m.m.super("");      // 6 |   DOT SUPER arguments

        */

        ThisExpr thisExpr = new ThisExpr();
        Expression leftExpression = thisExpr;

        for (int i = 0; i < primaryContext.Identifier().size(); i++) {
            FieldAccessExpr fieldAccessExpr = new FieldAccessExpr();
            fieldAccessExpr.setField(primaryContext.Identifier(i).getText());
            fieldAccessExpr.setScope(leftExpression);
            leftExpression = fieldAccessExpr;
        }

        // if thisSuffix is null/not specified
        if (primaryContext.thisSuffix() == null) {
            return leftExpression;
        }

        ClassOrInterfaceType rootType = new ClassOrInterfaceType();

        if (primaryContext.Identifier() != null && primaryContext.Identifier().size() > 0) {
            rootType.setName(primaryContext.Identifier(0).getText());
        }

        switch (primaryContext.thisSuffix().operationType) {
            case 1:
                for (int i = 0; i < primaryContext.thisSuffix().LBRACKET().size(); i++) {
                    ArrayAccessExpr arrayAccessExpr = new ArrayAccessExpr();
                    arrayAccessExpr.setName(leftExpression);
                    arrayAccessExpr.setIndex(Adapters.getExpressionContextAdapter().adapt(primaryContext.thisSuffix().expression(i), adapterParameters));
                    leftExpression = arrayAccessExpr;
                }

                return leftExpression;
            case 2:
                MethodCallExpr methodCallExpr = new MethodCallExpr();

                if (leftExpression instanceof FieldAccessExpr) {
                    methodCallExpr.setName(((FieldAccessExpr)leftExpression).getField());

                    // Set the leftExpression back one since we're changing the top one to a method call
                    leftExpression = ((FieldAccessExpr) leftExpression).getScope();
                    methodCallExpr.setScope(leftExpression);
                }

                if (methodCallExpr.getName() == null) {
                    throw new RuntimeException("Syntax Error: possibly calling 'this' as a method with arguments.  Something like 'this(\"\")'");
                }

                methodCallExpr.setArgs(Adapters.getArgumentsContextAdapter().adapt(primaryContext.thisSuffix().arguments(), adapterParameters));
                leftExpression = methodCallExpr;

                return leftExpression;
            case 3:
                List<Type> typeList = Adapters.getTypeListContextAdapter().adapt(primaryContext.thisSuffix().nonWildcardTypeArguments().typeList(), adapterParameters);

                MethodCallExpr typeArgMethodCallExpr = new MethodCallExpr();
                typeArgMethodCallExpr.setName(primaryContext.thisSuffix().Identifier().getText());
                typeArgMethodCallExpr.setTypeArgs(typeList);
                typeArgMethodCallExpr.setScope(leftExpression);
                typeArgMethodCallExpr.setArgs(Adapters.getArgumentsContextAdapter().adapt(primaryContext.thisSuffix().arguments(), adapterParameters));
                leftExpression = typeArgMethodCallExpr;

                return leftExpression;
            case 4:
                ObjectCreationExpr objectCreationExpr = Adapters.getInnerCreatorContextAdapter().adapt(primaryContext.thisSuffix().innerCreator(), adapterParameters);
                objectCreationExpr.setScope(leftExpression);
                return objectCreationExpr;
        }

        return null;
    }
669959
private void appendParameter(Object value, StringBuffer buf)
    {
        if (value instanceof Query)
        {
            appendSubQuery((Query) value, buf);
        }
        else
        {
            buf.append("?");
        }
    }
1210395
private void formatAffix2Attribute(boolean isPrefix, Field fieldType,
        StringBuffer buf, int offset, int symbolSize) {
        int begin;
        begin = offset;
        if (!isPrefix) {
            begin += buf.length();
        }

        addAttribute(fieldType, begin, begin + symbolSize);
    }
715906
private StringBuilder appendAttributeValue(final String value, final StringBuilder buf) {
      if(value.contains("\"")) {
         buf.append("\'").append(escapeAttribute(value)).append("\'");
      } else if(value.contains(" ") || value.contains("\'") || value.contains("=")) {
         buf.append("\"").append(escapeAttribute(value)).append("\"");
      } else {
         buf.append(escapeAttribute(value));
      }
      return buf;
   }
529056
private void toPrettyString(int indentLevel, StringBuilder buf) {
    for (int i = 0; i < indentLevel; i++) {
      buf.append("  ");
    }
    buf.append(shortName).append(": ").append(targetPatterns);
    for (GrammaticalRelation child : children) {
      buf.append('\n');
      child.toPrettyString(indentLevel + 1, buf);
    }
  }
655961
protected void process(StringBuffer buf, Object p) {
		buf.append('<');
		buf.append(p);
		buf.append('>');
		buf.append(this.get(p));
		buf.append("</");
		buf.append(p);
		buf.append('>');
	}