Encoded literal characters surrounding template variables,
ex. "a {id} b" will be encoded to "a%20{id}%20b"

@return encoded value
170973
public String encodeLiteralCharacters(boolean isQuery) {
        final float encodedRatio = 1.5f;
        StringBuilder sb = new StringBuilder((int) (encodedRatio * template.length()));
        for (UriChunk chunk : uriChunks) {
            String val = chunk.getValue();
            if (chunk instanceof Literal) {
                sb.append(HttpUtils.encodePartiallyEncoded(val, isQuery));
            } else {
                sb.append(val);
            }
        }
        return sb.toString();
    }
206902
public static String valueString(final Object value) {
        StringBuilder val = new StringBuilder(""+value);
        if (null != value && value.getClass().isArray()) {
            val = new StringBuilder("{");
            for (int i = 0; i < Array.getLength(value); i++)
                val.append(valueString(Array.get(value, i))).append(", ");
            if (val.reverse().charAt(0) == ' ')
                val.delete(0, 2);
            return val.reverse().append("}").toString();
        }
        if (value instanceof Collection) {
            val = new StringBuilder("[");
            for (Object v : ((Collection<?>) value))
                val.append(valueString(v)).append(", ");
            if (val.reverse().charAt(0) == ' ')
                val.delete(0, 2);
            return val.reverse().append("]").toString();
        }
        if (value instanceof Map) {
            val = new StringBuilder("{");
            for (Entry<?, ?> e : ((Map<?, ?>) value).entrySet())
                val.append(valueString(e.getKey())).append("=")
                .append(valueString(e.getValue())).append(", ");
            if (val.reverse().charAt(0) == ' ')
                val.delete(0, 2);
            return val.reverse().append("}").toString();
        }
        if (value instanceof Entry) {
            return new StringBuilder(
                    valueString(((Entry<?, ?>) value).getKey()))
                .append("=").append(
                    valueString(((Entry<?, ?>) value).getValue()))
                .toString();
        }
        if (value instanceof String)
            return val.insert(0, "\"").append("\"").toString();
        if (Primitive.unwrap(value) instanceof Character)
            return val.insert(0, "'").append("'").toString();
        if (Primitive.unwrap(value) instanceof Number) {
            if (Primitive.unwrap(value) instanceof Byte)
                return val.append("o").toString();
            if (Primitive.unwrap(value) instanceof Short)
                return val.append("s").toString();
            if (Primitive.unwrap(value) instanceof Integer)
                return val.append("I").toString();
            if (Primitive.unwrap(value) instanceof Long)
                return val.append("L").toString();
            if (Primitive.unwrap(value) instanceof BigInteger)
                return val.append("W").toString();
            if (Primitive.unwrap(value) instanceof Float)
                return val.append("f").toString();
            if (Primitive.unwrap(value) instanceof Double)
                return val.append("d").toString();
            if (Primitive.unwrap(value) instanceof BigDecimal)
                return val.append("w").toString();
        }
        return val.toString();
    }

    /** Count region matches.
     * @param one string to compare
     * @param two string to compare with
     * @return return max common string */
    public static String maxCommonPrefix(String one, String two) {
        int i=0;
        while( one.regionMatches(0, two, 0, i ))
            i++;
        return one.substring(0, i-1);
    }

    /** Produce a method string from supplied value args.
     * @param name method name.
     * @param args the value to process.
     * @return still just a method string. */
    public static String methodString(String name, Object[] args) {
        return methodString(name, Types.getTypes(args));
    }

    /** Produce a simple string representation of a method name with args.
     * @param name the method name
     * @param types the parameter type names
     * @return string representation of a method */
    public static String methodString(String name, String[] types) {
        StringBuilder sb = new StringBuilder();
        sb.append(name).append('(');
        for( int i=0; i<types.length; i++ ) {
            if (i != 0)
                sb.append(", ");
            sb.append(types[i]);
        }
        sb.append(')');
        return sb.toString();
    }

    /** Produce a simple string representation of a method name with args.
     * @param name the method name
     * @param types the parameter type args
     * @return string representation of a method */
    public static String methodString(String name, Class<?>[] types) {
        return methodString(name, getTypeNames(types));
    }

    /** Produce a simple string representation of a method name with args.
     * @param name the method name
     * @param types the parameter type args
     * @param names the parameter names
     * @return string representation of a method */
    public static String methodString(String name, Class<?>[] types, String[] names) {
        return methodString(name, getTypeNames(types, names));
    }

    /** Get type names as stream.
     * @param types class[] of classes
     * @return Stream of type names */
    private static Stream<String> getTypeNamesStream(Class<?>[] types) {
        return Stream.of(types).map(StringUtil::getTypeName);
    }

    /** Get type names as string list.
     * @param types class[] of classes
     * @return List of type names */
    private static List<String> getTypeNamesList(Class<?>[] types) {
        return getTypeNamesStream(types).collect(Collectors.toList());
    }

    /** Get type names as string[].
     * @param types class[] of classes
     * @return String[] of type names */
    private static String[] getTypeNames(Class<?>[] types) {
        return getTypeNamesStream(types).toArray(String[]::new);
    }

    /** Get type names as string[].
     * @param types class[] of parameter classes
     * @param names string[] of parameter names
     * @return String[] of type names */
    private static String[] getTypeNames(Class<?>[] types, String[] names) {
        Iterator<String> namesIt = Stream.of(names).iterator();
        return getTypeNamesStream(types)
                .map(type -> type +" "+ namesIt.next())
                .toArray(String[]::new);
    }

    /** Get type name as string.
     * @param type class
     * @return simple name or Object if null */
    private static String getTypeName(Class<?> type) {
        return ( null == type ) ? "Object"
                : type.getSimpleName();
    }

    /** Get extends string for class.
     * @param type the class to interrogate.
     * @return if type isInterface return empty string
     *         else return extends superClass */
    private static String getTypeExtends(Class<?> type) {
        return type.isInterface() ? "" : " extends " + getTypeName(type.getSuperclass());
    }

    /** Get the implements/extends string for type.
     * @param type the class to interrogate.
     * @return string implements (for classes)/extends (for interfaces)
     *         and comma separated list of interfaces. */
    private static String getTypeImplements(Class<?> type) {
        StringBuilder sb = new StringBuilder();
        if ( type.getInterfaces().length > 0 )
            sb.append(type.isInterface() ? " extends " : " implements ")
             .append(String.join(", ", getTypeNamesList(type.getInterfaces())));
        return sb.toString();
    }

    /** Produce a complete string representation of a reflect method. Shows
     * modifiers, return type, name and parameter types.
     * @param method a java reflect method
     * @return string representation of a method */
    public static String methodString(Method method) {
        String mods = Modifier.toString(method.getModifiers());
        StringBuilder sb = new StringBuilder();
        return sb.append(mods).append(" ")
            .append(getTypeName(method.getReturnType())).append(" ")
            .append(methodString(method.getName(), method.getParameterTypes()))
            .append(mods.contains("abstract") ? ";" : " {}").toString();
    }

    /** Produce a complete string representation of a bsh method. Shows
     * modifiers, return type, name and parameter types.
     * @param method a bsh method
     * @return string representation of a method */
    public static String methodString(BshMethod method) {
        String mods = method.getModifiers().toString().substring(11);
        StringBuilder sb = new StringBuilder();
        return sb.append(mods).append(" ")
            .append(getTypeName(method.getReturnType())).append(" ")
            .append(methodString(method.getName(),
                    method.getParameterTypes(), method.getParameterNames()))
            .append(mods.contains("abstract") ? ";" : " {}").toString();
    }

    /** Produce a string representation of a bsh generated class declaration.
     * Shows modifiers, name, extends and implements.
     * @param type the class to reflect
     * @return string representation of a class declaration */
    private static String generatedClassString(Class<?> type) {
        StringBuilder sb = new StringBuilder();
        sb.append(Reflect.getClassModifiers(type).toString().substring(11))
          .append(type.isInterface() ? " interface" : " class")
          .append(" ").append(getTypeName(type))
          .append(getTypeExtends(type))
          .append(getTypeImplements(type));
        return sb.append(" {").toString().trim();
    }

    /** Produce a string representation of a class declaration.
     * Verifies if type is a generated class else builds a java
     * reflect class string definition.
     * Shows modifiers, name, extends and implements.
     * @param type the class to reflect
     * @return string representation of a class declaration */
    public static String classString(Class<?> type) {
        if (Reflect.isGeneratedClass(type))
            return generatedClassString(type);
        StringBuilder sb = new StringBuilder();
        sb.append(Modifier.toString(type.getModifiers()))
            .append(type.isInterface() ? "": " class")
            .append(" ").append(getTypeName(type))
            .append(getTypeExtends(type))
            .append(getTypeImplements(type));
        return sb.append(" {").toString().trim();
    }

    /** Produce a string representation of a bsh variable declaration.
     * Shows modifiers, type and name.
     * @param var the variable to reflect
     * @return string representation of variable declaration */
    public static String variableString(Variable var) {
        StringBuilder sb = new StringBuilder();
        sb.append(var.getModifiers().toString().substring(11))
            .append(" ").append(getTypeName(var.getType()))
            .append(" ").append(var.getName());
        return sb.append(";").toString();
    }

    /** Produce a string representation of a java field declaration.
     * Shows modifiers, type and name.
     * @param var the field to reflect
     * @return string representation of field declaration */
    public static String variableString(Field field) {
        StringBuilder sb = new StringBuilder();
        sb.append(Modifier.toString(field.getModifiers()))
            .append(" ").append(getTypeName(field.getType()))
            .append(" ").append(field.getName());
        return sb.append(";").toString();
    }
}
1273727
@SuppressWarnings({"unchecked", "rawtypes"})
    public U encode(Object value) {
        requireNonNull(value, "Value for encoding can not be null");

        TypeEncoder encoder = classMapping.get(value.getClass());
        if (encoder != null)
            return (U) encoder.encode(value);

        throw new TypeEncodingException("An unknown type [" + value.getClass() + "] was encountered");
    }
