blob: 8fa24988d8ceec3a9869e04d6965c262b42d47d4 (
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
49
50
|
package it.niedermann.nextcloud.deck.ui.card.comments.util;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
public class CommentsUtil {
@Nullable
public static Pair<String, Integer> getUserNameForMentionProposal(String text, int cursorPosition) {
Pair<String, Integer> 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;
}
}
|