mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-29 22:04:25 +02:00
minimise regex usage
This commit is contained in:
parent
3a5e7087a8
commit
3fe4526122
@ -2064,7 +2064,11 @@
|
||||
}
|
||||
}
|
||||
private boolean parseLocaleScriptVariant(String qualifier){
|
||||
if(qualifier==null){
|
||||
if(qualifier == null || qualifier.length() < 4 ){
|
||||
return false;
|
||||
}
|
||||
char[] chars = qualifier.toCharArray();
|
||||
if(chars[0] != 'b' || chars[1] != '+'){
|
||||
return false;
|
||||
}
|
||||
Matcher matcher = PATTERN_LOCALE_SCRIPT_VARIANT.matcher(qualifier);
|
||||
@ -2099,11 +2103,7 @@
|
||||
}
|
||||
}
|
||||
private boolean parseLanguage(String qualifier){
|
||||
if(qualifier==null){
|
||||
return false;
|
||||
}
|
||||
Matcher matcher = PATTERN_LANGUAGE.matcher(qualifier);
|
||||
if(!matcher.matches()){
|
||||
if(!isLanguage(qualifier)){
|
||||
return false;
|
||||
}
|
||||
this.mConfig.setLanguage(qualifier);
|
||||
@ -2122,11 +2122,7 @@
|
||||
}
|
||||
}
|
||||
private boolean parseRegion(String qualifier){
|
||||
if(qualifier==null){
|
||||
return false;
|
||||
}
|
||||
Matcher matcher = PATTERN_REGION.matcher(qualifier);
|
||||
if(!matcher.matches() && !isRegionNumber(qualifier)){
|
||||
if(!isRegion(qualifier)){
|
||||
return false;
|
||||
}
|
||||
this.mConfig.setRegion(qualifier);
|
||||
@ -2167,30 +2163,64 @@
|
||||
}
|
||||
return text;
|
||||
}
|
||||
private static boolean isLanguage(String qualifier){
|
||||
if(qualifier == null){
|
||||
return false;
|
||||
}
|
||||
char[] chars = qualifier.toCharArray();
|
||||
int length = chars.length;
|
||||
if(length != 2 && length !=3 ){
|
||||
return false;
|
||||
}
|
||||
for(int i = 0; i < length; i++){
|
||||
if(!isAtoZLower(chars[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static boolean isRegion(String qualifier){
|
||||
if(qualifier == null || qualifier.length() != 3){
|
||||
return false;
|
||||
}
|
||||
char[] chars = qualifier.toCharArray();
|
||||
boolean checkDigit = false;
|
||||
for(int i = 0; i < chars.length; i++){
|
||||
char ch = chars[i];
|
||||
if(i == 0){
|
||||
if(ch == 'r'){
|
||||
continue;
|
||||
}
|
||||
checkDigit = isDigit(ch);
|
||||
if(checkDigit){
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(checkDigit){
|
||||
if(!isDigit(ch)){
|
||||
return false;
|
||||
}
|
||||
}else if(!isAtoZUpper(ch)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static String[] splitQualifiers(String qualifier){
|
||||
if(qualifier == null || qualifier.length() == 0){
|
||||
return null;
|
||||
}
|
||||
return qualifier.split("-");
|
||||
}
|
||||
private static boolean isRegionNumber(String qualifier){
|
||||
if(qualifier==null || qualifier.length()==0){
|
||||
return false;
|
||||
private static boolean isDigit(char ch){
|
||||
return ch <= '9' && ch >= '0';
|
||||
}
|
||||
return qualifier.length() == 3 && isAllDigit(qualifier);
|
||||
private static boolean isAtoZLower(char ch){
|
||||
return ch <= 'z' && ch >= 'a';
|
||||
}
|
||||
private static boolean isAllDigit(String qualifier){
|
||||
if(qualifier == null || qualifier.length()==0){
|
||||
return false;
|
||||
}
|
||||
char[] chars = qualifier.toCharArray();
|
||||
for(int i = 0; i < chars.length; i++){
|
||||
char ch = chars[i];
|
||||
if(ch > '9' || ch < '0'){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
private static boolean isAtoZUpper(char ch){
|
||||
return ch <= 'Z' && ch >= 'A';
|
||||
}
|
||||
|
||||
private static final Pattern PATTERN_PREFIX_NUMBER = Pattern.compile("^([mcnv]+)([0-9]+)$");
|
||||
@ -2198,8 +2228,6 @@
|
||||
private static final Pattern PATTERN_WIDTH_HEIGHT = Pattern.compile("^([0-9]+)[xX]([0-9]+)$");
|
||||
private static final Pattern PATTERN_LOCALE_NUMBERING_SYSTEM = Pattern.compile("^u\\+nu\\+(.{1,8})$");
|
||||
private static final Pattern PATTERN_LOCALE_SCRIPT_VARIANT = Pattern.compile("^b(\\+[a-z]{2})?(\\+r[A-Z]{2})?(\\+[A-Z][a-z]{3})?(\\+[A-Z]{2,8})?$");
|
||||
private static final Pattern PATTERN_LANGUAGE = Pattern.compile("^[a-z]{2}$");
|
||||
private static final Pattern PATTERN_REGION = Pattern.compile("^r[A-Z]{2}$");
|
||||
}
|
||||
|
||||
public static final int SIZE_16 = 16;
|
||||
|
Loading…
x
Reference in New Issue
Block a user