Skip to content

Commit

Permalink
0.11.2 - Added StringCompare.compareIgnoreCase(String, String) overload
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamworkGuy2 committed Aug 12, 2017
1 parent 295e57a commit 8749509
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 22 deletions.
36 changes: 21 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.11.1](N/A) - 2016-10-30
### [0.11.2](https://github.com/TeamworkGuy2/JTextUtil/commit/295e57a6016ecedbf3f68eb7f65aff98b27961c7) - 2016-10-30
#### Added
* Added StringCompare.compareIgnoreCase(String, String) overload and unit test


--------
### [0.11.1](https://github.com/TeamworkGuy2/JTextUtil/commit/295e57a6016ecedbf3f68eb7f65aff98b27961c7) - 2016-10-30
#### Added
* Added StringEscapeJson toJsonString() and fromJsonString() overloads which don't require string offset and length


--------
###[0.11.0](https://github.com/TeamworkGuy2/JTextUtil/commit/9f1c9bd4af821ebe504919c430d639037558ac6c) - 2016-10-08
### [0.11.0](https://github.com/TeamworkGuy2/JTextUtil/commit/9f1c9bd4af821ebe504919c430d639037558ac6c) - 2016-10-08
#### Added
* Added StringCase isDashCase() and toDashCase() with additional unit tests

