TextUtilities { public static String prefix(String s, int count) { if (s == null) { return null; } if (s.length() < count) { return s; } return s.substring(0, count); }  static String shadowNumbers(String string); @Deprecated static List<LayoutToken> dehyphenize(List<LayoutToken> tokens); static String dehyphenize(String text); static String getLastToken(String section); static String getFirstToken(String section); @Deprecated static String dehyphenizeHard(String text); static int getLevenshteinDistance(String s, String t); final static void appendN(StringBuffer buffer, char c, int nb); final static String removeAccents(String input); final static String cleanField(String input0, boolean applyStopwordsFilter); final static List<String> segment(String input, String segments); static String HTMLEncode(String string); static String HTMLEncode(String string, boolean fullHTML); static String normalizeRegex(String string); static String convertStreamToString(InputStream is); static int countDigit(String text); static String clean(String token); static String formatTwoDecimals(double d); static String formatFourDecimals(double d); static boolean isAllUpperCase(String text); static boolean isAllLowerCase(String text); static List<String> generateEmailVariants(String firstName, String lastName); static String capitalizeFully(String input, String delimiters); static String wordShape(String word); static String wordShapeTrimmed(String word); static String punctuationProfile(String line); static int getNbTokens(String line, int currentLinePos, List<String> tokenization); static String trimEncodedCharaters(String string); static boolean filterLine(String line); static StringBuilder replaceAll(StringBuilder sb, String regex, String replacement); static String prefix(String s, int count); static String suffix(String s, int count); static String JSONEncode(String json); static String strrep(char c, int times); static int getOccCount(String term, String string); static boolean test_digit(String tok); static boolean isAllUpperCaseOrDigitOrDot(String text); static final String punctuations; static final String fullPunctuations; static final String restrictedPunctuations; static String delimiters; static final String OR; static final String NEW_LINE; static final String SPACE; static final String COMMA; static final String QUOTE; static final String END_BRACKET; static final String START_BRACKET; static final String SHARP; static final String COLON; static final String DOUBLE_QUOTE; static final String ESC_DOUBLE_QUOTE; static final String LESS_THAN; static final String ESC_LESS_THAN; static final String GREATER_THAN; static final String ESC_GREATER_THAN; static final String AND; static final String ESC_AND; static final String SLASH; static final Pattern ORCIDPattern; static final Pattern DOIPattern; static final Pattern arXivPattern; static final Pattern pmidPattern; static final Pattern pmcidPattern; static final Pattern urlPattern; static final Pattern emailPattern; final static List<String> stopwords; }
@Test public void testPrefix() { String word = "Grobid"; assertEquals("", TextUtilities.prefix(word, 0)); assertEquals("G", TextUtilities.prefix(word, 1)); assertEquals("Gr", TextUtilities.prefix(word, 2)); assertEquals("Gro", TextUtilities.prefix(word, 3)); assertEquals("Grob", TextUtilities.prefix(word, 4)); assertEquals("Grobid", TextUtilities.prefix(word, 6)); assertEquals("Grobid", TextUtilities.prefix(word, 100)); assertEquals(null, TextUtilities.prefix(null, 0)); assertEquals(null, TextUtilities.prefix(null, 1)); }