Skip to content

Commit

Permalink
antstyle check
Browse files Browse the repository at this point in the history
  • Loading branch information
hwrdch committed Dec 9, 2017
1 parent b0b9ccc commit a867e28
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions python/common/org/python/types/Str.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public org.python.Object __getitem__(org.python.Object index) {
throw new org.python.exceptions.IndexError("string index out of range");
} else {
if (slice) {
if (this.value.length() < 2){
if (this.value.length() < 2) {
throw new org.python.exceptions.IndexError("string index out of range");
} else {
sliced = this.value.substring(1, 2);
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public org.python.Object rpartition(org.python.types.Object sep) {
"is a separator.\n",
default_args = {"sep", "maxsplit"}
)
public org.python.Object rsplit(org.python.Object sep, org.python.Object maxsplit ) {
public org.python.Object rsplit(org.python.Object sep, org.python.Object maxsplit) {
if (this.value.isEmpty()) { //handles empty strings
if (sep == null) {
if (maxsplit == null || maxsplit instanceof org.python.types.Int) {
Expand Down Expand Up @@ -1380,13 +1380,13 @@ public org.python.Object rsplit(org.python.Object sep, org.python.Object maxspli
}

org.python.types.List result_list = new org.python.types.List();
if (wspace == true) { //handles whitespace delimiters (default case)
if (wspace) { //handles whitespace delimiters (default case)
value = value.replaceAll("\\s++$", ""); //trim trailing spaces
int temp = value.length()-1, j=value.length()-1;
int temp = value.length() - 1, j = value.length() - 1;
int count = 0, number = 0;
for (int i = 0; i < value.length(); i++) { //count number of whitespace sequences
if (value.charAt(i) == ' ') {
while(value.charAt(i) == ' ') {
while (value.charAt(i) == ' ') {
i++;
}
count++;
Expand All @@ -1412,27 +1412,25 @@ public org.python.Object rsplit(org.python.Object sep, org.python.Object maxspli
temp = j;
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(sb.toString()));
break;
}
else {
} else {
sb.insert(0, value.charAt(j));
}
}
}
if (j != 0) {
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(0,j+1)));
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(0, j + 1)));
}
}
else { //handles non-whitespace and non-default whitespace delimiters (Ex. rsplit("e",12) rsplit(" ",2))
} else { //handles non-whitespace and non-default whitespace delimiters (Ex. rsplit("e",12) rsplit(" ",2))
int lastIndex = 0, count = 0, number = 0;
while(lastIndex != -1) {
lastIndex = value.indexOf(sepStr,lastIndex);
if(lastIndex != -1) {
count ++;
while (lastIndex != -1) {
lastIndex = value.indexOf(sepStr, lastIndex);
if (lastIndex != -1) {
count++;
lastIndex += sepStr.length();
}
}
if (count == 0) {
result_list.insert(new org.python.types.Int(0),new org.python.types.Str(value)); //if no matches found, simply return array containing original string
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value)); //if no matches found, simply return array containing original string
} else {
int numEnd = 0;
if (maxsplit != null && java.lang.Integer.parseInt(maxsplit.toString()) >= 0) {
Expand All @@ -1446,20 +1444,20 @@ public org.python.Object rsplit(org.python.Object sep, org.python.Object maxspli
int temp = value.length(), j = 0;
for (int i = number; i > numEnd; i--) {
for (j = temp; j >= 0; j--) {
if (value.substring(j,temp).contains(sepStr)) {
if (value.substring(j, temp).contains(sepStr)) {
if (i == 0) { //prevent going over string bounds
result_list.insert(new org.python.types.Int(0),new org.python.types.Str(value.substring(j+sepStr.length(),value.length())));
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(j + sepStr.length(), value.length())));
temp = j;
j--;
} else {
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(j+sepStr.length(),temp)));
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(j + sepStr.length(), temp)));
temp = j;
}
break;
}
}
}
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(0,j)));
result_list.insert(new org.python.types.Int(0), new org.python.types.Str(value.substring(0, j)));
}
return result_list;
}
Expand Down

0 comments on commit a867e28

Please sign in to comment.