Java HTML htmlSize(String str)

Here you can find the source of htmlSize(String str)

Description

retreive the size of a String with html code.

License

LGPL

Parameter

Parameter Description
str the string

Return

the size of the String;

Declaration

public static int htmlSize(String str) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from w  w w  .ja  v a2s  .c  o m*/
      * retreive the size of a String with html code. sample: "aaa´" = 4.
      * 
      * @param str
      *            the string
      * @return the size of the String;
      */
    public static int htmlSize(String str) {
        int c = 0;
        int cInCode = 0;
        boolean inHTMLCode = false;
        for (int i = 0; i < str.length(); i++) {
            if (!inHTMLCode) {
                if (str.charAt(i) == '&') {
                    inHTMLCode = true;
                    cInCode++;
                } else {
                    c++;
                }
            } else {
                cInCode++;
                if (str.charAt(i) == ';') {
                    inHTMLCode = false;
                    c++;
                    cInCode = 0;
                } else if (str.charAt(i) == '&') {
                    c = c + cInCode;
                    cInCode = 0;
                }
            }
        }
        c = c + cInCode;
        return c;
    }
}

Related

  1. htmlLineBreaks(String s)
  2. htmlLink(String url, String linkName)
  3. htmlNewline(String text)
  4. htmlSafe(String field)
  5. htmlSafe(String value)
  6. htmlString(String str)
  7. htmlText(String text)
  8. HTMLtoRGB(String htmlColor)
  9. HTMLToTriplet(String color)