content: package com.gelakinetic.mtgfam.helpers.util;
  
  import java.io.PrintWriter;
  import java.io.StringWriter;
  import java.text.Normalizer;
  import java.util.regex.Pattern;
  
  public class StringUtils {
  
      /**
       * Pattern used in {@link #stripAccents(String)}.
       */
      private static final Pattern STRIP_ACCENTS_PATTERN = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); //$NON-NLS-1$
  
      /**
       * The empty String {@code ""}.
       *
       * @since 2.0
       */
      public static final String EMPTY = "";
  
      private static void convertRemainingAccentCharacters(final StringBuilder decomposed) {
          for (int i = 0; i < decomposed.length(); i++) {
              if (decomposed.charAt(i) == '\u0141') {
                  decomposed.setCharAt(i, 'L');
              } else if (decomposed.charAt(i) == '\u0142') {
                  decomposed.setCharAt(i, 'l');
              }
          }
      }
  
      /**
       * <p>Removes diacritics (~= accents) from a string. The case will not be altered.</p>
       * <p>For instance, '&agrave;' will be replaced by 'a'.</p>
       * <p>Note that ligatures will be left as is.</p>
       *
       * <pre>
       * StringUtils.stripAccents(null)                = null
       * StringUtils.stripAccents("")                  = ""
       * StringUtils.stripAccents("control")           = "control"
       * StringUtils.stripAccents("&eacute;clair")     = "eclair"
       * </pre>
       *
       * @param input String to be stripped
       * @return input text with diacritics removed
       * @since 3.0
       */
      // See also Lucene's ASCIIFoldingFilter (Lucene 2.9) that replaces accented characters by their unaccented equivalent (and uncommitted bug fix: https://issues.apache.org/jira/browse/LUCENE-1343?focusedCommentId=12858907&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12858907).
      public static String stripAccents(final String input) {
          if (input == null) {
              return null;
          }
          final StringBuilder decomposed = new StringBuilder(Normalizer.normalize(input, Normalizer.Form.NFD));
          convertRemainingAccentCharacters(decomposed);
          // Note that this doesn't correctly remove ligatures...
          return STRIP_ACCENTS_PATTERN.matcher(decomposed).replaceAll(EMPTY);
      }
  
      /**
       * <p>Gets the stack trace from a Throwable as a String.</p>
       *
       * <p>The result of this method vary by JDK version as this method
       * uses {@link Throwable#printStackTrace(java.io.PrintWriter)}.
       * On JDK1.3 and earlier, the cause exception will not be shown
       * unless the specified throwable alters printStackTrace.</p>
       *
       * @param throwable the {@code Throwable} to be examined
       * @return the stack trace as generated by the exception's
       * {@code printStackTrace(PrintWriter)} method
       */
      public static String getStackTrace(final Throwable throwable) {
          final StringWriter sw = new StringWriter();
          final PrintWriter pw = new PrintWriter(sw, true);
          throwable.printStackTrace(pw);
          return sw.getBuffer().toString();
      }
  }
  