fixed IndexOutOfBounds when rendering quotes
This commit is contained in:
parent
226eb739bd
commit
ba4a47204b
|
@ -370,9 +370,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
char current = body.length() > i ? body.charAt(i) : '\n';
|
||||
if (lineStart == -1) {
|
||||
if (previous == '\n') {
|
||||
if (
|
||||
QuoteHelper.isPositionQuoteStart(body, i)
|
||||
) {
|
||||
if (i < body.length() && QuoteHelper.isPositionQuoteStart(body, i)) {
|
||||
// Line start with quote
|
||||
lineStart = i;
|
||||
if (quoteStart == -1) quoteStart = i;
|
||||
|
@ -806,12 +804,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
} else if (message.treatAsDownloadable()) {
|
||||
try {
|
||||
final URI uri = new URI(message.getBody());
|
||||
displayDownloadableMessage(viewHolder,
|
||||
message,
|
||||
activity.getString(R.string.check_x_filesize_on_host,
|
||||
UIHelper.getFileDescriptionString(activity, message),
|
||||
uri.getHost()),
|
||||
darkBackground);
|
||||
displayDownloadableMessage(viewHolder,
|
||||
message,
|
||||
activity.getString(R.string.check_x_filesize_on_host,
|
||||
UIHelper.getFileDescriptionString(activity, message),
|
||||
uri.getHost()),
|
||||
darkBackground);
|
||||
} catch (Exception e) {
|
||||
displayDownloadableMessage(viewHolder,
|
||||
message,
|
||||
|
|
|
@ -11,47 +11,47 @@ public class QuoteHelper {
|
|||
public static final char QUOTE_ALT_CHAR = '»';
|
||||
public static final char QUOTE_ALT_END_CHAR = '«';
|
||||
|
||||
public static boolean isPositionQuoteCharacter(CharSequence body, int pos){
|
||||
public static boolean isPositionQuoteCharacter(CharSequence body, int pos) {
|
||||
// second part of logical check actually goes against the logic indicated in the method name, since it also checks for context
|
||||
// but it's very useful
|
||||
return body.charAt(pos) == QUOTE_CHAR || isPositionAltQuoteStart(body, pos);
|
||||
}
|
||||
|
||||
public static boolean isPositionQuoteEndCharacter(CharSequence body, int pos){
|
||||
public static boolean isPositionQuoteEndCharacter(CharSequence body, int pos) {
|
||||
return body.charAt(pos) == QUOTE_END_CHAR;
|
||||
}
|
||||
|
||||
public static boolean isPositionAltQuoteCharacter (CharSequence body, int pos){
|
||||
public static boolean isPositionAltQuoteCharacter(CharSequence body, int pos) {
|
||||
return body.charAt(pos) == QUOTE_ALT_CHAR;
|
||||
}
|
||||
|
||||
public static boolean isPositionAltQuoteEndCharacter(CharSequence body, int pos){
|
||||
public static boolean isPositionAltQuoteEndCharacter(CharSequence body, int pos) {
|
||||
return body.charAt(pos) == QUOTE_ALT_END_CHAR;
|
||||
}
|
||||
|
||||
public static boolean isPositionAltQuoteStart(CharSequence body, int pos){
|
||||
public static boolean isPositionAltQuoteStart(CharSequence body, int pos) {
|
||||
return isPositionAltQuoteCharacter(body, pos) && !isPositionFollowedByAltQuoteEnd(body, pos);
|
||||
}
|
||||
|
||||
public static boolean isPositionFollowedByQuoteChar(CharSequence body, int pos) {
|
||||
return body.length() > pos + 1 && isPositionQuoteCharacter(body, pos +1 );
|
||||
return body.length() > pos + 1 && isPositionQuoteCharacter(body, pos + 1);
|
||||
}
|
||||
|
||||
// 'Prequote' means anything we require or can accept in front of a QuoteChar
|
||||
public static boolean isPositionPrecededByPrequote(CharSequence body, int pos){
|
||||
public static boolean isPositionPrecededByPreQuote(CharSequence body, int pos) {
|
||||
return UIHelper.isPositionPrecededByLineStart(body, pos);
|
||||
}
|
||||
|
||||
public static boolean isPositionQuoteStart (CharSequence body, int pos){
|
||||
public static boolean isPositionQuoteStart(CharSequence body, int pos) {
|
||||
return (isPositionQuoteCharacter(body, pos)
|
||||
&& isPositionPrecededByPrequote(body, pos)
|
||||
&& isPositionPrecededByPreQuote(body, pos)
|
||||
&& (UIHelper.isPositionFollowedByQuoteableCharacter(body, pos)
|
||||
|| isPositionFollowedByQuoteChar(body, pos)));
|
||||
|| isPositionFollowedByQuoteChar(body, pos)));
|
||||
}
|
||||
|
||||
public static boolean bodyContainsQuoteStart (CharSequence body){
|
||||
for (int i = 0; i < body.length(); i++){
|
||||
if (isPositionQuoteStart(body, i)){
|
||||
public static boolean bodyContainsQuoteStart(CharSequence body) {
|
||||
for (int i = 0; i < body.length(); i++) {
|
||||
if (isPositionQuoteStart(body, i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class QuoteHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNestedTooDeeply (CharSequence line){
|
||||
public static boolean isNestedTooDeeply(CharSequence line) {
|
||||
if (isPositionQuoteStart(line, 0)) {
|
||||
int nestingDepth = 1;
|
||||
for (int i = 1; i < line.length(); i++) {
|
||||
|
@ -91,9 +91,9 @@ public class QuoteHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static String replaceAltQuoteCharsInText(String text){
|
||||
for (int i = 0; i < text.length(); i++){
|
||||
if (isPositionAltQuoteStart(text, i)){
|
||||
public static String replaceAltQuoteCharsInText(String text) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (isPositionAltQuoteStart(text, i)) {
|
||||
text = text.substring(0, i) + QUOTE_CHAR + text.substring(i + 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue