Methods Summary |
---|
public static int[] | byteArrayToIntArray(byte[] source)Creates an array of int values from a given
byte array. Every four sequential one-byte values are
packed into one int value.
Caution: initial array's length must be a multiple of 4.
int[] output = new int[source.length >> 2];
for (int i = 0, j = 0; i < source.length; i += 4, ++j) {
output[j] = ((source[i] & 0xff) << 24) |
((source[i + 1] & 0xff) << 16) |
((source[i + 2] & 0xff) << 8) |
source[i + 3] & 0xff;
}
return output;
|
public static short[] | byteArrayToShortArray(byte[] source)Creates an array of short values from a given
byte array. Every two sequential one-byte values are
packed into one short value.
Caution: initial array must have even length.
short[] output = new short[source.length >> 1];
for (int i = 0, j = 0; i < source.length; i += 2, ++j) {
output[j] = (short)(((source[i] & 0xff) << 8) |
source[i + 1] & 0xff);
}
return output;
|
private static java.lang.String | extractElement(java.lang.String input)
String trimmed = input.trim();
int length = trimmed.length();
if ((length >= 2) && (trimmed.charAt(0) == '"") &&
(trimmed.charAt(length - 1) == '"")) {
return trimmed.substring(1, length - 1);
}
return trimmed;
|
public static java.lang.String | getParentLocale(java.lang.String locale)Returns parent for the given locale. Parent locale is obtained by removing
the last component of locale code, which is in form:
<language>-<country>-<variant>. Parent locale for
<language> is empty string.
if (locale == null) {
return null;
}
int len = locale.length();
if (len == 0) {
return null;
}
if (len > 6) {
return locale.substring(0, 5);
}
if (len > 3) {
return locale.substring(0, 2);
}
return "";
|
public static int | indexInSupportedLocales(java.lang.String locale, java.lang.String[] locales)Get an index of the given locale in array of locales returned from any
of getSupportedLocales methods (e.g.
{@link javax.microedition.global.ResourceManager#getSupportedLocales}).
if (locale == null || locales == null || locales.length == 0) {
return -1;
}
for (int i = 0; i < locales.length; i++) {
if (locale.equals(locales[i])) {
return i;
}
}
return -1;
|
public static boolean | isValidLocale(java.lang.String locale)Checks whether given locale is valid or not according to
JSR 238 specification, i.e. is in form of
<language>-<country>-<variant>.
Restrictions apply to length and
validity of characters of language part, country part and separators.
No checking of variant is performed.
if (locale == null) {
// Null locale is acceptable according to MIDP 2.0.
return true;
}
int len = locale.length();
if (len == 0) {
return true;
}
if (len < 2) {
// Language part, if present, must be 2 characters long.
return false;
}
char ch = locale.charAt(0);
if (ch < 'a" || ch > 'z") {
return false;
}
ch = locale.charAt(1);
if (ch < 'a" || ch > 'z") {
return false;
}
if (len > 2) {
if (len < 5 || len == 6) {
// Country part, if present, must be 2 characters long.
return false;
}
ch = locale.charAt(2);
if (ch != '-" && ch != '_") {
return false;
}
ch = locale.charAt(3);
if (ch < 'A" || ch > 'Z") {
return false;
}
ch = locale.charAt(4);
if (ch < 'A" || ch > 'Z") {
return false;
}
if (len > 6) {
ch = locale.charAt(5);
if (ch != '-" && ch != '_") {
return false;
}
}
}
return true;
|
public static java.lang.String | normalizeLocale(java.lang.String locale)Replaces characters (expected dashes or underscores) on appropriate
positions of locale code by dashes. The resulting locale name is likely
to conform with MIDP 2.0 specification.
if (locale == null) {
return null;
}
int len = locale.length();
if (len > 3) {
locale = locale.substring(0, 2) + '-" + locale.substring(3);
if (len > 6) {
locale = locale.substring(0, 5) + '-" + locale.substring(6);
}
}
return locale;
|
public static java.lang.String[] | splitString(java.lang.String input, java.lang.String separator, int limit)Splits the given string into parts according to the given separator. It
stops parsing the string after the first limit parts are
extracted. If limit equals -1 all parts are
extracted.
int index = input.indexOf(separator);
int count = 1;
// get the count of elements
while (index >= 0) {
++count;
index = input.indexOf(separator, index + 1);
}
if ((limit != -1) && (count > limit)) {
count = limit;
}
// create array for elements
String[] elements = new String[count];
splitString(elements, input, separator, limit);
return elements;
|
public static int | splitString(java.lang.String[] elements, java.lang.String input, java.lang.String separator, int limit)Splits the given string into parts according to the given separator. It
stops parsing the string after the first limit parts are
extracted. If limit equals -1 all parts are
extracted.
int lastIndex = -1;
int index = input.indexOf(separator);
int count = 0;
if ((limit == -1) || (limit > elements.length)) {
limit = elements.length;
}
if (limit == 0) {
return 0;
}
while (index >= 0) {
elements[count++] = extractElement(input.substring(lastIndex + 1,
index));
if (count == limit) {
return count;
}
lastIndex = index;
index = input.indexOf(separator, lastIndex + 1);
}
elements[count++] = extractElement(input.substring(lastIndex + 1,
input.length()));
return count;
|