compareToIgnoreSpaces(byte[] byteArray, char[] anotherCharArray) {

网友投稿 526 2022-11-15

compareToIgnoreSpaces(byte[] byteArray, char[] anotherCharArray) {

compareToIgnoreSpaces(byte[] byteArray, char[] anotherCharArray) {

public static int compareToIgnoreSpaces(byte[] byteArray, char[] anotherCharArray) { if (byteArray == null && anotherCharArray == null) { return 0; } else if (byteArray == null) { return -1; } else if (anotherCharArray == null) { return 1; } if (byteArray.length == 0 && anotherCharArray.length == 0) { return 0; } else if (byteArray.length == 0) { return -1; } else if (anotherCharArray.length == 0) { return 1; } // we only ignore end white spaces int startIndex0 = 0; int endIndex0 = byteArray.length - 1; if (startIndex0 < byteArray.length) { // charArray has non whitespace char while (endIndex0 >= 0) { char c = (char) (byteArray[endIndex0] & 0xFF); if (c == ' ') { endIndex0--; } else { break; } } } int startIndex1 = 0; int endIndex1 = anotherCharArray.length - 1; if (startIndex1 < anotherCharArray.length) { // anotherCharArray has non whitespace char while (endIndex1 >= 0) { char c = anotherCharArray[endIndex1]; if (c == ' ') { endIndex1--; } else { break; } } } int len1 = endIndex0 - startIndex0 + 1; int len2 = endIndex1 - startIndex1 + 1; int n = ((len1 <= len2) ? len1 : len2); for (int i = 0; i < n; i++) { char c1 = (char) (byteArray[startIndex0 + i] & 0xFF); char c2 = anotherCharArray[startIndex1 + i]; if (c1 != c2) { return c1 - c2; } } return len1 - len2; }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:debug in console.c
下一篇:Mybatis防止sql注入原理分析
相关文章

 发表评论

暂时没有评论,来抢沙发吧~