1062852
public static String encodeAttributeValue(String value)
	{
		String _result = value.replaceAll(PATTERN__CHAR_AMPERSAND, VALUE__ENTITY_AMPERSAND);
		_result = _result.replaceAll(PATTERN__CHAR_QUOTE, VALUE__ENTITY_QUOTE);
		return _result;
	}
1337129
public static String encode(String value) {
		if(value==null) return null;

		StringBuilder encoded=null;
		int len=value.length();
		for(int c=0;c<len;c++) {
			char ch=value.charAt(c);
			if(
				(ch<' ' && ch!='\n' && ch!='\r')
				|| ch=='\\'
			) {
				if(encoded==null) {
					encoded=new StringBuilder();
					if(c>0) encoded.append(value, 0, c);
				}
				if(ch=='\\') encoded.append("\\\\");
				else if(ch=='\b') encoded.append("\\b");
				else if(ch=='\f') encoded.append("\\f");
				else if(ch=='\t') encoded.append("\\t");
				else {
					int ich=ch;
					encoded
						.append("\\u")
						.append(hexChars[(ich>>>12)&15])
						.append(hexChars[(ich>>>8)&15])
						.append(hexChars[(ich>>>4)&15])
						.append(hexChars[ich&15])
					;
				}
			} else {
				if(encoded!=null) encoded.append(ch);
			}
		}
		return encoded==null ? value : encoded.toString();
	}
