NameRectifierpublic class NameRectifier extends Object implements MusicMetadataConstants
Fields Summary |
---|
private static final String[] | DEFAULTS | private static final String[] | DEFAULTS_VA | private static final String[] | DEFAULTS_SOUNDTRACK | private static final String | DEFAULT_ACAPELLA | private static final String | ROMAN_NUMERALS | private static final Map | natural_numbers | private static final String[] | PATTERNS_ALBUM | private static final String[] | PATTERNS_ARTIST | private static final String[] | FEATURING | private static final String | ESCAPED | private static final RegExCache | regex_cache |
Methods Summary |
---|
private java.lang.String | clean(java.lang.String s, java.util.Map flags)
// String old_s = s;
s = s.trim();
s = Diacriticals.convertDiacriticals(s);
while (s.startsWith("-"))
s = s.substring(1);
s = removeSafePrefixSuffix(s, DEFAULTS);
if (s == null)
return null;
{
final String kDISC_REGEXS[] = {
"[-\\(\\[] ?dis[ck] ?([a-zA-Z\\d]+)[\\)\\]]?$", //
"[-\\(\\[] ?cd ?([a-zA-Z\\d]+)[\\)\\]]?$", //
"^[\\(\\[]?dis[ck] ?([a-zA-Z\\d]+) ?[-\\)\\]]", //
"^[\\(\\[]?cd ?([a-zA-Z\\d]+) ?[-\\)\\]]", //
"^dis[ck] ?([a-zA-Z\\d]+)$", //
"^cd[\\. \\-]*([a-zA-Z\\d]+)$", //
};
for (int i = 0; i < kDISC_REGEXS.length; i++)
{
String kDISC_REGEX = kDISC_REGEXS[i];
RE re = new RE(kDISC_REGEX);
if (re.match(s.toLowerCase()))
{
if (re.getParenCount() < 2)
{
continue;
}
int start = re.getParenStart(0);
int end = re.getParenEnd(0);
String value = re.getParen(1);
Number number = parseNumber(value);
if (number == null)
{
continue;
}
String fixed = s.substring(0, start) + s.substring(end);
if (flags != null)
flags.put(KEY_DISC_NUMBER, number);
s = fixed.trim();
// return null;
}
}
}
String suffixes[] = {
" ", //
"-", //
".Mp3", //
" Mp3", //
};
s = removeSuffixes(s, suffixes);
String prefixes[] = {
" ", //
"-", //
};
s = removePrefixes(s, prefixes);
// {
// final String suffixes[] = {
// " ", ".", "-", "Gabba Cc", "GABBA_CC", "G A B B A C C",
// "mp3-link", "Mp3 - Link", ".mp3",
// };
//
// s = this.removeSuffixes(s, suffixes);
// }
s = s.replace('_", ' ");
s = TextUtils.replace(s, "-", " - ");
s = TextUtils.replace(s, "`", "'");
s = TextUtils.replace(s, "�", "'");
s = TextUtils.replace(s, "�", "'");
s = TextUtils.replace(s, "[", "(");
s = TextUtils.replace(s, "]", ")");
s = TextUtils.replace(s, "(", " (");
s = TextUtils.replace(s, "~", "-");
s = TextUtils.replace(s, " ", " ");
s = TextUtils.replace(s, " ", " ");
s = TextUtils.replace(s, "..", ".");
s = TextUtils.replace(s, "--", "-");
s = TextUtils.replace(s, "- -", "-");
s = TextUtils.replace(s, "#", "No. ");
{
String old = s;
s = removeSafePrefixSuffix(s, DEFAULTS_SOUNDTRACK, true);
if (s == null || !s.equals(old))
{
if (flags != null)
{
flags.put(KEY_SOUNDTRACK, Boolean.TRUE);
// flags.put(KEY_COMPILATION, Boolean.TRUE);
}
}
if (s == null)
return null;
}
{
String temp = removeSafePrefixSuffix(s, DEFAULT_ACAPELLA, true);
// String temp = removeSafePrefixSuffix(s, kDEFAULTS_acapella);
if (temp == null || !s.equals(temp))
{
if (flags != null)
flags.put(KEY_ACAPELLA, Boolean.TRUE);
}
}
{
String old = s;
s = removeSafePrefixSuffix(s, DEFAULTS_VA, true);
if (s == null || !s.equals(old))
{
if (flags != null)
flags.put(KEY_COMPILATION, Boolean.TRUE);
}
if (s == null)
return null;
}
{
String splits[] = TextUtils.split(s, " ");
for (int i = 0; i < splits.length; i++)
{
if (isRomanNumeral(splits[i]))
splits[i] = splits[i].toUpperCase();
}
s = TextUtils.join(splits, " ");
}
s = s.trim();
// if (s == null)
// return null;
// s = insertSpacesBeforeCaps(s);
s = toTitleCase(s);
return s;
| private java.util.Vector | debugRE(org.apache.regexp.RE re)
Vector result = new Vector();
int count = re.getParenCount();
for (int i = 0; i < count; i++)
{
String child = re.getParen(i);
result.add(child);
}
return result;
| private java.lang.String | discardMatches(java.lang.String s, java.lang.String[] patterns)
if (s == null)
return null;
for (int i = 0; i < patterns.length; i++)
{
String prefix = patterns[i];
if (s.equalsIgnoreCase(prefix))
return null;
}
return s;
| private java.lang.String | extractRegexPattern(java.lang.String s, java.lang.String pattern, int paren)
if (s == null)
return null;
try
{
RE re = regex_cache.getRegEx(pattern);
// RE re = new RE(pattern.toLowerCase());
if (!re.match(s.toLowerCase()))
return s;
if (paren < re.getParenCount())
{
s = re.getParen(paren);
}
return s;
}
catch (Exception e)
{
return s;
}
| public java.lang.String | getPrefixPattern(java.lang.String s, boolean permissive)
return "^('" + s + "'|\\\"" + s + "\\\"|\\[" + s + "\\]|\\(" + s
+ "\\)|\\{" + s + "\\}|" + s + "\\-"
+ (permissive ? "|" + s + " " : "") + ")";
// return ("^[" + kREGEX_OPEN_TOKENS + "]?" + s + " ?["
// + (permissive ? " " : "") + "\\-" + kREGEX_CLOSE_TOKENS + "]");
| public java.lang.String | getPrefixPattern2(java.lang.String s)
return "^('.*'|\\\".*\\\"|\\[.*\\]|\\(.*\\)|\\{.*\\}|.*\\-) ?" + s
+ "$";
// return ("^[" + kREGEX_OPEN_TOKENS + "]?" + "(.*)" + " ?["
// // + (permissive ? " " : "")
// + "\\-" + kREGEX_CLOSE_TOKENS + "] ?" + s + "$");
| public java.lang.String | getSuffixPattern(java.lang.String s, boolean permissive)
return "('" + s + "'|\\\"" + s + "\\\"|\\[" + s + "\\]|\\(" + s
+ "\\)|\\{" + s + "\\}|\\-" + s + ""
+ (permissive ? "| " + s : "") + ")$";
// return ("[" + (permissive ? " " : "") + "\\-" + kREGEX_OPEN_TOKENS
// + "] ?" + s + "[" + kREGEX_CLOSE_TOKENS + "]?$");
| public java.lang.String | getSuffixPattern2(java.lang.String s)
return "^" + s
+ " ?('.*'|\\\".*\\\"|\\[.*\\]|\\(.*\\)|\\{.*\\}|\\-.*)$";
// return ("^" + s + " ?["
// // + (permissive ? " " : "")
// + "\\-" + kREGEX_OPEN_TOKENS + "] ?" + "(.*)" + "["
// + kREGEX_CLOSE_TOKENS + "]?$");
| private java.lang.String | insertSpacesBeforeCaps(java.lang.String s)
StringBuffer result = new StringBuffer();
char prev = 0;
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if (Character.isLetter(c) && (i > 0) && Character.isLetter(prev)
&& Character.isLowerCase(prev) && Character.isUpperCase(c))
result.append(' ");
result.append(c);
prev = c;
}
return result.toString();
| private boolean | isRomanNumeral(java.lang.String s)
char chars[] = s.toCharArray();
for (int i = 0; i < chars.length; i++)
{
char c = chars[i];
if (ROMAN_NUMERALS.indexOf(c) < 0
&& ROMAN_NUMERALS.toUpperCase().indexOf(c) < 0)
return false;
}
return true;
| private java.util.Vector | listToNames(org.apache.regexp.RE re)
Vector result = new Vector();
int count = re.getParenCount();
for (int i = 0; i < count / 2; i++)
{
String child = re.getParen(i * 2 + 1);
child = rectifyArtist(child);
result.remove(child);
result.add(child);
}
return result;
| private java.lang.Number | parseNumber(java.lang.String s)
natural_numbers.put("zero", new Integer(0));
natural_numbers.put("one", new Integer(1));
natural_numbers.put("two", new Integer(2));
natural_numbers.put("three", new Integer(3));
natural_numbers.put("four", new Integer(4));
natural_numbers.put("five", new Integer(5));
natural_numbers.put("six", new Integer(6));
natural_numbers.put("seven", new Integer(7));
natural_numbers.put("eight", new Integer(8));
natural_numbers.put("nine", new Integer(9));
natural_numbers.put("ten", new Integer(10));
natural_numbers.put("eleven", new Integer(11));
natural_numbers.put("twelve", new Integer(12));
natural_numbers.put("thirteen", new Integer(13));
natural_numbers.put("fourteen", new Integer(14));
natural_numbers.put("fifteen", new Integer(15));
natural_numbers.put("sixteen", new Integer(16));
natural_numbers.put("seventeen", new Integer(17));
natural_numbers.put("eighteen", new Integer(18));
natural_numbers.put("nineteen", new Integer(19));
natural_numbers.put("twenty", new Integer(20));
if (s == null)
return null;
s = s.trim();
if (s.length() < 1)
return null;
try
{
return Integer.valueOf(s.trim());
}
catch (Throwable e)
{
}
Number value = (Number) natural_numbers.get(s.toLowerCase());
return value;
| private void | parseTrackNumber(java.lang.String s, java.util.Map flags)
if (flags == null)
return;
try
{
s = s.trim();
Number number = new Integer(s);
if (flags != null)
flags.put(KEY_TRACK_NUMBER, number);
}
catch (NumberFormatException e)
{
}
catch (Throwable e)
{
}
| public java.lang.String | processFeaturing(java.lang.String s, java.util.Vector primary_artists, java.util.Vector featured_artists, java.lang.String pattern)
if (s == null)
return null;
RE re = new RE(pattern);
if (re.match(s.toLowerCase()))
{
// String wholeExpr = re.getParen(0);
// String insideParens = re.getParen(1);
int startInside = re.getParenStart(1);
int endInside = re.getParenEnd(1);
String left = s.substring(0, startInside);
String right = s.substring(startInside, endInside);
// int pattern_length = TextUtils.replace(pattern. "\\", "\");
int index = Integer.MAX_VALUE;
right = right.trim();
{
int i = right.indexOf('.");
if (i >= 0)
index = Math.min(index, i);
}
{
int i = right.indexOf(' ");
if (i >= 0)
index = Math.min(index, i);
}
if (index < 0)
{
return s;
}
right = right.substring(index + 1);
if (right.endsWith(")"))
right = right.substring(0, right.length() - 1);
if (left.endsWith("("))
left = left.substring(0, left.length() - 1);
right = right.trim();
RE re2 = new RE("(.*)(,.*)*\\&(.*)");
if (re2.match(right))
{
Vector v = listToNames(re2);
featured_artists.removeAll(v);
featured_artists.addAll(v);
}
else
{
re2 = new RE("(.*)(,.*)*\\ And (.*)");
if (re2.match(right))
{
Vector v = listToNames(re2);
featured_artists.removeAll(v);
featured_artists.addAll(v);
}
else
{
right = rectifyArtist(right);
featured_artists.remove(right);
featured_artists.add(right);
}
}
s = rectifyArtist(left);
}
return s;
| public void | processFeaturing(java.lang.String s, java.util.Vector primary_artists, java.util.Vector featured_artists)
for (int i = 0; i < FEATURING.length; i++)
{
String regex = "\\((" + FEATURING[i] + ".*)\\)$";
s = processFeaturing(s, primary_artists, featured_artists, regex);
}
for (int i = 0; i < FEATURING.length; i++)
{
String regex = "( " + FEATURING[i] + ".*$)";
s = processFeaturing(s, primary_artists, featured_artists, regex);
}
if (primary_artists == null)
return;
s = rectifyArtist(s);
primary_artists.remove(s);
primary_artists.add(s);
| public java.lang.String | rectifyAlbum(java.lang.String s)
return rectifyAlbum(
// null,
s, null);
| public java.lang.String | rectifyAlbum(java.lang.String s, java.util.Map flags)
String old = s;
while (true)
{
s = rectifyAlbum_1(s, flags);
if (s == null)
return null;
// if (artist != null)
// {
// if (s.startsWith(artist.name + " - "))
// s = s.substring(artist.name.length() + 3);
// if (s.endsWith(" - " + artist.name))
// s = s.substring(0, s.length() - (artist.name.length() + 3));
// }
if (s.equals(old))
return s;
old = s;
}
| public java.lang.String | rectifyAlbum_1(java.lang.String s, java.util.Map flags)
Arrays.sort(PATTERNS_ARTIST, MyComparator.kToStringLengthReverse);
s = rectifyGeneric_1(s, flags);
if (s == null)
return null;
s = removeSafePrefixSuffix(s, PATTERNS_ALBUM);
if (s == null)
return null;
if (s.endsWith(" Box Set"))
{
if (flags != null)
flags.put(KEY_COMPILATION, Boolean.TRUE);
}
s = removeYearPrefixSuffix(s);
s = removeURLs(s);
s = removeQuotes(s);
{
String old = s;
s = removeSafePrefixSuffix(s, DEFAULT_ACAPELLA, true);
// s = removeSafePrefixSuffix(s, kDEFAULTS_acapella);
if (s == null || !s.equals(old))
{
if (flags != null)
{
flags.put(KEY_ACAPELLA, Boolean.TRUE);
// flags.put(KEY_COMPILATION, Boolean.TRUE);
}
}
if (s == null)
return null;
}
if (s.endsWith(" !"))
s = s.substring(0, s.length() - 2);
else if (s.endsWith(" (!)"))
s = s.substring(0, s.length() - 4);
return s;
| public java.lang.String | rectifyArtist(java.lang.String s)
return rectifyArtist(s, null);
| public java.lang.String | rectifyArtist(java.lang.String s, java.util.Map flags)
String old = s;
while (true)
{
s = rectifyArtist_1(s, flags);
if (s == null)
return null;
// s = removeTrackNumbers(s);
if (s.equals(old))
return s;
old = s;
}
| private java.lang.String | rectifyArtist_1(java.lang.String s, java.util.Map flags)
s = rectifyGeneric_1(s, flags);
if (s == null)
return null;
if (s.equalsIgnoreCase("unknown artist"))
return null;
s = removeTrackNumbers(s, flags);
s = removeYearPrefixSuffix(s);
s = removeSafePrefixSuffix(s, PATTERNS_ARTIST);
if (s == null)
return null;
{
String old = s;
// s = removeSafePrefixSuffix(s, kDEFAULTS_acapella);
s = removeSafePrefixSuffix(s, DEFAULT_ACAPELLA, true);
if (s == null || !s.equals(old))
{
if (flags != null)
{
flags.put(KEY_ACAPELLA, Boolean.TRUE);
// flags.put(KEY_COMPILATION, Boolean.TRUE);
}
}
if (s == null)
return null;
}
s = removeQuotes(s);
s = removeURLs(s);
return s;
| public java.lang.String | rectifyGeneric(java.lang.String s)
return rectifyGeneric(s, null);
| public java.lang.String | rectifyGeneric(java.lang.String s, java.util.Map flags)
String old = s;
while (true)
{
s = rectifyGeneric_1(s, flags);
s = removeQuotes(s);
if (s == null)
return null;
if (s.equals(old))
return s;
old = s;
}
| private java.lang.String | rectifyGeneric_1(java.lang.String s, java.util.Map flags)
if (s == null)
return null;
s = s.trim();
if (s.length() < 1)
return null;
// s = new MusicOrganizerFilter().getNewName2(s);
s = clean(s, flags);
if (s == null)
return null;
s = TextUtils.replace(s, ".", ". ");
s = TextUtils.replace(s, " .", " ");
s = TextUtils.replace(s, " ", " ");
if (new RE("^\\?+$").match(s))
{
return null;
}
while (s.startsWith("."))
s = s.substring(1);
s = TextUtils.replace(s, "Live @ ", "Live At ");
s = TextUtils.replace(s, "Live@", "Live At ");
// s = s.re
if (s == null)
return null;
if (s.endsWith(", The"))
s = "The " + s.substring(0, s.length() - 5);
return s;
| public java.lang.String | rectifyGenre(java.lang.String s)
String old = s;
while (true)
{
s = rectifyGenre_1(s);
if (s == null)
return null;
if (s.equals(old))
return s;
old = s;
}
| private java.lang.String | rectifyGenre_1(java.lang.String s)
s = rectifyGeneric_1(s, null);
if (s == null)
return null;
if (s.equalsIgnoreCase("music"))
return null;
s = removeQuotes(s);
s = TextUtils.replace(s, " - ", "-");
s = removeSafePrefixSuffix(s, "�", true);
s = removeSafePrefixSuffix(s, DEFAULT_ACAPELLA, true);
return s;
| public java.lang.String | rectifyPublisher(java.lang.String s)
String old = s;
while (true)
{
s = rectifyPublisher_1(s);
if (s == null)
return null;
if (s.equals(old))
return s;
old = s;
}
| private java.lang.String | rectifyPublisher_1(java.lang.String s)
s = rectifyGeneric_1(s, null);
if (s == null)
return null;
s = removeURLs(s);
s = removeQuotes(s);
s = TextUtils.replace(s, " - ", "-");
return s;
| public java.lang.String | rectifySongTitle(java.lang.String s)
return rectifySongTitle(
// null, null,
s, null);
| public java.lang.String | rectifySongTitle(java.lang.String s, java.util.Map flags)
String old = s;
// while (true)
for (int i = 0; true; i++)
{
s = rectifySongTitle_1(s, flags);
if (s == null)
return null;
// if (artist != null)
// {
// if (s.startsWith(artist.name + " - "))
// s = s.substring(artist.name.length() + 3);
// if (s.endsWith(" - " + artist.name))
// s = s.substring(0, s.length() - (artist.name.length() + 3));
// }
// if (album != null)
// {
// if (s.startsWith(album.name + " - "))
// s = s.substring(album.name.length() + 3);
// if (s.endsWith(" - " + album.name))
// s = s.substring(0, s.length() - (album.name.length() + 3));
// }
if (s.equals(old))
return s;
old = s;
}
| private java.lang.String | rectifySongTitle_1(java.lang.String s, java.util.Map flags)
s = rectifyGeneric_1(s, flags);
if (s == null)
return null;
s = removeTrackNumbers(s, flags);
if (s == null)
return null;
s = removeQuotes(s);
return s;
| private java.lang.String | removePrefixes(java.lang.String s, java.lang.String[] prefixes)
return removePrefixes(s, new Vector(Arrays.asList(prefixes)));
// // return removePrefixes(s, prefixes, "");
// // }
// //
// // private String removePrefixes(String s, String prefixes[],
// // String prefix_suffix)
// // {
// if (s == null)
// return null;
//
// for (int i = 0; i < prefixes.length; i++)
// {
// String prefix = prefixes[i];
// // prefix = prefix + prefix_suffix;
//
// if (s.toLowerCase().startsWith(prefix.toLowerCase()))
// s = s.substring(prefix.length());
// }
// return s;
| private java.lang.String | removePrefixes(java.lang.String s, java.util.Vector prefixes)
if (s == null)
return null;
for (int i = 0; i < prefixes.size(); i++)
{
String prefix = (String) prefixes.get(i);
// prefix = prefix + prefix_suffix;
if (s.toLowerCase().startsWith(prefix.toLowerCase()))
s = s.substring(prefix.length());
}
return s;
| private java.lang.String | removeQuotes(java.lang.String s)
if (s == null)
return null;
if (new RE("^\".+\"$").match(s) || new RE("^'.+'$").match(s)
|| new RE("^\\{.+\\}$").match(s)
|| new RE("^\\(.+\\)$").match(s) || new RE("^<.+>$").match(s)
|| new RE("^\\[.+\\]$").match(s))
{
s = s.substring(1, s.length() - 1);
}
return s;
| private java.lang.String | removeSafePrefixSuffix(java.lang.String s, java.lang.String[] patterns)
return removeSafePrefixSuffix(s, patterns, false);
| private java.lang.String | removeSafePrefixSuffix(java.lang.String s, java.lang.String[] patterns, boolean permissive)
if (s == null)
return null;
for (int i = 0; s != null && i < patterns.length; i++)
{
String pattern = patterns[i];
s = removeSafePrefixSuffixLiteral(s, pattern, permissive);
}
return s;
| private java.lang.String | removeSafePrefixSuffix(java.lang.String s, java.lang.String pattern)
return removeSafePrefixSuffix(s, pattern, false);
| private java.lang.String | removeSafePrefixSuffix(java.lang.String s, java.lang.String pattern, boolean permissive)
if (s == null)
return null;
if (s.equalsIgnoreCase(pattern))
return null;
s = stripRegexMatch(s, getPrefixPattern((pattern), permissive));
s = stripRegexMatch(s, getSuffixPattern((pattern), permissive));
s = extractRegexPattern(s, getPrefixPattern2((pattern)), 1);
s = extractRegexPattern(s, getSuffixPattern2((pattern)), 1);
return s;
| private java.lang.String | removeSafePrefixSuffixLiteral(java.lang.String s, java.lang.String pattern, boolean permissive)
return removeSafePrefixSuffix(s, toRegexLiteral(pattern), permissive);
| private java.lang.String | removeSuffixes(java.lang.String s, java.lang.String[] suffixes)
return removeSuffixes(s, new Vector(Arrays.asList(suffixes)));
| private java.lang.String | removeSuffixes(java.lang.String s, java.util.Vector suffixes)
// return removeSuffixes(s, suffixes, "");
// }
//
// private String removeSuffixes(String s, String suffixes[],
// String suffix_prefix)
// {
if (s == null)
return null;
for (int i = 0; i < suffixes.size(); i++)
{
String suffix = (String) suffixes.get(i);
// suffix = suffix_prefix + suffix;
if (s.toLowerCase().endsWith(suffix.toLowerCase()))
s = s.substring(0, s.length() - suffix.length());
}
return s;
| private java.lang.String | removeTrackNumbers(java.lang.String s, java.util.Map flags)
if (s == null)
return null;
if (new RE("^(audio)? ?track ?[- ]?[0-9][0-9]?$")
.match(s.toLowerCase()))
{
if (s.toLowerCase().startsWith("audio"))
s = s.substring(5).trim();
parseTrackNumber(s.substring(5), flags);
return null;
}
if (new RE("^piste ?[- ]?[0-9][0-9]?$").match(s.toLowerCase()))
{
parseTrackNumber(s.substring(5), flags);
return null;
}
if (new RE("^[0-9][0-9] - ").match(s)
|| new RE("^[0-9][0-9][0-9] - ").match(s)
|| new RE("^[aAbBcCdD][0-9] - ").match(s))
{
int index = s.indexOf('-");
if (index >= 0)
{
String after = s.substring(index + 1).trim();
if (after.indexOf('-") < 0) // if mutiple -'s then ignore...
{
parseTrackNumber(s.substring(0, index), flags);
s = after;
}
}
}
if (new RE("^\\([0-9][0-9]\\) ").match(s)
|| new RE("^\\([abcdABCD][0-9]\\) ").match(s))
{
int index = s.indexOf(')");
if (index >= 0)
{
parseTrackNumber(s.substring(1, index), flags);
s = s.substring(index + 1).trim();
}
}
// if (new RE("^\\([0-9][0-9]\\) ").match(s))
// {
// int index = s.indexOf(')');
// if (index >= 0)
// {
// parseTrackNumber(s.substring(1, index), flags);
// s = s.substring(index + 1).trim();
// }
// }
return s;
| private java.lang.String | removeURLs(java.lang.String s)
if (s == null)
return null;
{
if (new RE("^http://").match(s.toLowerCase()))
return null;
// if (new RE("^[hH][tT][tT][pP]://").match(s))
// return null;
}
{
String temp = s;
temp = TextUtils.replace(temp, ". ", ".");
RE re = new RE("^[\\w \\-]*\\.[\\w \\.\\-]*\\.(com|net|org|edu)$");
// re.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
if (re.match(temp.toLowerCase()))
return null;
// if (new RE(
// "^[\\w \\-]*\\.[\\w \\.\\-]*\\.([cC][oO][mM]|[oO][rR][gG]|[nN][eE][tT])$")
// .match(temp))
// {
// return null;
// }
}
return s;
| private java.lang.String | removeYearPrefixSuffix(java.lang.String s)
if (s == null)
return null;
if (new RE("^\\(199[0-9]\\)").match(s)
|| new RE("^\\(200[0-9]\\)").match(s))
s = s.substring(7);
if (new RE("^\\( 199[0-9] \\)").match(s)
|| new RE("^\\( 200[0-9] \\)").match(s))
s = s.substring(9);
if (new RE("\\(199[0-9]\\)$").match(s)
|| new RE("\\(200[0-9]\\)$").match(s))
s = s.substring(0, s.length() - 7);
if (new RE("\\( 199[0-9] \\)$").match(s)
|| new RE("\\( 200[0-9] \\)$").match(s))
s = s.substring(0, s.length() - 9);
if (new RE("199[0-9] - ").match(s) || new RE("200[0-9] - ").match(s))
{
int index = s.indexOf('-");
if (index >= 0)
{
String temp = s.substring(index + 1);
if (temp.indexOf('-") < 0)
s = temp;
}
}
if (new RE("- 199[0-9]").match(s) || new RE(" - 200[0-9]").match(s))
{
int index = s.lastIndexOf('-");
if (index >= 0)
{
String temp = s.substring(0, index);
if (temp.indexOf('-") < 0)
s = temp;
}
}
return s;
| private java.lang.String | stripRegexMatch(java.lang.String s, java.lang.String pattern)
if (s == null)
return null;
try
{
RE re = regex_cache.getRegEx(pattern);
// RE re = new RE(pattern.toLowerCase());
if (!re.match(s.toLowerCase()))
return s;
// String match = re.getParen(0);
s = s.substring(0, re.getParenStart(0))
+ s.substring(re.getParenEnd(0));
return s;
}
catch (Exception e)
{
return s;
}
| public java.lang.String | toRegexLiteral(java.lang.String s)
StringBuffer result = new StringBuffer();
char chars[] = s.toCharArray();
for (int i = 0; i < chars.length; i++)
{
char c = chars[i];
if (ESCAPED.indexOf(c) >= 0)
result.append('\\");
result.append(c);
}
return result.toString();
| private java.lang.String | toTitleCase(java.lang.String s)
StringBuffer result = new StringBuffer();
char prev = 0;
char chars[] = s.toCharArray();
for (int i = 0; i < chars.length; i++)
{
char c = chars[i];
if (Character.isLetter(c))
{
if (i == 0)
result.append(Character.toUpperCase(c));
else if ((prev == '\'"))
// else if ((prev == '\'') && Character.isLetter(next))
result.append(Character.toLowerCase(c));
else if (!Character.isLetter(prev))
result.append(Character.toUpperCase(c));
else
result.append(Character.toLowerCase(c));
}
else
result.append(c);
prev = c;
}
return result.toString();
|
|