Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CommentsUtil.java « util « comments « card « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5251291c84f94469a3a0e473039a4ed13004c4b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package it.niedermann.nextcloud.deck.ui.card.comments.util;


import androidx.core.util.Pair;

public class CommentsUtil {

    public static Pair<String, Integer> getUserNameForMentionProposal(String text, int cursorPosition) {
        Pair result = null;

        if (text != null) {
            // find start of relevant substring
            int cursor = cursorPosition;
            if (cursor < 1) {
                return null;
            }
            int start = 0;
            while (cursor > 0) {
                cursor--;
                if (Character.isWhitespace(text.charAt(cursor))) {
                    start = cursor + 1;
                    break;
                }
            }
            if (text.length()-1 < start || text.charAt(start) != '@') {
                return null;
            }

            // find end of relevant substring
            cursor = cursorPosition;
            int textLength = text.length();
            int end = textLength;
            while (cursor < textLength) {
                if (Character.isWhitespace(text.charAt(cursor))) {
                    end = cursor;
                    break;
                }
                cursor++;
            }

            start++;
            result = Pair.create(text.substring(start, end), start);

        }

        return result;
    }
}