|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mailster.util.StringUtilities
public class StringUtilities
---
Mailster (C) 2007-2009 De Oliveira Edouard
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
See Mailster
Web Site
---
StringUtilities.java - Various methods to handle strings.
| Field Summary | |
|---|---|
static java.lang.String |
EMPTY_STRING
Constant for the empty String |
| Constructor Summary | |
|---|---|
StringUtilities()
|
|
| Method Summary | |
|---|---|
private static void |
extractDirective(java.util.HashMap<java.lang.String,java.lang.String> map,
java.lang.String key,
java.lang.String value)
Processes directive/value pairs from the digest-challenge and fill out the provided map. |
static java.lang.String |
intToFixedLengthHex(int value,
int length)
Takes value and return its HEX value prefixed with zeros . |
static boolean |
isEmpty(java.lang.String str)
Tests if the given String is empty. |
static boolean |
isLws(byte b)
Is character a linear white space ? |
static int |
occ(java.lang.String s,
char c,
int start,
int length)
Returns the occurence count of char c in a substring of the String
s starting at position start and containing
length chars. |
static java.util.HashMap<java.lang.String,java.lang.String> |
parseDirectives(byte[] buf)
Parses digest-challenge string, extracting each token and value(s) |
static java.lang.String |
replace(java.lang.String text,
java.lang.String repl,
java.lang.String with)
Replaces all occurrences of a String within another String. |
static java.lang.String |
replace(java.lang.String text,
java.lang.String repl,
java.lang.String with,
int max)
Replaces a String with another String inside a larger String, for the first max values of the search String. |
private static int |
skipLws(byte[] buf,
int start)
Skip all linear white spaces |
static java.lang.String[] |
split(java.lang.String s)
Split a String into an array of String[]
using the space character as token. |
static java.lang.String[] |
split(java.lang.String s,
java.lang.String token)
Split a String into an array of String[]. |
static java.lang.String |
stringTo_8859_1(java.lang.String str,
boolean useUTF8)
Used to convert username-value, passwd or realm to 8859_1 encoding if all chars in string are within the 8859_1 (Latin 1) encoding range. |
static java.lang.String |
strip(java.lang.String str)
Strips whitespace from the start and end of a String. |
static java.lang.String |
strip(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the start and end of a String. |
static java.lang.String |
stripEnd(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the end of a String. |
static java.lang.String |
stripStart(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the start of a String. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String EMPTY_STRING
String
| Constructor Detail |
|---|
public StringUtilities()
| Method Detail |
|---|
public static boolean isEmpty(java.lang.String str)
String is empty. A String
object is considered empty if it is either null or its
trimmed length is zero.
str - the String to test
true if the given String is empty;
false otherwisepublic static java.lang.String[] split(java.lang.String s)
String into an array of String[]
using the space character as token.
s - the string to split
public static java.lang.String[] split(java.lang.String s,
java.lang.String token)
String into an array of String[].
s - the string to splittoken - the character token
public static java.lang.String intToFixedLengthHex(int value,
int length)
value and return its HEX value prefixed with zeros .
value - the value to be convertedlength - the length to pad to.
public static java.lang.String stringTo_8859_1(java.lang.String str,
boolean useUTF8)
throws AuthException
str - a non-null StringuseUTF8 - a boolean value set to true if UT8 is in use.
AuthException
public static int occ(java.lang.String s,
char c,
int start,
int length)
c in a substring of the String
s starting at position start and containing
length chars.
s - the string to parsec - the character to search for
public static java.util.HashMap<java.lang.String,java.lang.String> parseDirectives(byte[] buf)
throws javax.security.sasl.SaslException
buf - A non-null digest-challenge string.
java.io.UnsupportedEncodingException
javax.security.sasl.SaslException - if the String cannot be parsed according to RFC 2831
private static void extractDirective(java.util.HashMap<java.lang.String,java.lang.String> map,
java.lang.String key,
java.lang.String value)
throws javax.security.sasl.SaslException
key - A non-null String challenge token name.value - A non-null String token value.
javax.security.sasl.SaslException - if either the key or the value is null or
if the key already has a value.public static boolean isLws(byte b)
b - the byte to check
true if it's a linear white space
private static int skipLws(byte[] buf,
int start)
public static java.lang.String replace(java.lang.String text,
java.lang.String repl,
java.lang.String with)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null
StringUtils.replace("", *, *) = ""
StringUtils.replace("any", null, *) = "any"
StringUtils.replace("any", *, null) = "any"
StringUtils.replace("any", "", *) = "any"
StringUtils.replace("aba", "a", null) = "aba"
StringUtils.replace("aba", "a", "") = "b"
StringUtils.replace("aba", "a", "z") = "zbz"
text - text to search and replace in, may be nullrepl - the String to search for, may be nullwith - the String to replace with, may be null
null if null String inputreplace(String text, String repl, String with, int max)
public static java.lang.String replace(java.lang.String text,
java.lang.String repl,
java.lang.String with,
int max)
Replaces a String with another String inside a larger String,
for the first max values of the search String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *, *) = null
StringUtils.replace("", *, *, *) = ""
StringUtils.replace("any", null, *, *) = "any"
StringUtils.replace("any", *, null, *) = "any"
StringUtils.replace("any", "", *, *) = "any"
StringUtils.replace("any", *, *, 0) = "any"
StringUtils.replace("abaa", "a", null, -1) = "abaa"
StringUtils.replace("abaa", "a", "", -1) = "b"
StringUtils.replace("abaa", "a", "z", 0) = "abaa"
StringUtils.replace("abaa", "a", "z", 1) = "zbaa"
StringUtils.replace("abaa", "a", "z", 2) = "zbza"
StringUtils.replace("abaa", "a", "z", -1) = "zbzz"
text - text to search and replace in, may be nullrepl - the String to search for, may be nullwith - the String to replace with, may be nullmax - maximum number of values to replace, or -1 if no maximum
null if null String inputpublic static java.lang.String strip(java.lang.String str)
Strips whitespace from the start and end of a String.
This is similar to String.trim() but removes whitespace.
Whitespace is defined by Character.isWhitespace(char).
A null input String returns null.
StringUtils.strip(null) = null
StringUtils.strip("") = ""
StringUtils.strip(" ") = ""
StringUtils.strip("abc") = "abc"
StringUtils.strip(" abc") = "abc"
StringUtils.strip("abc ") = "abc"
StringUtils.strip(" abc ") = "abc"
StringUtils.strip(" ab c ") = "ab c"
str - the String to remove whitespace from, may be null
null if null String input
public static java.lang.String strip(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the start and end of a String.
This is similar to String.trim() but allows the characters
to be stripped to be controlled.
A null input String returns null.
An empty string ("") input returns the empty string.
If the stripChars String is null, whitespace is
stripped as defined by Character.isWhitespace(char).
Alternatively use strip(String).
StringUtils.strip(null, *) = null
StringUtils.strip("", *) = ""
StringUtils.strip("abc", null) = "abc"
StringUtils.strip(" abc", null) = "abc"
StringUtils.strip("abc ", null) = "abc"
StringUtils.strip(" abc ", null) = "abc"
StringUtils.strip(" abcyx", "xyz") = " abc"
str - the String to remove characters from, may be nullstripChars - the characters to remove, null treated as whitespace
null if null String input
public static java.lang.String stripStart(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the start of a String.
A null input String returns null.
An empty string ("") input returns the empty string.
If the stripChars String is null, whitespace is
stripped as defined by Character.isWhitespace(char).
StringUtils.stripStart(null, *) = null
StringUtils.stripStart("", *) = ""
StringUtils.stripStart("abc", "") = "abc"
StringUtils.stripStart("abc", null) = "abc"
StringUtils.stripStart(" abc", null) = "abc"
StringUtils.stripStart("abc ", null) = "abc "
StringUtils.stripStart(" abc ", null) = "abc "
StringUtils.stripStart("yxabc ", "xyz") = "abc "
str - the String to remove characters from, may be nullstripChars - the characters to remove, null treated as whitespace
null if null String input
public static java.lang.String stripEnd(java.lang.String str,
java.lang.String stripChars)
Strips any of a set of characters from the end of a String.
A null input String returns null.
An empty string ("") input returns the empty string.
If the stripChars String is null, whitespace is
stripped as defined by Character.isWhitespace(char).
StringUtils.stripEnd(null, *) = null
StringUtils.stripEnd("", *) = ""
StringUtils.stripEnd("abc", "") = "abc"
StringUtils.stripEnd("abc", null) = "abc"
StringUtils.stripEnd(" abc", null) = " abc"
StringUtils.stripEnd("abc ", null) = "abc"
StringUtils.stripEnd(" abc ", null) = " abc"
StringUtils.stripEnd(" abcyx", "xyz") = " abc"
str - the String to remove characters from, may be nullstripChars - the characters to remove, null treated as whitespace
null if null String input
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||