@Test public void testExtractSecondOfTwoHashtags() { String content = "Did you know that #potatoes are made of #frenchfries?"; Substring expectedResult = new Substring(9 * 4 + 4, 9 + 3, "#frenchfries"); assertTrue(IsEqualInternally.areEqualInternally(expectedResult, sut.extract(content, 9 * 2 + 1))); assertTrue(IsEqualInternally.areEqualInternally(expectedResult, sut.extract(content, 9 * 2 + 7))); assertTrue(IsEqualInternally.areEqualInternally(expectedResult, sut.extract(content, 9 * 3 + 3))); assertTrue(IsEqualInternally.areEqualInternally(expectedResult, sut.extract(content, 9 * 4 + 3))); assertTrue(IsEqualInternally.areEqualInternally(expectedResult, sut.extract(content, 9 * 4 + 4))); }
public Substring extract(final String content, final int inStartingIndex) { if (content == null || content.length() == 0 || content.indexOf('#') == -1) { return null; } int pos = inStartingIndex; int hashPos = -1; int contentLength = content.length(); while ((hashPos = content.indexOf('#', pos)) > -1) { if (hashPos == 0 || (isValidCharBeforeHashtag(content.charAt(hashPos - 1)) && !isInAUrl(content, hashPos) && !isInHrefBlock(content, hashPos))) { pos = hashPos + 1; char nextChar; while (pos < contentLength) { nextChar = content.charAt(pos); if (!isValidHashTagCharacter(nextChar)) { break; } pos++; } if (pos > hashPos + 1) { return new Substring(hashPos, pos - hashPos, content.substring(hashPos, pos)); } } else { pos = hashPos + 1; } } return null; }
HashTagExtractor { public Substring extract(final String content, final int inStartingIndex) { if (content == null || content.length() == 0 || content.indexOf('#') == -1) { return null; } int pos = inStartingIndex; int hashPos = -1; int contentLength = content.length(); while ((hashPos = content.indexOf('#', pos)) > -1) { if (hashPos == 0 || (isValidCharBeforeHashtag(content.charAt(hashPos - 1)) && !isInAUrl(content, hashPos) && !isInHrefBlock(content, hashPos))) { pos = hashPos + 1; char nextChar; while (pos < contentLength) { nextChar = content.charAt(pos); if (!isValidHashTagCharacter(nextChar)) { break; } pos++; } if (pos > hashPos + 1) { return new Substring(hashPos, pos - hashPos, content.substring(hashPos, pos)); } } else { pos = hashPos + 1; } } return null; } }
HashTagExtractor { public Substring extract(final String content, final int inStartingIndex) { if (content == null || content.length() == 0 || content.indexOf('#') == -1) { return null; } int pos = inStartingIndex; int hashPos = -1; int contentLength = content.length(); while ((hashPos = content.indexOf('#', pos)) > -1) { if (hashPos == 0 || (isValidCharBeforeHashtag(content.charAt(hashPos - 1)) && !isInAUrl(content, hashPos) && !isInHrefBlock(content, hashPos))) { pos = hashPos + 1; char nextChar; while (pos < contentLength) { nextChar = content.charAt(pos); if (!isValidHashTagCharacter(nextChar)) { break; } pos++; } if (pos > hashPos + 1) { return new Substring(hashPos, pos - hashPos, content.substring(hashPos, pos)); } } else { pos = hashPos + 1; } } return null; }  }
HashTagExtractor { public Substring extract(final String content, final int inStartingIndex) { if (content == null || content.length() == 0 || content.indexOf('#') == -1) { return null; } int pos = inStartingIndex; int hashPos = -1; int contentLength = content.length(); while ((hashPos = content.indexOf('#', pos)) > -1) { if (hashPos == 0 || (isValidCharBeforeHashtag(content.charAt(hashPos - 1)) && !isInAUrl(content, hashPos) && !isInHrefBlock(content, hashPos))) { pos = hashPos + 1; char nextChar; while (pos < contentLength) { nextChar = content.charAt(pos); if (!isValidHashTagCharacter(nextChar)) { break; } pos++; } if (pos > hashPos + 1) { return new Substring(hashPos, pos - hashPos, content.substring(hashPos, pos)); } } else { pos = hashPos + 1; } } return null; }  Substring extract(final String content, final int inStartingIndex); List<String> extractAll(final String content); }
HashTagExtractor { public Substring extract(final String content, final int inStartingIndex) { if (content == null || content.length() == 0 || content.indexOf('#') == -1) { return null; } int pos = inStartingIndex; int hashPos = -1; int contentLength = content.length(); while ((hashPos = content.indexOf('#', pos)) > -1) { if (hashPos == 0 || (isValidCharBeforeHashtag(content.charAt(hashPos - 1)) && !isInAUrl(content, hashPos) && !isInHrefBlock(content, hashPos))) { pos = hashPos + 1; char nextChar; while (pos < contentLength) { nextChar = content.charAt(pos); if (!isValidHashTagCharacter(nextChar)) { break; } pos++; } if (pos > hashPos + 1) { return new Substring(hashPos, pos - hashPos, content.substring(hashPos, pos)); } } else { pos = hashPos + 1; } } return null; }  Substring extract(final String content, final int inStartingIndex); List<String> extractAll(final String content);  }