Skip to content

Commit 8749509

Browse files
committed
0.11.2 - Added StringCompare.compareIgnoreCase(String, String) overload
1 parent 295e57a commit 8749509

File tree

7 files changed

+77
-22
lines changed

7 files changed

+77
-22
lines changed

CHANGELOG.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
###[0.11.1](N/A) - 2016-10-30
7+
### [0.11.2](https://github.com/TeamworkGuy2/JTextUtil/commit/295e57a6016ecedbf3f68eb7f65aff98b27961c7) - 2016-10-30
8+
#### Added
9+
* Added StringCompare.compareIgnoreCase(String, String) overload and unit test
10+
11+
12+
--------
13+
### [0.11.1](https://github.com/TeamworkGuy2/JTextUtil/commit/295e57a6016ecedbf3f68eb7f65aff98b27961c7) - 2016-10-30
814
#### Added
915
* Added StringEscapeJson toJsonString() and fromJsonString() overloads which don't require string offset and length
1016

1117

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

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

2430

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

3036

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

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

3945

4046
--------
41-
###[0.10.4](https://github.com/TeamworkGuy2/JTextUtil/commit/6d7676e216cd63cfed9fb4f96180a5d647cb8372) - 2016-09-24
47+
### [0.10.4](https://github.com/TeamworkGuy2/JTextUtil/commit/6d7676e216cd63cfed9fb4f96180a5d647cb8372) - 2016-09-24
4248
#### Added
4349
* Added StringSplit.splitAtBoundary()
4450

4551

4652
--------
47-
###[0.10.3](https://github.com/TeamworkGuy2/JTextUtil/commit/cb0f1e114944175eafe06cc8311609187a2cc93e) - 2016-09-11
53+
### [0.10.3](https://github.com/TeamworkGuy2/JTextUtil/commit/cb0f1e114944175eafe06cc8311609187a2cc93e) - 2016-09-11
4854
#### Added
4955
* Added StringSplit.countMatches(char[], int, int, char[], int, int)
5056

5157

5258
--------
53-
###[0.10.2](https://github.com/TeamworkGuy2/JTextUtil/commit/573390227bb299d442f19b76f5761c8bc80e5a3c) - 2016-08-27
59+
### [0.10.2](https://github.com/TeamworkGuy2/JTextUtil/commit/573390227bb299d442f19b76f5761c8bc80e5a3c) - 2016-08-27
5460
#### Changed
5561
* Changed remote git repository name
5662

5763

5864
--------
59-
###[0.10.1](https://github.com/TeamworkGuy2/JTextFluff/commit/1d91013ca264434f32d59ac84b2e720444433689) - 2016-08-15
65+
### [0.10.1](https://github.com/TeamworkGuy2/JTextFluff/commit/1d91013ca264434f32d59ac84b2e720444433689) - 2016-08-15
6066
#### Added
6167
* StringPad
6268

6369

6470
--------
65-
###[0.10.0](https://github.com/TeamworkGuy2/JTextFluff/commit/621ad58574853f831ce5bc7e669e1447b8f306f9) - 2016-08-07
71+
### [0.10.0](https://github.com/TeamworkGuy2/JTextFluff/commit/621ad58574853f831ce5bc7e669e1447b8f306f9) - 2016-08-07
6672
#### Added
6773
* StringSearchOp for string comparison
6874

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

7379

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

8389

8490
--------
85-
###[0.9.0](https://github.com/TeamworkGuy2/JTextFluff/commit/d48b7163392bbfab2a5eca4bc6f06d2143b29a0f) - 2016-06-26
91+
### [0.9.0](https://github.com/TeamworkGuy2/JTextFluff/commit/d48b7163392bbfab2a5eca4bc6f06d2143b29a0f) - 2016-06-26
8692
#### Added
8793
* StringSplit substring*() and lastSubstring*() methods
8894

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

95101

96102
--------
97-
###[0.8.0](https://github.com/TeamworkGuy2/JTextFluff/commit/78acc7e47201b572db507634e5b3517b874e9c8f) - 2016-02-28
103+
### [0.8.0](https://github.com/TeamworkGuy2/JTextFluff/commit/78acc7e47201b572db507634e5b3517b874e9c8f) - 2016-02-28
98104
#### Added
99105
* Added StringIndex lastIndexOf()
100106

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

105111

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

115121

116122
--------
117-
###[0.7.1](https://github.com/TeamworkGuy2/JTextFluff/commit/07ef4c94a2ec576cc8aeb55ef9b6871ff304f304) - 2016-01-16
123+
### [0.7.1](https://github.com/TeamworkGuy2/JTextFluff/commit/07ef4c94a2ec576cc8aeb55ef9b6871ff304f304) - 2016-01-16
118124
#### Added
119125
* Added more JUnit tests
120126

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

125131

