projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Extract functions to detect long-enough links.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
text
/
SoneTextParser.java
diff --git
a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
index
d41a7e2
..
efb36c4
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
+++ b/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
@@
-207,7
+207,7
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
}
if (linkType == LinkType.SONE) {
}
if (linkType == LinkType.SONE) {
- if (line
.length() >= (7 + 43
)) {
+ if (line
IsLongEnoughToContainASoneLink(line
)) {
String soneId = line.substring(7, 50);
Optional<Sone> sone = database.getSone(soneId);
if (!sone.isPresent()) {
String soneId = line.substring(7, 50);
Optional<Sone> sone = database.getSone(soneId);
if (!sone.isPresent()) {
@@
-226,7
+226,7
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
continue;
}
if (linkType == LinkType.POST) {
continue;
}
if (linkType == LinkType.POST) {
- if (line
.length() >= (7 + 36
)) {
+ if (line
IsLongEnoughToContainAPostLink(line
)) {
String postId = line.substring(7, 43);
Optional<Post> post = database.getPost(postId);
if (post.isPresent()) {
String postId = line.substring(7, 43);
Optional<Post> post = database.getPost(postId);
if (post.isPresent()) {
@@
-316,6
+316,14
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
return (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId());
}
return (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId());
}
+ private boolean lineIsLongEnoughToContainAPostLink(String line) {
+ return line.length() >= (7 + 36);
+ }
+
+ private boolean lineIsLongEnoughToContainASoneLink(String line) {
+ return line.length() >= (7 + 43);
+ }
+
private int findNextWhitespace(String line) {
Matcher matcher = whitespacePattern.matcher(line);
return matcher.find(0) ? matcher.start() : line.length();
private int findNextWhitespace(String line) {
Matcher matcher = whitespacePattern.matcher(line);
return matcher.find(0) ? matcher.start() : line.length();