commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [14/50] [lang] LANG-1300: Merged Rob's javadoc comments and updated to use code units instead of code points
Date Mon, 17 Apr 2017 12:19:37 GMT
LANG-1300: Merged Rob's javadoc comments and updated to use code units instead of code points


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/b521820b
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/b521820b
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/b521820b

Branch: refs/heads/release
Commit: b521820b23c45fd068618d10955eceed48801eff
Parents: 0e1b328
Author: MarkDacek <mark.dacek@richmond.edu>
Authored: Wed Mar 15 23:32:31 2017 -0400
Committer: MarkDacek <mark.dacek@richmond.edu>
Committed: Wed Mar 15 23:32:31 2017 -0400

----------------------------------------------------------------------
 .../apache/commons/lang3/CharSequenceUtils.java | 20 +++--------------
 .../lang3/StringUtilsEqualsIndexOfTest.java     | 23 +++++++++++++++-----
 2 files changed, 21 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b521820b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
index 7be6573..88d7373 100644
--- a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
@@ -113,18 +113,13 @@ public class CharSequenceUtils {
         }
         //supplementary characters (LANG1300)
         if (searchChar <= Character.MAX_CODE_POINT) {
-            int ind = 0;
             char[] chars = Character.toChars(searchChar);
             for (int i = start; i < sz - 1; i++) {
                 char high = cs.charAt(i);
                 char low = cs.charAt(i + 1);
                 if (high == chars[0] && low == chars[1]) {
-                    return ind;
-                } else if (Character.isSurrogatePair(high, low)) {
-                    //skip over 1
-                    i++;
+                    return i;
                 }
-                ind++;
             }
         }
         return NOT_FOUND;
@@ -203,21 +198,12 @@ public class CharSequenceUtils {
             if (start == sz - 1) {
                 return NOT_FOUND;
             }
-            int maxInd = -1;
-            int ind = 0;
-            for (int i = 0; i < cs.length() - 1; i++) {
+            for (int i = start; i >= 0; i--) {
                 char high = cs.charAt(i);
                 char low = cs.charAt(i + 1);
                 if (chars[0] == high && chars[1] == low) {
-                    maxInd = ind;
-                    i++;
-                } else if (Character.isSurrogatePair(high, low)) {
-                    i++; //skip over one
+                    return i;
                 }
-                ind++;
-            }
-            if (maxInd >= start) {
-                return maxInd;
             }
         }
         return NOT_FOUND;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b521820b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index 701f022..4635a54 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -300,13 +300,21 @@ public class StringUtilsEqualsIndexOfTest  {
     	StringBuilder builder = new StringBuilder();
     	builder.appendCodePoint(CODE_POINT);
     	assertEquals(0, StringUtils.indexOf(builder, CODE_POINT, 0));
+    	assertEquals(0, StringUtils.indexOf(builder.toString(), CODE_POINT, 0));
     	builder.appendCodePoint(CODE_POINT);
-    	assertEquals(1, StringUtils.indexOf(builder, CODE_POINT, 1));
+    	assertEquals(2, StringUtils.indexOf(builder, CODE_POINT, 1));
+    	assertEquals(2, StringUtils.indexOf(builder.toString(), CODE_POINT, 1));
     	//inner branch on the supplementary character block
     	char[] tmp = {(char) 55361};
     	builder = new StringBuilder();
     	builder.append(tmp);
     	assertEquals(-1, StringUtils.indexOf(builder, CODE_POINT, 0));
+    	assertEquals(-1, StringUtils.indexOf(builder.toString(), CODE_POINT, 0));
+    	builder.appendCodePoint(CODE_POINT);
+    	assertEquals(1, StringUtils.indexOf(builder, CODE_POINT, 0));
+    	assertEquals(1, StringUtils.indexOf(builder.toString(), CODE_POINT, 0));
+    	assertEquals(-1, StringUtils.indexOf(builder, CODE_POINT, 2));
+        assertEquals(-1, StringUtils.indexOf(builder.toString(), CODE_POINT, 2));
         
     }
 
@@ -546,20 +554,25 @@ public class StringUtilsEqualsIndexOfTest  {
     	builder.appendCodePoint(CODE_POINT);
     	assertEquals(0, StringUtils.lastIndexOf(builder, CODE_POINT, 0));
     	builder.appendCodePoint(CODE_POINT);
-    	assertEquals(1, StringUtils.lastIndexOf(builder, CODE_POINT, 0));
-    	assertEquals(1, StringUtils.lastIndexOf(builder, CODE_POINT, 1));
+    	assertEquals(0, StringUtils.lastIndexOf(builder, CODE_POINT, 0));
+    	assertEquals(0, StringUtils.lastIndexOf(builder, CODE_POINT, 1));
+        assertEquals(2, StringUtils.lastIndexOf(builder, CODE_POINT, 2));
+
 
 
     	builder.append("aaaaa");
-    	assertEquals(-1, StringUtils.lastIndexOf(builder, CODE_POINT, 4));
+    	assertEquals(2, StringUtils.lastIndexOf(builder, CODE_POINT, 4));
     	//inner branch on the supplementary character block
     	char[] tmp = {(char) 55361};
     	builder = new StringBuilder();
     	builder.append(tmp);
     	assertEquals(-1, StringUtils.lastIndexOf(builder, CODE_POINT, 0));
     	builder.appendCodePoint(CODE_POINT);
-    	assertEquals(1, StringUtils.lastIndexOf(builder, CODE_POINT, 0 ));
+    	assertEquals(-1, StringUtils.lastIndexOf(builder, CODE_POINT, 0 ));
         assertEquals(1, StringUtils.lastIndexOf(builder, CODE_POINT, 1 ));
+        assertEquals(-1, StringUtils.lastIndexOf(builder.toString(), CODE_POINT, 0));
+        assertEquals(1, StringUtils.lastIndexOf(builder.toString(), CODE_POINT, 1));
+
 
     }
 


Mime
View raw message