126132
--------
127-
###[0.7.0](https://github.com/TeamworkGuy2/JTextFluff/commit/94a5ebba1b9c37887dd017f87b3849eaa261ac56) - 2016-01-10
133+
### [0.7.0](https://github.com/TeamworkGuy2/JTextFluff/commit/94a5ebba1b9c37887dd017f87b3849eaa261ac56) - 2016-01-10
128134
#### Added
129135
* Additional tests and cleaning of old debugging statements and variable names
130136
* Added StringTrim trimLeading() and trimTrailing()

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
JTextUtil
22
==============
3-
version: 0.11.1
3+
version: 0.11.2
44

55
Dependencies: none
66

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

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

13-
####twg2.text.stringUtils
13+
### twg2.text.stringUtils
1414
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.
1515
Meant to provide more options than available in the Java API as of Java 1.8.
1616

17-
####twg2.text.test
17+
### twg2.text.test
1818
JUnit tests and examples (requires [JUnit 4] (http://junit.org/))

bin/jtext_util-with-tests.jar

1019 Bytes
Binary file not shown.

bin/jtext_util.jar

953 Bytes
Binary file not shown.

package-lib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"version" : "0.11.1",
2+
"version" : "0.11.2",
33
"name" : "jtext-util",
4-
"description" : "String search, replace, and transform functions that provide more control, at the expense of verbosity, than those already in the Java API",
4+
"description" : "String search, replace, and transform functions that provide more control, at the trade-off of verbosity, than those already in the Java API",
55
"homepage" : "https://github.com/TeamworkGuy2/JTextUtil",
66
"license" : "MIT",
77
"main" : "./bin/jtext_util.jar",

src/twg2/text/stringSearch/StringCompare.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ public static final boolean containsAny(String src, final String[] subStrs) {
209209
}
210210

211211

212+
public static final boolean containsIgnoreCase(String str, String searchStr) {
213+
return indexOfIgnoreCase(str, 0, str.length(), searchStr, 0, searchStr.length(), 0) > -1;
214+
}
215+
216+
212217
public static final boolean containsEqualIgnoreCase(final String[] strs, String str) {
213218
for(int i = 0, size = strs.length; i < size; i++) {
214219
if(strs[i] != null && strs[i].equalsIgnoreCase(str)) {
@@ -424,4 +429,41 @@ public static final int compareEqualCount(CharSequence str1, int offset1, CharSe
424429
return size - offset1;
425430
}
426431

432+
433+
static int indexOfIgnoreCase(String source, int sourceOffset, int sourceCount,
434+
String target, int targetOffset, int targetCount, int fromIndex) {
435+
if (fromIndex >= sourceCount) {
436+
return (targetCount == 0 ? sourceCount : -1);
437+
}
438+
if (fromIndex < 0) {
439+
fromIndex = 0;
440+
}
441+
if (targetCount == 0) {
442+
return fromIndex;
443+
}
444+
445+
char first = Character.toUpperCase(target.charAt(targetOffset));
446+
int max = sourceOffset + (sourceCount - targetCount);
447+
448+
for (int i = sourceOffset + fromIndex; i <= max; i++) {
449+
/* Look for first character. */
450+
if (Character.toUpperCase(source.charAt(i)) != first) {
451+
while (++i <= max && Character.toUpperCase(source.charAt(i)) != first);
452+
}
453+
454+
/* Found first character, now look at the rest of v2 */
455+
if (i <= max) {
456+
int j = i + 1;
457+
int end = j + targetCount - 1;
458+
for (int k = targetOffset + 1; j < end && Character.toUpperCase(source.charAt(j)) == Character.toUpperCase(target.charAt(k)); j++, k++);
459+
460+
if (j == end) {
461+
/* Found whole string. */
462+
return i - sourceOffset;
463+
}
464+
}
465+
}
466+
return -1;
467+
}
468+
427469
}

test/twg2/text/test/StringCompareTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public void anyEndsWith() {
3030

3131
@Test
3232
public void ignoreCase() {
33+
Assert.assertTrue(StringCompare.containsIgnoreCase("Char", "Char"));
34+
Assert.assertTrue(StringCompare.containsIgnoreCase("Chars", "char"));
35+
Assert.assertFalse(StringCompare.containsIgnoreCase("Chars", "char="));
36+
Assert.assertFalse(StringCompare.containsIgnoreCase("", "char="));
37+
3338
String[] strs = new String[] { "Alpha", "Beta", "Charlie", "Delta" };
3439

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

4247
Assert.assertTrue(StringCompare.containsIgnoreCase(strs, "Char"));
4348
Assert.assertTrue(StringCompare.containsIgnoreCase(strs, "char"));
49+
Assert.assertTrue(StringCompare.containsIgnoreCase(strs, "elta"));
4450
Assert.assertFalse(StringCompare.containsIgnoreCase(strs, "char="));
4551
Assert.assertTrue(StringCompare.containsIgnoreCase(Arrays.asList(strs), "Char"));
4652
Assert.assertTrue(StringCompare.containsIgnoreCase(Arrays.asList(strs), "char"));
53+
Assert.assertTrue(StringCompare.containsIgnoreCase(Arrays.asList(strs), "elta"));
4754
Assert.assertFalse(StringCompare.containsIgnoreCase(Arrays.asList(strs), "char="));
4855
}
4956

0 commit comments

Comments
 (0)