feat(gui): search in resource files (#347) (#1032) (PR #1108)

Co-authored-by: tobias <tobias.hotmail.com>
This commit is contained in:
LBJ-the-GOAT
2021-01-31 00:34:20 +08:00
committed by GitHub
parent c93e7fb9cd
commit c774ffc979
19 changed files with 546 additions and 23 deletions
@@ -256,6 +256,56 @@ public class StringUtils {
return count;
}
/**
* returns how many lines does it have between start to pos in content.
*/
public static int countLinesByPos(String content, int pos, int start) {
if (start >= pos) {
return 0;
}
int count = 0;
int tempPos = start;
do {
tempPos = content.indexOf("\n", tempPos);
if (tempPos == -1) {
break;
}
if (tempPos >= pos) {
break;
}
count += 1;
tempPos += 1;
} while (tempPos < content.length());
return count;
}
/**
* returns lines that contain pos to end if end is not -1.
*/
public static String getLine(String content, int pos, int end) {
if (pos >= content.length()) {
return "";
}
if (end != -1) {
if (end > content.length()) {
end = content.length() - 1;
}
} else {
end = pos + 1;
}
// get to line head
int headPos = content.lastIndexOf("\n", pos);
if (headPos == -1) {
headPos = 0;
}
// get to line end
int endPos = content.indexOf("\n", end);
if (endPos == -1) {
endPos = content.length();
}
return content.substring(headPos, endPos);
}
public static boolean isWhite(char chr) {
return WHITES.indexOf(chr) != -1;
}