All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.util.Strings Maven / Gradle / Ivy

There is a newer version: 7.10.1
Show newest version
package org.testng.util;

import org.testng.collections.Lists;
import org.testng.collections.Maps;

import java.util.List;
import java.util.Map;

public class Strings {
  public static boolean isNullOrEmpty(String string) {
    return string == null || string.length() == 0; // string.isEmpty() in Java 6
  }

  private static List ESCAPE_HTML_LIST = Lists.newArrayList(
    "&", "&",
    "<", "<",
    ">", ">"
  );
  
  private static final Map ESCAPE_HTML_MAP = Maps.newLinkedHashMap();

  static {
    for (int i = 0; i < ESCAPE_HTML_LIST.size(); i += 2) {
      ESCAPE_HTML_MAP.put(ESCAPE_HTML_LIST.get(i), ESCAPE_HTML_LIST.get(i + 1));
    }
  }

  public static String escapeHtml(String text) {
    String result = text;
    for (Map.Entry entry : ESCAPE_HTML_MAP.entrySet()) {
      result = result.replace(entry.getKey(), entry.getValue());
    }
    return result;
  }

  public static void main(String[] args) {
    System.out.println(escapeHtml("10 < 20 && 30 > 20"));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy