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;
}
}
|