List of usage examples for java.lang StringIndexOutOfBoundsException StringIndexOutOfBoundsException
public StringIndexOutOfBoundsException(int index)
From source file:org.aries.util.SimpleString.java
/** * //from w ww . j a v a 2 s . com * @param srcBegin * @param srcEnd * @param dst * @param dstBegin */ public void getChars(final int srcBegin, final int srcEnd, final char dst[], final int dstBegin) { if (srcBegin < 0) { throw new StringIndexOutOfBoundsException(srcBegin); } if (srcEnd > length()) { throw new StringIndexOutOfBoundsException(srcEnd); } if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } int j = 0; for (int i = srcBegin; i < srcEnd - srcBegin; i++) { int low = data[j++] & 0xFF; int high = data[j++] << 8 & 0xFF00; dst[i] = (char) (low | high); } }
From source file:it.d4nguard.rgrpg.util.StringCompiler.java
/** * Appends a char array to the string builder. * Appending null will call {@link #appendNull()}. * //w ww . j a v a2 s .c om * @param chars * the char array to append * @param startIndex * the start index, inclusive, must be valid * @param length * the length to append, must be valid * @return this, to enable chaining */ public StringCompiler append(char[] chars, int startIndex, int length) { preliminars(); if (chars == null) { return appendNull(); } if (startIndex < 0 || startIndex > chars.length) { throw new StringIndexOutOfBoundsException("Invalid startIndex: " + length); } if (length < 0 || (startIndex + length) > chars.length) { throw new StringIndexOutOfBoundsException("Invalid length: " + length); } if (length > 0) { int len = length(); ensureCapacity(len + length); System.arraycopy(chars, startIndex, buffer, len, length); size += length; } return this; }
From source file:com.door43.translationstudio.core.TargetTranslation.java
/** * Returns the id of the project of the target translation * @param targetTranslationId the target translation id * @return// www.j a v a 2 s. c o m */ public static String getProjectSlugFromId(String targetTranslationId) throws StringIndexOutOfBoundsException { String[] complexId = targetTranslationId.split("_"); if (complexId.length >= 3) { return complexId[1]; } else { throw new StringIndexOutOfBoundsException("malformed target translation id " + targetTranslationId); } }
From source file:com.door43.translationstudio.core.TargetTranslation.java
/** * Returns the id of the target lanugage of the target translation * @param targetTranslationId the target translation id * @return/* w w w .j a va2 s. c om*/ */ public static String getTargetLanguageSlugFromId(String targetTranslationId) throws StringIndexOutOfBoundsException { String[] complexId = targetTranslationId.split("_"); if (complexId.length >= 3) { return complexId[0]; } else { throw new StringIndexOutOfBoundsException("malformed target translation id" + targetTranslationId); } }
From source file:org.regenstrief.util.Util.java
/** * Parses an int from a substring of the given String; should yield the same results as * Integer.parseInt(s.substring(startIndex, endIndex), but should be more efficient * /*from www . j ava 2 s .c o m*/ * @param s the String * @param startIndex the start index of the substring * @param endIndex the end index of the substring * @return the int **/ public final static int parseInt(final String s, final int startIndex, final int endIndex) { int n = 0, sign = 1; if (startIndex >= endIndex) { throw new StringIndexOutOfBoundsException(endIndex - startIndex); } for (int i = startIndex; i < endIndex; i++) { final char c = s.charAt(i); if (i == startIndex) { if (c == '-') { sign = -1; continue; } else if (c == '+') { // Java 7 introduced support for leading + character continue; } } if ((c < '0') || (c > '9')) { throw new NumberFormatException(s); } n = (n * 10) + (c - '0'); } return sign * n; }
From source file:it.d4nguard.rgrpg.util.StringCompiler.java
/** * Appends part of a string to this string builder. * Appending null will call {@link #appendNull()}. * //from w w w. j a va2 s.c o m * @param str * the string to append * @param startIndex * the start index, inclusive, must be valid * @param length * the length to append, must be valid * @return this, to enable chaining */ public StringCompiler append(String str, int startIndex, int length) { preliminars(); if (str == null) { return appendNull(); } if (startIndex < 0 || startIndex > str.length()) { throw new StringIndexOutOfBoundsException("startIndex must be valid"); } if (length < 0 || (startIndex + length) > str.length()) { throw new StringIndexOutOfBoundsException("length must be valid"); } if (length > 0) { int len = length(); ensureCapacity(len + length); str.getChars(startIndex, startIndex + length, buffer, len); size += length; } return this; }
From source file:it.d4nguard.rgrpg.util.StringCompiler.java
/** * Appends part of a string buffer to this string builder. * Appending null will call {@link #appendNull()}. * //from w w w .j a va 2 s .c om * @param str * the string to append * @param startIndex * the start index, inclusive, must be valid * @param length * the length to append, must be valid * @return this, to enable chaining */ public StringCompiler append(StringBuffer str, int startIndex, int length) { preliminars(); if (str == null) { return appendNull(); } if (startIndex < 0 || startIndex > str.length()) { throw new StringIndexOutOfBoundsException("startIndex must be valid"); } if (length < 0 || (startIndex + length) > str.length()) { throw new StringIndexOutOfBoundsException("length must be valid"); } if (length > 0) { int len = length(); ensureCapacity(len + length); str.getChars(startIndex, startIndex + length, buffer, len); size += length; } return this; }
From source file:it.d4nguard.rgrpg.util.StringCompiler.java
/** * Appends part of a string builder to this string builder. * Appending null will call {@link #appendNull()}. * //from w ww. java 2 s . co m * @param str * the string to append * @param startIndex * the start index, inclusive, must be valid * @param length * the length to append, must be valid * @return this, to enable chaining */ public StringCompiler append(StringCompiler str, int startIndex, int length) { preliminars(); if (str == null) { return appendNull(); } if (startIndex < 0 || startIndex > str.length()) { throw new StringIndexOutOfBoundsException("startIndex must be valid"); } if (length < 0 || (startIndex + length) > str.length()) { throw new StringIndexOutOfBoundsException("length must be valid"); } if (length > 0) { int len = length(); ensureCapacity(len + length); str.getChars(startIndex, startIndex + length, buffer, len); size += length; } return this; }
From source file:br.msf.commons.text.EnhancedStringBuilder.java
public EnhancedStringBuilder subSequence(final int start, final int end) { int len = end - start; if (start < 0) { throw new StringIndexOutOfBoundsException(start); } else if (end > delegate.length()) { throw new StringIndexOutOfBoundsException(end); } else if (len < 0) { throw new StringIndexOutOfBoundsException(len); }/* w w w. j a va2s . c o m*/ final EnhancedStringBuilder builder = new EnhancedStringBuilder(len + 100); for (int i = start; i < end; i++) { builder.append(delegate.charAt(i)); } return builder; }
From source file:it.d4nguard.rgrpg.util.StringCompiler.java
/** * Gets the character at the specified index. * // w ww . ja va 2 s .co m * @see #setCharAt(int, char) * @see #deleteCharAt(int) * @param index * the index to retrieve, must be valid * @return the character at the index * @throws IndexOutOfBoundsException * if the index is invalid */ public char charAt(int index) { if (index < 0 || index >= length()) { throw new StringIndexOutOfBoundsException(index); } return buffer[index]; }