diff options
author | aclement <aclement> | 2009-08-24 18:11:00 +0000 |
---|---|---|
committer | aclement <aclement> | 2009-08-24 18:11:00 +0000 |
commit | 6706a106771e2a04d75735977e98795e407aa2e1 (patch) | |
tree | 2c34d627928e9c3fb72d153bbb522b0a185dc43f /asm | |
parent | b6649690748b44544a361e39510a10e0bf83ca46 (diff) | |
download | aspectj-6706a106771e2a04d75735977e98795e407aa2e1.tar.gz aspectj-6706a106771e2a04d75735977e98795e407aa2e1.zip |
few more helper methods
Diffstat (limited to 'asm')
-rw-r--r-- | asm/src/org/aspectj/asm/internal/CharOperation.java | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/asm/src/org/aspectj/asm/internal/CharOperation.java b/asm/src/org/aspectj/asm/internal/CharOperation.java index 71ae5cafe..bf5330a11 100644 --- a/asm/src/org/aspectj/asm/internal/CharOperation.java +++ b/asm/src/org/aspectj/asm/internal/CharOperation.java @@ -16,6 +16,10 @@ package org.aspectj.asm.internal; */ public class CharOperation { + public static final char[][] NO_CHAR_CHAR = new char[0][]; + + public static final char[] NO_CHAR = new char[0]; + /** * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation */ @@ -34,6 +38,44 @@ public class CharOperation { return result; } + public static final char[][] subarray(char[][] array, int start, int end) { + if (end == -1) + end = array.length; + if (start > end) + return null; + if (start < 0) + return null; + if (end > array.length) + return null; + + char[][] result = new char[end - start][]; + System.arraycopy(array, start, result, 0, end - start); + return result; + } + + public static final char[][] splitOn(char divider, char[] array) { + int length = array == null ? 0 : array.length; + if (length == 0) + return NO_CHAR_CHAR; + + int wordCount = 1; + for (int i = 0; i < length; i++) + if (array[i] == divider) + wordCount++; + char[][] split = new char[wordCount][]; + int last = 0, currentWord = 0; + for (int i = 0; i < length; i++) { + if (array[i] == divider) { + split[currentWord] = new char[i - last]; + System.arraycopy(array, last, split[currentWord++], 0, i - last); + last = i + 1; + } + } + split[currentWord] = new char[length - last]; + System.arraycopy(array, last, split[currentWord], 0, length - last); + return split; + } + /** * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation */ @@ -88,6 +130,67 @@ public class CharOperation { return true; } + final static public String toString(char[][] array) { + char[] result = concatWith(array, '.'); + return new String(result); + } + + public static final char[] concatWith(char[][] array, char separator) { + int length = array == null ? 0 : array.length; + if (length == 0) + return CharOperation.NO_CHAR; + + int size = length - 1; + int index = length; + while (--index >= 0) { + if (array[index].length == 0) + size--; + else + size += array[index].length; + } + if (size <= 0) + return CharOperation.NO_CHAR; + char[] result = new char[size]; + index = length; + while (--index >= 0) { + length = array[index].length; + if (length > 0) { + System.arraycopy(array[index], 0, result, (size -= length), length); + if (--size >= 0) + result[size] = separator; + } + } + return result; + } + + public static final int hashCode(char[] array) { + int length = array.length; + int hash = length == 0 ? 31 : array[0]; + if (length < 8) { + for (int i = length; --i > 0;) + hash = (hash * 31) + array[i]; + } else { + // 8 characters is enough to compute a decent hash code, don't waste time examining every character + for (int i = length - 1, last = i > 16 ? i - 16 : 0; i > last; i -= 2) + hash = (hash * 31) + array[i]; + } + return hash & 0x7FFFFFFF; + } + + public static final boolean equals(char[][] first, char[][] second) { + if (first == second) + return true; + if (first == null || second == null) + return false; + if (first.length != second.length) + return false; + + for (int i = first.length; --i >= 0;) + if (!equals(first[i], second[i])) + return false; + return true; + } + /** * Taken from org.aspectj.org.eclipse.jdt.core.compiler.CharOperation */ |