in framework/src/main/java/org/osgi/framework/PackagePermission.java [234:327]
private static int parseActions(String actions) {
boolean seencomma = false;
int mask = ACTION_NONE;
if (actions == null) {
return mask;
}
char[] a = actions.toCharArray();
int i = a.length - 1;
if (i < 0)
return mask;
while (i != -1) {
char c;
// skip whitespace
while ((i != -1) && ((c = a[i]) == ' ' || c == '\r' || c == '\n' || c == '\f' || c == '\t'))
i--;
// check for the known strings
int matchlen;
if (i >= 5 && (a[i - 5] == 'i' || a[i - 5] == 'I')
&& (a[i - 4] == 'm' || a[i - 4] == 'M')
&& (a[i - 3] == 'p' || a[i - 3] == 'P')
&& (a[i - 2] == 'o' || a[i - 2] == 'O')
&& (a[i - 1] == 'r' || a[i - 1] == 'R')
&& (a[i] == 't' || a[i] == 'T')) {
matchlen = 6;
mask |= ACTION_IMPORT;
} else
if (i >= 5 && (a[i - 5] == 'e' || a[i - 5] == 'E')
&& (a[i - 4] == 'x' || a[i - 4] == 'X')
&& (a[i - 3] == 'p' || a[i - 3] == 'P')
&& (a[i - 2] == 'o' || a[i - 2] == 'O')
&& (a[i - 1] == 'r' || a[i - 1] == 'R')
&& (a[i] == 't' || a[i] == 'T')) {
matchlen = 6;
mask |= ACTION_EXPORT | ACTION_IMPORT;
} else {
if (i >= 9 && (a[i - 9] == 'e' || a[i - 9] == 'E')
&& (a[i - 8] == 'x' || a[i - 8] == 'X')
&& (a[i - 7] == 'p' || a[i - 7] == 'P')
&& (a[i - 6] == 'o' || a[i - 6] == 'O')
&& (a[i - 5] == 'r' || a[i - 5] == 'R')
&& (a[i - 4] == 't' || a[i - 4] == 'T')
&& (a[i - 3] == 'o' || a[i - 3] == 'O')
&& (a[i - 2] == 'n' || a[i - 2] == 'N')
&& (a[i - 1] == 'l' || a[i - 1] == 'L')
&& (a[i] == 'y' || a[i] == 'Y')) {
matchlen = 10;
mask |= ACTION_EXPORT;
} else {
// parse error
throw new IllegalArgumentException("invalid permission: " + actions);
}
}
// make sure we didn't just match the tail of a word
// like "ackbarfimport". Also, skip to the comma.
seencomma = false;
while (i >= matchlen && !seencomma) {
switch (a[i - matchlen]) {
case ',' :
seencomma = true;
/* FALLTHROUGH */
case ' ' :
case '\r' :
case '\n' :
case '\f' :
case '\t' :
break;
default :
throw new IllegalArgumentException("invalid permission: " + actions);
}
i--;
}
// point i at the location of the comma minus one (or -1).
i -= matchlen;
}
if (seencomma) {
throw new IllegalArgumentException("invalid permission: " + actions);
}
return mask;
}