|
From: Christopher W. <caw...@us...> - 2006-05-17 02:41:11
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv24172/src/org/rubypeople/rdt/internal/core/util Modified Files: CharOperation.java Log Message: Add support for a Ruby "Lint" like AST visitor which will create semantic analysis and warnings ala JDT Index: CharOperation.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CharOperation.java 25 Mar 2006 02:27:35 -0000 1.4 --- CharOperation.java 17 May 2006 02:41:08 -0000 1.5 *************** *** 8,11 **** --- 8,16 ---- */ public class CharOperation { + + /** + * Constant for an empty char array + */ + public static final char[] NO_CHAR = new char[0]; /** *************** *** 880,882 **** --- 885,943 ---- return hash & 0x7FFFFFFF; } + + /** + * Answers the concatenation of the given array parts using the given separator between each part. + * <br> + * <br> + * For example:<br> + * <ol> + * <li><pre> + * array = { { 'a' }, { 'b' } } + * separator = '.' + * => result = { 'a', '.', 'b' } + * </pre> + * </li> + * <li><pre> + * array = null + * separator = '.' + * => result = { } + * </pre></li> + * </ol> + * + * @param array the given array + * @param separator the given separator + * @return the concatenation of the given array parts using the given separator between each part + */ + 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; + } } |