public class StringUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
allCapsToSUMOID(String str) |
static String |
arrayListToSpacedString(ArrayList<String> al)
Convert an arbitrary string to a legal KIF identifier by
substituting dashes for illegal characters.
|
static String |
asSUMORelationID(String str) |
static String |
concatN(String input,
int n)
Returns a String formed from n concatenations of input.
|
static boolean |
containsNonAsciiChars(String str) |
static String |
decode(String input)
Returns a URL decoded String obtained from input, which is
assumed to be a URL encoded String composed of characters in
the default charset.
|
static boolean |
emptyString(Object s) |
static String |
encode(String input)
Returns a URL encoded String obtained from input, which is
assumed to be a String composed of characters in the default
charset.
|
static String |
encrypt(String input,
String charset)
Converts input, which is assumed to belong to charset, to a
base 64 representation, and then encrypts the result using the
SHA algorithm.
|
static String |
escapeEscapeChars(String str) |
static String |
escapeQuoteChars(String str) |
static String |
fillString(String st,
char fillchar,
int totalLength,
boolean prepend)
Fill a string with the desired character up to the totalLength.
|
static String |
filterHtml(String input)
Remove HTML from input string.
|
static int |
findBalancedParen(int pIndex,
String st)
Find the parenthesis that balances the one in st at character pIndex
|
static String |
fromBase64(String input,
String charset)
Given an input String encoded in base-64, decodes the String
and returns the original form of input in charset.
|
static String |
getCharset()
Returns a String denoting a character encoding scheme.
|
static String |
getContents(File aFile)
Fetch the entire contents of a text file, and return it in a String.
|
static String |
getDateTime(String pattern)
Returns a date/time string corresponding to pattern.
|
static String |
getKifNamespaceDelimiter()
Returns the string used in SUO-KIF to separate a namespace
prefix from the term it qualifies.
|
static String |
getLineSeparator()
Returns the default line separator token for the current
runtime platform.
|
static String |
getLocalReferenceBaseName() |
static String |
getSafeNamespaceDelimiter()
Returns a "safe" alphanumeric ASCII string that can be
substituted for the W3C or SUO-KIF string delimiting a
namespace prefix from an unqualified term name.
|
static String |
getW3cNamespaceDelimiter()
Returns the string preferred by W3C to separate a namespace
prefix from the term it qualifies.
|
static String |
indent(int num,
String indentChars) |
static boolean |
isDigitString(String input)
Returns true if every char in input is a digit char, else
returns false.
|
static boolean |
isLocalTermReference(String term) |
static boolean |
isNonEmptyString(Object obj) |
static boolean |
isNumeric(String input) |
static boolean |
isQuotedString(String input)
Returns true if input appears to be a quoted String, else
returns false.
|
static boolean |
isStringWithSpaces(String input)
Returns true if input is a String containing some whitespace
chars, else returns false.
|
static boolean |
isUri(String input)
Returns true if input appears to be a URI string, else returns
false.
|
static ArrayList |
kifListToArrayList(String kifListAsString)
Returns a new ArrayList formed by extracting in order the
top-level members of kifListAsString, which is assumed to be
the String representation of a SUO-KIF (LISP) list.
|
static String |
kifToW3c(String term) |
static void |
main(String[] args) |
static String |
makeQuotedString(String input,
char quoteChar)
Returns a new String formed by adding quoteChar to each end of
input.
|
static String |
normalizeSpaceChars(String str) |
static String |
quote(String input) |
static String |
removeEnclosingChar(String s,
int n,
char c)
Removes n layers of balanced ASCII double-quote characters from each
end of the String s, if any are present.
|
static String |
removeEnclosingCharPair(String s,
int n,
char c1,
char c2)
Removes n layers of balanced characters from each
end of the String s, if any are present.
|
static String |
removeEnclosingChars(String s,
int n,
char c)
Removes n layers of balanced characters from each
end of the String s, if any are present.
|
static String |
removeEnclosingQuotes(String s)
Removes all balanced ASCII double-quote characters from each
end of the String s, if any are present.
|
static String |
removeEscapedDoubleQuotes(String str) |
static String |
removeEscapedEscapes(String str) |
static String |
removeHTML(String sentence)
Remove HTML markup from a sentence.
|
static String |
removeInternalDoubleQuotes(String str) |
static String |
removePunctuation(String sentence)
Remove punctuation and contractions from a sentence.
|
static String |
removeQuoteEscapes(String str) |
static File |
renameFileIfExists(File f)
If the file f already exists, this method returns a new File
object with a unique name formed by appending an integer.
|
static String |
replaceDateTime(String input)
If the input String contains the sequence {date}pattern{date},
replaces the first occurrence of this sequence with a UTC
date/time string formatted according to pattern.
|
static String |
replaceNonAsciiChars(String str) |
static String |
replaceNonIdChars(String st)
Replace any character that isn't a valid KIF identifier
character with a lower-case x.
|
static String |
replaceRepeatedDoubleQuotes(String str) |
static String |
replaceUnsafeNamespaceDelimiters(String input)
Replaces non-alphanumeric namespace delimiters in input with an
alphanumeric form that can be handled by Vampire and other
provers.
|
static String |
safeToKifNamespaceDelimiters(String input)
Replaces all occurrences of the "safe" namespace delimiter in
input with the default KIF namespace delimiter, which might
contain characters that are not acceptable to some provers.
|
static void |
setCharset(String charEncoding)
Sets the default value of CHARSET to charEncoding.
|
static String |
setKifNamespaceDelimiter(String str)
Sets to str the String used in SUO-KIF to separate a namespace
prefix from the term it qualifies.
|
static void |
setLineSeparator(String separator)
Sets the default line separator token for the current runtime
platform.
|
static void |
setLocalReferenceBaseName(String basename) |
static String |
setSafeNamespaceDelimiter(String str)
Sets to str the "safe" alphanumeric ASCII String value that can
be substituted for the W3C or SUO-KIF string delimiting a
namespace prefix from an unqualified term name.
|
static String |
setW3cNamespaceDelimiter(String str)
Sets to str the String token preferred by W3C to separate a
namespace prefix from the term it qualifies.
|
static String |
stringToKIF(String input,
boolean upcaseFirst)
Convert any arbitrary string to a valid KIF id.
|
static String |
StringToKIFid(String s)
Convert an arbitrary string to a legal KIF identifier by
substituting dashes for illegal characters.
|
static String |
StringToPrologID(String s)
Convert an arbitrary string to a legal Prolog identifier by
substituting dashes for illegal characters.
|
static String |
toBase64(String input,
String charset)
Given an input String encoded in charset, returns a String
representing the base-64 encoding of the input.
|
static String |
toSafeNamespaceDelimiter(String term)
Replaces the namespace delimiter in term with a string that is
safe for inference, and for all common file systems.
|
static String |
toSafeNamespaceDelimiter(String kbHref,
String term)
Replaces the namespace delimiter in term with a string that is
safe for inference and for all common file systems, but only if
kbHref is an empty string or == null.
|
static String |
treeReplace(String oldPattern,
String newTerm,
String tree)
Performs a depth-first search of tree, replacing all terms
matching oldPattern with newTerm.
|
static String |
unquote(String input) |
static String |
w3cToKif(String term) |
static String |
wordWrap(String input)
Convenience method with default line length of 70
|
static String |
wordWrap(String input,
int length) |
public static void setCharset(String charEncoding)
charEncoding - A String denoting a character encoding schemepublic static String getCharset()
public static String encode(String input)
input - A String which has not yet been URL encodedpublic static String decode(String input)
input - A URL encoded Stringpublic static String getLineSeparator()
public static void setLineSeparator(String separator)
separator - The String to use as the line separatorpublic static String getKifNamespaceDelimiter()
public static String setKifNamespaceDelimiter(String str)
public static String getW3cNamespaceDelimiter()
public static String setW3cNamespaceDelimiter(String str)
public static String getSafeNamespaceDelimiter()
public static String setSafeNamespaceDelimiter(String str)
public static String toBase64(String input, String charset)
input - A Stringcharset - A String constant denoting a Charsetpublic static String fromBase64(String input, String charset)
input - A base-64 Stringcharset - A String constant denoting a Charset, such at UTF-8public static String encrypt(String input, String charset)
input - A String in charsetcharset - A String constant denoting a Charset, such at UTF-8public static boolean isNonEmptyString(Object obj)
obj - Any objectpublic static boolean emptyString(Object s)
s - An input Object, expected to be a String.public static String removeEnclosingQuotes(String s)
public static String removeEnclosingChar(String s, int n, char c)
public static String removeEnclosingChars(String s, int n, char c)
public static String removeEnclosingCharPair(String s, int n, char c1, char c2)
public static String removePunctuation(String sentence)
public static String normalizeSpaceChars(String str)
str - A Stringpublic static String arrayListToSpacedString(ArrayList<String> al)
public static String StringToKIFid(String s)
public static String StringToPrologID(String s)
public static String escapeQuoteChars(String str)
str - A Stringpublic static String escapeEscapeChars(String str)
str - A Stringpublic static String removeQuoteEscapes(String str)
str - A Stringpublic static String removeEscapedEscapes(String str)
str - A Stringpublic static String removeEscapedDoubleQuotes(String str)
str - A Stringpublic static String removeInternalDoubleQuotes(String str)
str - A Stringpublic static String replaceRepeatedDoubleQuotes(String str)
str - A Stringpublic static boolean containsNonAsciiChars(String str)
str - A Stringpublic static String replaceNonAsciiChars(String str)
str - A Stringpublic static String replaceNonIdChars(String st)
public static String getDateTime(String pattern)
pattern - Examples: yyyy, yyyy-MM-dd.public static String replaceDateTime(String input)
input - The input String into which a formatted date/time
will be insertedpublic static boolean isUri(String input)
input - A Stringpublic static boolean isStringWithSpaces(String input)
input - A Stringpublic static boolean isQuotedString(String input)
input - A Stringpublic static String makeQuotedString(String input, char quoteChar)
input - A Stringpublic static boolean isDigitString(String input)
input - A Stringpublic static boolean isNumeric(String input)
public static String concatN(String input, int n)
input - A Stringn - A non-negative intpublic static String treeReplace(String oldPattern, String newTerm, String tree)
oldPattern - A regular expression pattern to be matched
against terms in treenewTerm - A String to replace terms matching oldPatterntree - A String representing a SUO-KIF Formula (list)public static ArrayList kifListToArrayList(String kifListAsString)
kifListAsString - A SUO-KIF list represented as a Stringpublic static String replaceUnsafeNamespaceDelimiters(String input)
input - The String representation of a SUO-KIF Formula or
other expressionpublic static String safeToKifNamespaceDelimiters(String input)
input - The String representation of a SUO-KIF Formula or
other expression, such as a TPTP Formulapublic static String toSafeNamespaceDelimiter(String term)
public static String toSafeNamespaceDelimiter(String kbHref, String term)
public static boolean isLocalTermReference(String term)
public static String getLocalReferenceBaseName()
public static void setLocalReferenceBaseName(String basename)
public static File renameFileIfExists(File f)
f - A Filepublic static String wordWrap(String input)
public static String stringToKIF(String input, boolean upcaseFirst)
public static int findBalancedParen(int pIndex,
String st)
public static String fillString(String st, char fillchar, int totalLength, boolean prepend)
public static void main(String[] args)
public static String getContents(File aFile)
aFile - is a file which already exists and can be read.Copyright © 2015. All rights reserved.