Issue 447 - allow users to specify delimiters for toTitlecase function

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2253 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2011-09-20 05:07:46 +00:00
parent 884d0ea8d4
commit 1b197d93d8
2 changed files with 8 additions and 9 deletions

View File

@ -52,12 +52,12 @@ public class ToTitlecase implements Function {
Object o = args[0]; Object o = args[0];
String s = o instanceof String ? (String) o : o.toString(); String s = o instanceof String ? (String) o : o.toString();
return WordUtils.capitalizeFully(s, delimiters); return WordUtils.capitalizeFully(s, delimiters);
// } else if (args.length == 2 && args[0] != null && args[1] != null) { } else if (args.length == 2 && args[0] != null && args[1] != null) {
// Object o = args[0]; Object o = args[0];
// String s = o instanceof String ? (String) o : o.toString(); String s = o instanceof String ? (String) o : o.toString();
// o = args[1]; o = args[1];
// String delims = o instanceof String ? (String) o: o.toString(); String delims = o instanceof String ? (String) o: o.toString();
// return WordUtils.capitalizeFully(s,delims.toCharArray()); return WordUtils.capitalizeFully(s,delims.toCharArray());
} else { } else {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a one or two strings"); return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a one or two strings");
} }

View File

@ -93,7 +93,6 @@ public class StringCaseTests extends RefineTest {
@Test @Test
public void testToTitlecaseInvalidParams() { public void testToTitlecaseInvalidParams() {
Assert.assertTrue(invoke("toTitlecase") instanceof EvalError); Assert.assertTrue(invoke("toTitlecase") instanceof EvalError);
Assert.assertTrue(invoke("toTitlecase", "one","two") instanceof EvalError);
Assert.assertTrue(invoke("toTitlecase", "one","two","three") instanceof EvalError); Assert.assertTrue(invoke("toTitlecase", "one","two","three") instanceof EvalError);
} }
@ -103,8 +102,8 @@ public class StringCaseTests extends RefineTest {
Assert.assertEquals((String)(invoke("toTitlecase", "ONE")),"One"); Assert.assertEquals((String)(invoke("toTitlecase", "ONE")),"One");
Assert.assertEquals((String)(invoke("toTitlecase", "one two three")),"One Two Three"); Assert.assertEquals((String)(invoke("toTitlecase", "one two three")),"One Two Three");
Assert.assertEquals((String)(invoke("toTitlecase", "C.R. SANDIDGE WINES, INC.")),"C.R. Sandidge Wines, Inc."); Assert.assertEquals((String)(invoke("toTitlecase", "C.R. SANDIDGE WINES, INC.")),"C.R. Sandidge Wines, Inc.");
// Assert.assertEquals((String)(invoke("toTitlecase", "C.R. SANDIDGE WINES, INC.",",. ")),"C.R. Sandidge Wines, Inc."); Assert.assertEquals((String)(invoke("toTitlecase", "C.R. SANDIDGE WINES, INC.",",. ")),"C.R. Sandidge Wines, Inc.");
// Assert.assertEquals((String)(invoke("toTitlecase", "one-two-three","-")),"One-Two-Three"); Assert.assertEquals((String)(invoke("toTitlecase", "one-two-three","-")),"One-Two-Three");
} }
} }