Skip to content

Commit

Permalink
Merge pull request #89 from sclassen/simplifyAsciiClass
Browse files Browse the repository at this point in the history
remove Ascii class
  • Loading branch information
martinfrancois authored Aug 25, 2019
2 parents a142d97 + d2e4dac commit f46dd57
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 228 deletions.
198 changes: 0 additions & 198 deletions preferencesfx/src/main/java/com/dlsc/preferencesfx/util/Ascii.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dlsc.preferencesfx.util;

import static com.dlsc.preferencesfx.util.Ascii.containsIgnoreCase;
import static com.dlsc.preferencesfx.util.Strings.containsIgnoreCase;

import com.dlsc.formsfx.model.structure.Field;
import com.dlsc.preferencesfx.model.Category;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dlsc.preferencesfx.util;

import static com.dlsc.preferencesfx.util.Ascii.containsIgnoreCase;
import static com.dlsc.preferencesfx.util.Strings.containsIgnoreCase;

import com.dlsc.preferencesfx.model.Category;
import com.dlsc.preferencesfx.model.Group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,29 @@ public static String hexString(byte[] bytes) {
return new String(hexChars);
}

/**
* Indicates whether the character sequence {@code sequence} contains the {@code subSequence},
* ignoring the case in the same manner as {@link String#equalsIgnoreCase(String)}.
*
* @param str the string to search in
* @param searchStr the string to search for
* @return {@code true} if str contains the searchStr (case insensitive)
*/
static boolean containsIgnoreCase(String str, String searchStr) {
if (str == null || searchStr == null) {
return false;
}
if (searchStr.isEmpty()) {
return true;
}

final int len = searchStr.length();
final int max = str.length() - len;
for (int i = 0; i <= max; i++) {
if (str.regionMatches(true, i, searchStr, 0, len)) {
return true;
}
}
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.dlsc.preferencesfx.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* Test class for {@link Strings}.
*
* @author François Martin
* @author Marco Sanfratello
*/
public class StringsTest {
@Test
public void testContainsIgnoreCase() {
assertTrue(Strings.containsIgnoreCase("Favorites", ""));
assertTrue(Strings.containsIgnoreCase("Favorites", "F"));
assertTrue(Strings.containsIgnoreCase("Favorites", "Fa"));
assertTrue(Strings.containsIgnoreCase("Font Size", "Fo"));
assertTrue(Strings.containsIgnoreCase("Font Size", "fo"));
assertTrue(Strings.containsIgnoreCase("Font Size", "fO"));
assertTrue(Strings.containsIgnoreCase("Font Size", "nt si"));
assertTrue(Strings.containsIgnoreCase("Scaling & Ordering", "ord"));

assertFalse(Strings.containsIgnoreCase(null, "Fo"));
assertFalse(Strings.containsIgnoreCase("Favorites", null));
assertFalse(Strings.containsIgnoreCase("Favorites", "Fo"));
assertFalse(Strings.containsIgnoreCase("Scaling & Ordering", "awdawdhwhd"));
}

}

0 comments on commit f46dd57

Please sign in to comment.