code: public static String normalizeString(String s, boolean canonical)
     {
  
        StringBuilder strBuf = new StringBuilder();
        int len = (s != null) ? s.length() : 0;
        for (int i = 0; i < len; i++)
        {
           char c = s.charAt(i);
           if ('_' == c)
           {
              if (len - i > ENCODE_CHARS)
              {
                 String spart = s.substring(i, i + ENCODE_CHARS);
                 Matcher encodeMatcher = ENCODE_PATTERN.matcher(spart);
                 if (encodeMatcher.matches())
                    strBuf.append(normalizeChar(c, canonical));
                 else
                    strBuf.append(c);
              }
              else
                 strBuf.append(c);
           }
           else
              strBuf.append(normalizeChar(c, canonical));
        }
        return new String(strBuf);
     }
docs: Normalizes and prints the given string.