Formats a string (typically a component {@link Description}) into an
appropriate set of HTML paragraphs ('p' tag).

@param str
@return
504227
public static String createHtmlParagraphs(String str) {
        if (Strings.isNullOrEmpty(str)) {
            return "";
        }
        str = "<p>" + str + "</p>";
        str = StringUtils.replaceAll(str, "\n\n", "\n");
        str = StringUtils.replaceAll(str, "\n", "</p><p>");
        return str;
    }
890623
public StringGrabber set(String str) {
		if (str == null)
		{
			str = "";
		}
		return set(new StringBuilder(str));
	}
57968
public String trimLeading(String str) {
        if (str == null) {
            return null;
        }

        int length = str.length();
        for (int i=0; i<length; i++) {
            if (str.charAt(i) > ' ') {
                return str.substring(i);
            }
        }

        return "";
    }
950285
public static List<String> split(
                    final String str
                    )
    {
        String  s = str;
        if (s != null) {
            s = s.trim();
        }

        List<String>  list = new ArrayList<String>();
        if (s == null || s.length() == 0) {
            return list;
        }

        String[]  tokens = s.split( "[ \t\n\r\f]" );
        // NOTE: tokens[i] may be an empty string "".

        // excludes empty strings.
        for (String  t : tokens) {
            if (t.length() > 0) {
                list.add( t );
            }
        }

        return list;
    }
549472
public static String quote(String str) {
        int len = str.length();
        StringBuffer buf = new StringBuffer(len+2);
        buf.append("\"");
        char c;
        for (int i=0;i<len;i++) {
            c = str.charAt(i);
            if (c == '"' || c == '\\') {
                buf.append("\\");
            }
            buf.append(c);
        }
        buf.append("\"");
        return buf.toString();
    }
1159600
public JBBPTextWriter Str(final String... str) throws IOException {
    JBBPUtils.assertNotNull(str, "String must not be null");

    final String oldPrefix = this.prefixValue;
    final String oldPostfix = this.postfixValue;
    this.prefixValue = "";
    this.postfixValue = "";

    for (final String s : str) {
      ensureValueMode();
      printValueString(s == null ? "<NULL>" : s);
    }

    this.prefixValue = oldPrefix;
    this.postfixValue = oldPostfix;
    return this;
  }
950411
public static final String decode(String str)
    {
        Matcher m = ENT.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find())
        {
            String entity = m.group(1);
            Matcher m2 = HENT.matcher(entity);
            Integer codePoint = null;
            if (m2.matches())
            {
                codePoint = Integer.parseInt(m2.group(1));
            }
            else
            {
                codePoint = codePointMap.get(entity);
            }
            if (codePoint == null)
            {
                m.appendReplacement(sb, m.group());
            }
            else
            {
                String s = new String(new int[] {codePoint.intValue()}, 0, 1);
                m.appendReplacement(sb, s);
            }
        }
        m.appendTail(sb);
        return sb.toString();
    }
548613
@Trivial
    public static final String normalizeString(String str) {
        return (str == null || str.length() == 0) ? " " : str;
    }
1088755
public static String trim(String str) {
		return str != null && str.length() > 0 ? str.trim() : str;
	}
1347965
public IStringBuffer append( String str )
    {
        if ( str == null )
            throw new NullPointerException();
        //check the necessary to resize the buffer.
        if ( count + str.length() > buff.length ) {
            resizeTo( (count + str.length()) * 2 + 1 );
        }
        
        for ( int j = 0; j < str.length(); j++ ) {
            buff[count++] = str.charAt(j);
        }
        
        return this;
    }
277195
public static String escapeForXML(String str) {
        StringBuilder sb = new StringBuilder(str.length());

        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);

            boolean foundEscape = false;
            for (int j = 0; j < toBeEscaped.length; j++) {
                if (c == toBeEscaped[j]) {
                    sb.append(escaped[j]);
                    foundEscape = true;
                    break;
                }
            }

            if (!foundEscape) {
                sb.append(c);
            }
        }
        return sb.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();
  }
650658
public static String decode(String str) {
    if (str!=null) {
      try {
        StringBuilder sb = new StringBuilder();
        for (int idx = str.toLowerCase().indexOf("%2f"); idx>=0; idx = str.toLowerCase().indexOf("%2f")) {
          sb.append(java.net.URLDecoder.decode(str.substring(0, idx),"UTF-8")).append(str.substring(idx, idx+3));
          str = str.substring(idx+3);
        }
        sb.append(java.net.URLDecoder.decode(str,"UTF-8"));
        str = sb.toString();
      } catch (Exception ex) {
      }
    }
    return str;
  }
