in framework/src/main/java/org/osgi/framework/ServicePermission.java [257:334]
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 >= 2 && (a[i - 2] == 'g' || a[i - 2] == 'G')
&& (a[i - 1] == 'e' || a[i - 1] == 'E')
&& (a[i] == 't' || a[i] == 'T')) {
matchlen = 3;
mask |= ACTION_GET;
} else
if (i >= 7 && (a[i - 7] == 'r' || a[i - 7] == 'R')
&& (a[i - 6] == 'e' || a[i - 6] == 'E')
&& (a[i - 5] == 'g' || a[i - 5] == 'G')
&& (a[i - 4] == 'i' || a[i - 4] == 'I')
&& (a[i - 3] == 's' || a[i - 3] == 'S')
&& (a[i - 2] == 't' || a[i - 2] == 'T')
&& (a[i - 1] == 'e' || a[i - 1] == 'E')
&& (a[i] == 'r' || a[i] == 'R')) {
matchlen = 8;
mask |= ACTION_REGISTER;
} else {
// parse error
throw new IllegalArgumentException("invalid permission: " + actions);
}
// make sure we didn't just match the tail of a word
// like "ackbarfregister". 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;
}