Class StringUtil
java.lang.Object
org.eclipse.birt.report.model.api.util.StringUtil
Collection of string utilities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildQualifiedReference(String namespace, String value) Builds the qualified reference value.static StringdoubleToString(double d, int fNumber) Converts the double value to locale-independent string representation.static StringdoubleToString(double d, int fNumber, com.ibm.icu.util.ULocale locale) Converts the double value to locale-dependent string representation.static StringextractFileName(String filePathName) Extract file name (without path and suffix) from file name with path and suffix.static StringextractFileNameWithSuffix(String filePathName) Extract file name (without path but with suffix) from file name with path and suffix.static StringextractName(String qualifiedName) Extracts the name from the given qualified reference value.static StringextractNamespace(String qualifiedName) Extracts the libaray namespace from the given qualified reference value.static booleanReports if a string is blank.static booleanReports if a string is empty.static booleanReturns if the two string are null or equal.static booleanisEqualIgnoreCase(String str1, String str2) Returns if the two string are null or equal.static booleanisValidLocale(String locale) Check if the locale string is a valid locale format, with the language, country and variant separated by underbars.static DimensionValueParses a dimension string in locale-independent way.static DimensionValueparseInput(String value, com.ibm.icu.util.ULocale locale) Parses a dimension string in locale-dependent way.static StringtoRgbText(int rgb) Convert an integer to an HTML RGB value.static StringtrimQuotes(String value) Trims the quotes.static StringtrimString(String value) Trim a string.
-
Field Details
-
EMPTY_STRING
- See Also:
-
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
trimString
Trim a string. Removes leading and trailing blanks. If the resulting string is empty, normalizes the string to an null string.- Parameters:
value- the string to trim- Returns:
- the trimmed string, or null if the string is empty
-
toRgbText
Convert an integer to an HTML RGB value. The result is of the form #hhhhhh. The input rgb integer value will be clipped into the range 0 ~ 0xFFFFFF- Parameters:
rgb- the integer RGB value- Returns:
- the value as an HTML RGB string
-
isValidLocale
Check if the locale string is a valid locale format, with the language, country and variant separated by underbars.The language argument is a valid ISO Language Code. . These codes are the lower-case, two-letter codes.
The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes.
If the language is missing, the string should begin with an underbar. (Can't have a locale with just a variant -- the variant must accompany a valid language or country code). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"
- Parameters:
locale- string representing a locale- Returns:
- true if the locale is a valid locale, false if the locale is not valid.
-
isBlank
Reports if a string is blank. A string is considered blank either if it is null, is an empty string, of consists entirely of white space.For example,
- null, "" and " " are blank strings
- Parameters:
str- the string to check- Returns:
- true if the string is blank, false otherwise.
-
isEmpty
Reports if a string is empty. A string is considered empty either if it is null, is an empty string.For example,
- Both null and "" are empty strings
- " " is not empty string.
- Parameters:
value- the string to check- Returns:
- true if the string is empty, false otherwise.
-
isEqual
Returns if the two string are null or equal. TheString.equals(String)is used to compare two strings.- Parameters:
str1- the string to comparestr2- the string to compare- Returns:
- true, if the two string are null, or the two string are equal with case sensitive.
-
isEqualIgnoreCase
Returns if the two string are null or equal. TheString.equalsIgnoreCase(String)is used to compare two strings.- Parameters:
str1- the string to comparestr2- the string to compare- Returns:
- true, if the two string are null, or the two string are equal with case sensitive.
-
doubleToString
Converts the double value to locale-independent string representation. This method works likeDouble.toString( double ), and can also handle very large number like 1.234567890E16 to "12345678900000000".- Parameters:
d- the double value to convertfNumber- the positive maximum fractional number- Returns:
- the locale-independent string representation.
-
doubleToString
Converts the double value to locale-dependent string representation.- Parameters:
d- the double value to convertfNumber- the positive maximum fractional numberlocale-- Returns:
- the locale-dependent string representation.
-
parse
Parses a dimension string in locale-independent way. The input string must match the following:- null
- [1-9][0-9]*[.[0-9]*[ ]*[in|cm|mm|pt|pc|em|ex|px|%]]
- Parameters:
value- the dimension string to parse- Returns:
- a dimension object representing the dimension string.
- Throws:
PropertyValueException- if the string is not valid
-
parseInput
public static DimensionValue parseInput(String value, com.ibm.icu.util.ULocale locale) throws PropertyValueException Parses a dimension string in locale-dependent way. The input can be in localized value. The measure part use the decimal separator from the locale. e,g. "123,456.78" for English ; "123.456,78" for German.The string must match the following:
- null
- [1-9][0-9]*[.[0-9]*[ ]*[u]], u is the one of the allowed units
- Parameters:
value- the string to parselocale- the locale where the input string resides- Returns:
- a dimension object
- Throws:
PropertyValueException- if the string is not valid
-
extractFileName
Extract file name (without path and suffix) from file name with path and suffix.For example:
- "c:\home\abc.xml" => "abc"
- "c:\home\abc" => "abc"
- "/home/user/abc.xml" => "abc"
- "/home/user/abc" => "abc"
- Parameters:
filePathName- the file name with path and suffix- Returns:
- the file name without path and suffix
-
extractFileNameWithSuffix
Extract file name (without path but with suffix) from file name with path and suffix.For example:
- "c:\home\abc.xml" => "abc.xml"
- "c:\home\abc" => "abc"
- "/home/user/abc.xml" => "abc.xml"
- "/home/user/abc" => "abc"
- Parameters:
filePathName- the file name with path and suffix- Returns:
- the file name without path but with suffix
-
extractNamespace
Extracts the libaray namespace from the given qualified reference value.For example,
- "LibA" is extracted from "LibA.style1"
- null is returned from "style1"
- Parameters:
qualifiedName- the qualified reference value- Returns:
- the library namespace
-
extractName
Extracts the name from the given qualified reference value.For example,
- "style1" is extracted from "LibA.style1"
- "style1" is returned from "style1"
- Parameters:
qualifiedName- the qualified reference value- Returns:
- the name
-
buildQualifiedReference
Builds the qualified reference value.For example,
- ("LibA", "style1") => "LibA.style1"
- (" ", "style1) => "style1"
- Parameters:
namespace- the library namespace to indicate which library the reference is using.value- the actual reference value- Returns:
- the qualified reference value
-
trimQuotes
Trims the quotes.For example,
- ("a.b") => a.b
- ("a.b) => "a.b
- (a.b") => a.b"
- Parameters:
value- the string may have quotes- Returns:
- the string without quotes
-