Package org.w3c.tidy
Class TidyUtils
java.lang.Object
org.w3c.tidy.TidyUtils
Utility class with handy methods, mainly for String handling or for reproducing c behaviours.
- Version:
- $Revision $ ($Author $)
- Author:
- Fabrizio Giustina
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanfindBadSubString(String s, String p, int len) Return true if substring s is in p and isn't all in upper case.static charfoldCase(char c, boolean tocaps, boolean xmlTags) Fold case of a char.static byte[]Should always be able convert to/from UTF-8, so encoding exceptions are converted to an Error to avoid adding throws declarations in lots of methods.static StringgetString(byte[] bytes, int offset, int length) Should always be able convert to/from UTF-8, so encoding exceptions are converted to an Error to avoid adding throws declarations in lots of methods.static booleanIs the given character encoding supported?static booleanisDigit(char c) Is the given char a digit?static booleanisLetter(char c) Is the given char a letter?static booleanisLower(char c) Determines if the specified character is a lowercase character.static booleanisNamechar(char c) Is the given char valid in name? (letter, digit or "-", ".", ":", "_")static booleanisUpper(char c) Determines if the specified character is a uppercase character.static booleanisWhite(char c) Determines if the specified character is whitespace.static intReturn the last char in string.static chartoLower(char c) Maps the given character to its lowercase equivalent.static chartoUpper(char c) Maps the given character to its uppercase equivalent.
-
Method Details
-
findBadSubString
Return true if substring s is in p and isn't all in upper case. This is used to check the case of SYSTEM, PUBLIC, DTD and EN.- Parameters:
s- substringp- full stringlen- how many chars to check in p- Returns:
- true if substring s is in p and isn't all in upper case
-
getBytes
Should always be able convert to/from UTF-8, so encoding exceptions are converted to an Error to avoid adding throws declarations in lots of methods.- Parameters:
str- String- Returns:
- utf8 bytes
- See Also:
-
getString
Should always be able convert to/from UTF-8, so encoding exceptions are converted to an Error to avoid adding throws declarations in lots of methods.- Parameters:
bytes- byte arrayoffset- starting offset in byte arraylength- length in byte array starting from offset- Returns:
- same as
new String(bytes, offset, length, "UTF8")
-
lastChar
Return the last char in string. This is useful when trailing quotemark is missing on an attribute- Parameters:
str- String- Returns:
- last char in String
-
isWhite
public static boolean isWhite(char c) Determines if the specified character is whitespace.- Parameters:
c- char- Returns:
trueif char is whitespace.
-
isDigit
public static boolean isDigit(char c) Is the given char a digit?- Parameters:
c- char- Returns:
trueif the given char is a digit
-
isLetter
public static boolean isLetter(char c) Is the given char a letter?- Parameters:
c- char- Returns:
trueif the given char is a letter
-
isNamechar
public static boolean isNamechar(char c) Is the given char valid in name? (letter, digit or "-", ".", ":", "_")- Parameters:
c- char- Returns:
trueif char is a name char.
-
isLower
public static boolean isLower(char c) Determines if the specified character is a lowercase character.- Parameters:
c- char- Returns:
trueif char is lower case.
-
isUpper
public static boolean isUpper(char c) Determines if the specified character is a uppercase character.- Parameters:
c- char- Returns:
trueif char is upper case.
-
toLower
public static char toLower(char c) Maps the given character to its lowercase equivalent.- Parameters:
c- char- Returns:
- lowercase char.
-
toUpper
public static char toUpper(char c) Maps the given character to its uppercase equivalent.- Parameters:
c- char- Returns:
- uppercase char.
-
foldCase
public static char foldCase(char c, boolean tocaps, boolean xmlTags) Fold case of a char.- Parameters:
c- chartocaps- convert to capsxmlTags- use xml tags? If true no change will be performed- Returns:
- folded char
- To Do:
- check the use of xmlTags parameter
-
isCharEncodingSupported
Is the given character encoding supported?- Parameters:
name- character encoding name- Returns:
trueif encoding is supported, false otherwhise.
-