Expand All @@ -23,13 +29,13 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.10.6](https://github.com/TeamworkGuy2/JTextUtil/commit/1b81c02b2af0ac1186c1bab9c8534c6f851be2e9) - 2016-10-02
### [0.10.6](https://github.com/TeamworkGuy2/JTextUtil/commit/1b81c02b2af0ac1186c1bab9c8534c6f851be2e9) - 2016-10-02
#### Added
* Added StringEscapeJson.toJsonString(char, Appendable) override


--------
###[0.10.5](https://github.com/TeamworkGuy2/JTextUtil/commit/d0299113a4f3478320321a7e9dfa8ffac84ce9c6) - 2016-09-26
### [0.10.5](https://github.com/TeamworkGuy2/JTextUtil/commit/d0299113a4f3478320321a7e9dfa8ffac84ce9c6) - 2016-09-26
#### Added
* Added StringJoin.join(Iterator, ...) and StringJoin.Objects.join(Iterator, ...)

Expand All @@ -38,31 +44,31 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.10.4](https://github.com/TeamworkGuy2/JTextUtil/commit/6d7676e216cd63cfed9fb4f96180a5d647cb8372) - 2016-09-24
### [0.10.4](https://github.com/TeamworkGuy2/JTextUtil/commit/6d7676e216cd63cfed9fb4f96180a5d647cb8372) - 2016-09-24
#### Added
* Added StringSplit.splitAtBoundary()


--------
###[0.10.3](https://github.com/TeamworkGuy2/JTextUtil/commit/cb0f1e114944175eafe06cc8311609187a2cc93e) - 2016-09-11
### [0.10.3](https://github.com/TeamworkGuy2/JTextUtil/commit/cb0f1e114944175eafe06cc8311609187a2cc93e) - 2016-09-11
#### Added
* Added StringSplit.countMatches(char[], int, int, char[], int, int)


--------
###[0.10.2](https://github.com/TeamworkGuy2/JTextUtil/commit/573390227bb299d442f19b76f5761c8bc80e5a3c) - 2016-08-27
### [0.10.2](https://github.com/TeamworkGuy2/JTextUtil/commit/573390227bb299d442f19b76f5761c8bc80e5a3c) - 2016-08-27
#### Changed
* Changed remote git repository name


--------
###[0.10.1](https://github.com/TeamworkGuy2/JTextFluff/commit/1d91013ca264434f32d59ac84b2e720444433689) - 2016-08-15
### [0.10.1](https://github.com/TeamworkGuy2/JTextFluff/commit/1d91013ca264434f32d59ac84b2e720444433689) - 2016-08-15
#### Added
* StringPad


--------
###[0.10.0](https://github.com/TeamworkGuy2/JTextFluff/commit/621ad58574853f831ce5bc7e669e1447b8f306f9) - 2016-08-07
### [0.10.0](https://github.com/TeamworkGuy2/JTextFluff/commit/621ad58574853f831ce5bc7e669e1447b8f306f9) - 2016-08-07
#### Added
* StringSearchOp for string comparison

Expand All @@ -72,7 +78,7 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.9.1](https://github.com/TeamworkGuy2/JTextFluff/commit/cd020a56da7a9549c2be5814bda830e59c23d245) - 2016-07-07
### [0.9.1](https://github.com/TeamworkGuy2/JTextFluff/commit/cd020a56da7a9549c2be5814bda830e59c23d245) - 2016-07-07
#### Added
* StringJoin join() overloads with 'off' and 'len' parameters
* Additional unit tests
Expand All @@ -82,7 +88,7 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.9.0](https://github.com/TeamworkGuy2/JTextFluff/commit/d48b7163392bbfab2a5eca4bc6f06d2143b29a0f) - 2016-06-26
### [0.9.0](https://github.com/TeamworkGuy2/JTextFluff/commit/d48b7163392bbfab2a5eca4bc6f06d2143b29a0f) - 2016-06-26
#### Added
* StringSplit substring*() and lastSubstring*() methods

Expand All @@ -94,7 +100,7 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.8.0](https://github.com/TeamworkGuy2/JTextFluff/commit/78acc7e47201b572db507634e5b3517b874e9c8f) - 2016-02-28
### [0.8.0](https://github.com/TeamworkGuy2/JTextFluff/commit/78acc7e47201b572db507634e5b3517b874e9c8f) - 2016-02-28
#### Added
* Added StringIndex lastIndexOf()

Expand All @@ -104,7 +110,7 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.7.2](https://github.com/TeamworkGuy2/JTextFluff/commit/9103614630787018da70515f6f519dc485dfdc63) - 2016-02-08
### [0.7.2](https://github.com/TeamworkGuy2/JTextFluff/commit/9103614630787018da70515f6f519dc485dfdc63) - 2016-02-08
#### Added
* Added StringJoin repeat() and repeatJoin() methods to repeat a string several times and return a string result or appending to a destination
* Added StringTrim countAndTrimLeading() and countAndTrimTrailing() to return a trimmed string as well as how many leading/trailing characters or strings were trimmed
Expand All @@ -114,7 +120,7 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.7.1](https://github.com/TeamworkGuy2/JTextFluff/commit/07ef4c94a2ec576cc8aeb55ef9b6871ff304f304) - 2016-01-16
### [0.7.1](https://github.com/TeamworkGuy2/JTextFluff/commit/07ef4c94a2ec576cc8aeb55ef9b6871ff304f304) - 2016-01-16
#### Added
* Added more JUnit tests

Expand All @@ -124,7 +130,7 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/


--------
###[0.7.0](https://github.com/TeamworkGuy2/JTextFluff/commit/94a5ebba1b9c37887dd017f87b3849eaa261ac56) - 2016-01-10
### [0.7.0](https://github.com/TeamworkGuy2/JTextFluff/commit/94a5ebba1b9c37887dd017f87b3849eaa261ac56) - 2016-01-10
#### Added
* Additional tests and cleaning of old debugging statements and variable names
* Added StringTrim trimLeading() and trimTrailing()
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
JTextUtil
==============
version: 0.11.1
version: 0.11.2

Dependencies: none

####twg2.text.stringEscape
### twg2.text.stringEscape
Escape and unescape methods for JSON, XML, and strings with special characters (i.e. non-ASCII, quotes, or \t \b \f \r characters).

####twg2.text.stringSearch
### twg2.text.stringSearch
String search methods for indexOf, endsWith, startsWith, compare, contains, and common prefix/suffix (StringCommonality).

####twg2.text.stringUtils
### twg2.text.stringUtils
String utility methods for join, pad, split, substring, trim, replace, n-th match, hex conversion (StringHex), empty/whitespace checking (StringCheck), and other replacement and transformation methods.
Meant to provide more options than available in the Java API as of Java 1.8.

####twg2.text.test
### twg2.text.test
JUnit tests and examples (requires [JUnit 4] (http://junit.org/))
Binary file modified bin/jtext_util-with-tests.jar
Binary file not shown.
Binary file modified bin/jtext_util.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lib.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version" : "0.11.1",
"version" : "0.11.2",
"name" : "jtext-util",
"description" : "String search, replace, and transform functions that provide more control, at the expense of verbosity, than those already in the Java API",
"description" : "String search, replace, and transform functions that provide more control, at the trade-off of verbosity, than those already in the Java API",
"homepage" : "https://github.com/TeamworkGuy2/JTextUtil",
"license" : "MIT",
"main" : "./bin/jtext_util.jar",
Expand Down
42 changes: 42 additions & 0 deletions src/twg2/text/stringSearch/StringCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ public static final boolean containsAny(String src, final String[] subStrs) {
}


public static final boolean containsIgnoreCase(String str, String searchStr) {
return indexOfIgnoreCase(str, 0, str.length(), searchStr, 0, searchStr.length(), 0) > -1;
}


public static final boolean containsEqualIgnoreCase(final String[] strs, String str) {
for(int i = 0, size = strs.length; i < size; i++) {
if(strs[i] != null && strs[i].equalsIgnoreCase(str)) {
Expand Down Expand Up @@ -424,4 +429,41 @@ public static final int compareEqualCount(CharSequence str1, int offset1, CharSe
return size - offset1;
}


static int indexOfIgnoreCase(String source, int sourceOffset, int sourceCount,
String target, int targetOffset, int targetCount, int fromIndex) {
if (fromIndex >= sourceCount) {
return (targetCount == 0 ? sourceCount : -1);
}
if (fromIndex < 0) {
fromIndex = 0;
}
if (targetCount == 0) {
return fromIndex;
}

char first = Character.toUpperCase(target.charAt(targetOffset));
int max = sourceOffset + (sourceCount - targetCount);

for (int i = sourceOffset + fromIndex; i <= max; i++) {
/* Look for first character. */
if (Character.toUpperCase(source.charAt(i)) != first) {
while (++i <= max && Character.toUpperCase(source.charAt(i)) != first);
}

/* Found first character, now look at the rest of v2 */
if (i <= max) {
int j = i + 1;
int end = j + targetCount - 1;
for (int k = targetOffset + 1; j < end && Character.toUpperCase(source.charAt(j)) == Character.toUpperCase(target.charAt(k)); j++, k++);

if (j == end) {
/* Found whole string. */
return i - sourceOffset;
}
}
}
return -1;
}

}
7 changes: 7 additions & 0 deletions test/twg2/text/test/StringCompareTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void anyEndsWith() {

@Test
public void ignoreCase() {
Assert.assertTrue(StringCompare.containsIgnoreCase("Char", "Char"));
Assert.assertTrue(StringCompare.containsIgnoreCase("Chars", "char"));
Assert.assertFalse(StringCompare.containsIgnoreCase("Chars", "char="));
Assert.assertFalse(StringCompare.containsIgnoreCase("", "char="));

String[] strs = new String[] { "Alpha", "Beta", "Charlie", "Delta" };

Assert.assertTrue(StringCompare.containsEqualIgnoreCase(strs, "Alpha"));
Expand All @@ -41,9 +46,11 @@ public void ignoreCase() {

Assert.assertTrue(StringCompare.containsIgnoreCase(strs, "Char"));
Assert.assertTrue(StringCompare.containsIgnoreCase(strs, "char"));
Assert.assertTrue(StringCompare.containsIgnoreCase(strs, "elta"));
Assert.assertFalse(StringCompare.containsIgnoreCase(strs, "char="));
Assert.assertTrue(StringCompare.containsIgnoreCase(Arrays.asList(strs), "Char"));
Assert.assertTrue(StringCompare.containsIgnoreCase(Arrays.asList(strs), "char"));
Assert.assertTrue(StringCompare.containsIgnoreCase(Arrays.asList(strs), "elta"));
Assert.assertFalse(StringCompare.containsIgnoreCase(Arrays.asList(strs), "char="));
}

Expand Down

0 comments on commit 8749509

Please sign in to comment.