QuoteHelper.java

 1package eu.siacs.conversations.ui.util;
 2
 3import eu.siacs.conversations.Config;
 4import eu.siacs.conversations.utils.UIHelper;
 5
 6public class QuoteHelper {
 7
 8    public static boolean isPositionQuoteCharacter(CharSequence body, int pos){
 9        return body.charAt(pos) == '>';
10    }
11
12    public static boolean isPositionFollowedByQuoteChar(CharSequence body, int pos) {
13        return body.length() > pos + 1 && isPositionQuoteCharacter(body, pos +1 );
14    }
15
16    // 'Prequote' means anything we require or can accept in front of a QuoteChar
17    public static boolean isPositionPrecededByPrequote(CharSequence body, int pos){
18        return UIHelper.isPositionPrecededByLineStart(body, pos);
19    }
20
21    public static boolean isPositionQuoteStart (CharSequence body, int pos){
22        return isPositionQuoteCharacter(body, pos)
23                && isPositionPrecededByPrequote(body, pos)
24                && (UIHelper.isPositionFollowedByWhitespace(body, pos)
25                    || isPositionFollowedByQuoteChar(body, pos));
26    }
27
28    public static boolean bodyContainsQuoteStart (CharSequence body){
29       for (int i = 0; i < body.length(); i++){
30            if (isPositionQuoteStart(body, i)){
31                return true;
32            }
33        }
34        return false;
35    }
36
37    public static boolean isNestedTooDeeply (CharSequence line){
38        if (isPositionQuoteCharacter(line, 0)) {
39            int nestingDepth = 1;
40            for (int i = 1; i < line.length(); i++) {
41                if (isPositionQuoteCharacter(line, i)) {
42                    nestingDepth++;
43                }
44                if (nestingDepth > (Config.QUOTING_MAX_DEPTH - 1)) {
45                    return true;
46                }
47            }
48        }
49        return false;
50    }
51}