1309008
public static String encodeXmlAttribute(String str) {
    if (str == null) return null;
    int len = str.length();
    if (len == 0) return str;
    StringBuffer encoded = new StringBuffer();
    for (int i = 0; i < len; i++) {
      char c = str.charAt(i);
      if (c == '<') encoded.append("&lt;");
      else if (c == '\"') encoded.append("&quot;");
      else if (c == '>') encoded.append("&gt;");
      else if (c == '\'') encoded.append("&apos;");
      else if (c == '&') encoded.append("&amp;");
      else encoded.append(c);
    }
    return encoded.toString();
  }
474711
public byte[] encode() {
		char type = getAttributeType();
		byte binValue[] = new byte[HEADER_LENGTH + getDataLength()];

		// Type
		binValue[0] = (byte) (type >> 8);
		binValue[1] = (byte) (type & 0x00FF);

		// Length
		binValue[2] = (byte) (getDataLength() >> 8);
		binValue[3] = (byte) (getDataLength() & 0x00FF);

		return binValue;
	}
1301780
@Override
    public String encode() {
        StringBuffer buffer = new StringBuffer("[");
        if (lowerBound != null) {
            buffer.append(lowerBound.encode());
            buffer.append(',');
        }
        buffer.append(basis.encode());
        if (upperBound != null) {
            buffer.append(',');
            buffer.append(upperBound.encode());
        }
        buffer.append(']');
        return buffer.toString();
    }
1097057
@Override
   public String encode() {
       ReadableByteArrayOutputStream out = new ReadableByteArrayOutputStream();
       encode(out);
       return out.toString();
   }
91143
public String keyValueList() {
		String separator = "";
		StringBuilder buffer = new StringBuilder();

		for (int i = 0; i < names.size(); i++) {
			buffer.append(separator + "?");
			separator = ", ";
		}

		return buffer.toString();
	}