357683
public static String tokenize(String str) {		
		str = str.replaceAll("``", " `` ");
		str = str.replaceAll("''", "  '' ");
		str = str.replaceAll("\"", "  \" ");
		str = str.replaceAll("([?!\";#$&])", " $1 ");                
		str = str.replaceAll("\\.\\.\\.", " ... ");
		str = str.replaceAll("([^.])([.])([\\])}>\"']*)\\s*$", "$1 $2$3 ");		
		str = str.replaceAll("([\\[\\](){}<>])", " $1 ");
		str = str.replaceAll("--", " -- ");

		str = str.replaceAll("$", " ");
		str = str.replaceAll("^", " ");

		//str = str.replaceAll("\"", " '' ");
		str = str.replaceAll("([^'])' ", "$1 ' ");
		str = str.replaceAll("'([sSmMdD]) ", " '$1 ");
		str = str.replaceAll("'ll ", " 'll ");
		str = str.replaceAll("'re ", " 're ");
		str = str.replaceAll("'ve ", " 've ");
		str = str.replaceAll("n't ", " n't ");
		str = str.replaceAll("'LL ", " 'LL ");
		str = str.replaceAll("'RE ", " 'RE ");
		str = str.replaceAll("'VE ", " 'VE ");
		str = str.replaceAll("N'T ", " N'T ");

		str = str.replaceAll(" ([Cc])annot ", " $1an not ");
		str = str.replaceAll(" ([Dd])'ye ", " $1' ye ");
		str = str.replaceAll(" ([Gg])imme ", " $1im me ");
		str = str.replaceAll(" ([Gg])onna ", " $1on na ");
		str = str.replaceAll(" ([Gg])otta ", " $1ot ta ");
		str = str.replaceAll(" ([Ll])emme ", " $1em me ");
		str = str.replaceAll(" ([Mm])ore'n ", " $1ore 'n ");
		str = str.replaceAll(" '([Tt])is ", " $1 is ");
		str = str.replaceAll(" '([Tt])was ", " $1 was ");
		str = str.replaceAll(" ([Ww])anna ", " $1an na ");

		//"Nicole I. Kidman" gets tokenized as "Nicole I . Kidman"
		str = str.replaceAll(" ([A-Z])\\. ", " $1 . ");
		
		
		//written by TuNC from here
	    str = str.replaceAll(",([^0-9])", ", $1");
		str = str.replaceAll("'([^'])", "' $1");   
		str = str.replaceAll("([^\\xBB])(\\xBB)", "$1 $2");					
		str = str.replaceAll("(\\u201C)([^'])", "$1 $2");    				
		str = str.replaceAll("([^'])(\\u201D)", "$1 $2");
		
    	str = str.replaceAll("\\,([^0-9])", "\\, $1"); 			                
		str = str.replaceAll("([^\\s]),([\\s])", "$1 , $2");	 			//abc,<blank> -> abc ,		
		str = str.replaceAll("([^\\s:/0-9])/([^\\s:/0-9])", "$1 / $2"); 	//exception : url http://..., date-time: 12/3/98
		str = str.replaceAll("([^\\s0-9]+)-"," $1 -"); 						//abc-xyz -> abc - xyz; exception 12-3 (date-time)
		str = str.replaceAll("-([^\\s0-9]+)","- $1");
		str = str.replaceAll("([^\\s]):([\\s])", "$1 : $2"); 				// abc:<blank> -> abc : 
	    str = str.replaceAll("([^\\s]):([^0-9]+)", "$1 : $2"); 				//abc:xyz --> abc : xyz; exception: 12:03
	    str = str.replaceAll("([^0-9]+):([^\\s])", "$1 : $2");
    	str = str.replaceAll(" -([^\\s]+)", " - $1");
    	
    	str = str.replaceAll("|", "");
    	str = str.replaceAll("[\u2026\u201C\u201D]", "");   
    	str = str.replaceAll("([^\\p{L}0-9\\.\\,:\\-/])", " $1 "); 			//tokenize all unknown characters
		str = str.replaceAll("[ \t]+", " ");
		str = str.replaceAll("^\\s+", "");	
		str = str.replaceAll("\\. \\.\\.", " ... ");
		str = str.trim();
		
		return str;
	}
417511
public static String escapeHTML(String s) {
    // this version is much faster than using s.replaceAll()
    StringBuilder sb = new StringBuilder();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      char c = s.charAt(i);
      switch (c) {
        case '<':
          sb.append("&lt;");
          break;
        case '>':
          sb.append("&gt;");
          break;
        case '&':
          sb.append("&amp;");
          break;
        case '"':
          sb.append("&quot;");
          break;
        default:
          sb.append(c);
          break;
      }
    }
    return sb.toString();
  }
289422
private String normalize(String str){
		str = StringUtils.trimToEmpty(str);
		str = StringUtils.normalizeSpace(str);

		// remove whitespace before punctuation. not using \p{Punct},
		// because it includes to many special characters.
		str = str.replaceAll("\\s+(?=[.!,\\?;:])", "");

		return str;
	}
799901
public static List<String> split(
                    final String str
                    )
    {
        String  s = str;
        if (s != null) {
            s = s.trim();
        }

        List<String>  list = new ArrayList<String>();
        if (s == null || s.length() == 0) {
            return list;
        }

        String[]  tokens = s.split( "[ \t\n\r\f]" );
        // NOTE: tokens[i] may be an empty string "".

        // excludes empty strings.
        int  n_tokens = tokens.length;
        for (int  i = 0; i < n_tokens; i++) {
            if (tokens[i].length() > 0) {
                list.add( tokens[i] );
            }
        }

        return list;
    }