@Override
	public String encodeCharacter(final char[] immune, final Character c) {

		// check for immune characters
		if (containsCharacter(c, immune)) {
			return "" + c;
		}

		// check for alphanumeric characters
		String hex = Codec.getHexForNonAlphanumeric(c);
		if (hex == null) {
			return "" + c;
		}

		// check for illegal characters
		if (((c <= 0x1f) && (c != '\t') && (c != '\n') && (c != '\r')) || ((c >= 0x7f) && (c <= 0x9f))) {
			return (" ");
		}

		// check if there's a defined entity
		String entityName = characterToEntityMap.get(c);
		if (entityName != null) {
			return "&" + entityName + ";";
		}

		// return the hex entity as suggested in the spec
		return "&#x" + hex + ";";
	}