295094
private String nextString() {
    assert input.charAt(idx - 1) == '"' : "Char is '" + input.charAt(idx - 1) + '\'';
    StringBuilder sb = new StringBuilder();
    while (true) {
      char c = nextChar();
      switch (c) {
        case '\n':
        case '\r':
          throw new IllegalArgumentException("Unterminated string");
        case '\\':
          c = nextChar();
          switch (c) {
            case 'b':
              sb.append('\b');
              break;
            case 't':
              sb.append('\t');
              break;
            case 'n':
              sb.append('\n');
              break;
            case 'f':
              sb.append('\f');
              break;
            case 'r':
              sb.append('\r');
              break;
            case 'u':
              sb.append((char) Integer.parseInt(input.substring(idx, idx + 4), 16));
              idx += 4;
              break;
            case '"':
            case '\'':
            case '\\':
            case '/':
              sb.append(c);
              break;
            default:
              throw new IllegalArgumentException("Illegal escape");
          }
          break;
        default:
          if (c == '"') {
            return sb.toString();
          }
          sb.append(c);
      }
    }
  }
1181045
function () {
      var val = '"' + this.value + '"';
      if (this.lang !== undefined) {
        val += '@' + this.lang;
      } else if (this.datatype !== undefined) {
        val += '^^<' + this.datatype + '>';
      }
      return val;
    }
1219003
private static String getKeyValuePair(final Entry<String,String> param, 
        final boolean formEncoding)
        {
        try 
            {
            return getKeyValuePair(param.getKey(),param.getValue(),formEncoding);
            }
        catch (final Exception e)
            {
            LOG.error("Could not get encoding for: {}", param, e);
            return "unknown=unknown";
            }
        }
429088
public String toTemplateString() {
    String[] parametersName =
        this.parameters.stream().map(VariableInfo::getName).toArray(String[]::new);

    return this.getId() + "(" + String.join(", ", parametersName) + ")";
  }
1287344
public function varsToEncode()
    {
        if ($this->isAutoEncodeAll() === true) {
            $allClassVariables = array();
            $vars = SerializationHelper::getProperties($this);
            foreach ($vars as $classVar => $val) {
                if (HtmlMarkupSerializationHelper::encodableClassVariable($this, $classVar)) {
                    $allClassVariables[] = $classVar;
                }
            }
            return $allClassVariables;
        } else {
            return $this->varsToEncode;
        }
    }
188124
private String escapeString(String value)
   {
      m_buffer.setLength(0);
      m_buffer.append('"');
      for (int index = 0; index < value.length(); index++)
      {
         char c = value.charAt(index);
         switch (c)
         {
            case '"':
            {
               m_buffer.append("\\\"");
               break;
            }

            case '\\':
            {
               m_buffer.append("\\\\");
               break;
            }

            case '/':
            {
               m_buffer.append("\\/");
               break;
            }

            case '\b':
            {
               m_buffer.append("\\b");
               break;
            }

            case '\f':
            {
               m_buffer.append("\\f");
               break;
            }

            case '\n':
            {
               m_buffer.append("\\n");
               break;
            }

            case '\r':
            {
               m_buffer.append("\\r");
               break;
            }

            case '\t':
            {
               m_buffer.append("\\t");
               break;
            }

            default:
            {
               // Append if it's not a control character (0x00 to 0x1f)
               if (c > 0x1f)
               {
                  m_buffer.append(c);
               }
               break;
            }
         }
      }
      m_buffer.append('"');
      return m_buffer.toString();
   }
1196160
private void encodeThis() throws IOException {
        if (id == null && names == null && serialNum == null) {
            this.extensionValue = null;
            return;
        }
        DerOutputStream seq = new DerOutputStream();
        DerOutputStream tmp = new DerOutputStream();
        if (id != null) {
            DerOutputStream tmp1 = new DerOutputStream();
            id.encode(tmp1);
            tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                              false, TAG_ID), tmp1);
        }
        try {
            if (names != null) {
                DerOutputStream tmp1 = new DerOutputStream();
                names.encode(tmp1);
                tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                                  true, TAG_NAMES), tmp1);
            }
        } catch (Exception e) {
            throw new IOException(e.toString());
        }
        if (serialNum != null) {
            DerOutputStream tmp1 = new DerOutputStream();
            serialNum.encode(tmp1);
            tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                              false, TAG_SERIAL_NUM), tmp1);
        }
        seq.write(DerValue.tag_Sequence, tmp);
        this.extensionValue = seq.toByteArray();
    }