FmUtil { public static String stripSuffix(String name, String suffix, boolean recursiveStrip) { if (name.length() < 2) { return name; } int suffixStart = name.lastIndexOf(suffix.charAt(0)); if (suffixStart != -1 && name.regionMatches(suffixStart, suffix, 0, name.length() - suffixStart)) { name = name.substring(0, suffixStart); } if (recursiveStrip && name.endsWith(suffix)) { return stripSuffix(name, suffix, recursiveStrip); } return name; }  static String stripSuffix(String name, String suffix, boolean recursiveStrip);  }
@Test public void testStripSuffix() throws Exception { assertEquals("", stripSuffix("", "", false)); assertEquals("", stripSuffix("", "foo", false)); assertEquals("", stripSuffix("foo", "foo", false)); assertEquals("Foo", stripSuffix("FooBar", "Bar", false)); assertEquals("Foo", stripSuffix("FooBa", "Bar", false)); assertEquals("Foo", stripSuffix("FooBarBar", "Bar", true)); assertEquals("FooBar", stripSuffix("FooBarBar", "Bar", false)); }