Top Description Inners Fields Constructors Methods
de.undercouch.citeproc.helper

public Class StringHelper

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .Comparator, .List, .Locale, java.util.regex.Matcher, .Pattern

Helper methods related to Strings
Author
Michel Kraemer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final char[]
HEX_DIGITS

Hexadecimal characters

private static final Pattern
private static final Pattern
private static final String
TITLECASE_STOPWORD_FOLLOWEDBY

Words that should not converted to title-case See stop-words.json

private static final Pattern[]
private static final String
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

if the string contains only latin, common, or inherited characters
containsLatinScriptOnly
(String
the string to check
s
)

Check if a string contains no other characters than those from the Unicode scripts "Latin", "Common", or "Inherited"

public static String

Returns:

the escpaped string
escapeJava
(String
the string to escape
s
)

Escapes characters in the given string according to Java rules

private static String

Returns:

the string
hex4
(char
the character to convert
c
)

Converts the given character to a four-digit hexadecimal string

public static String

Returns:

the converted name
initializeName
(String
the name to convert
name
,
String
the string to append to each initial
initializeWith
)

Parse the given name, split it into parts, and convert them to initials

public static String

Returns:

the converted name
initializeName
(String
the name to convert
name
,
String
the string to append to each initial
initializeWith
,
boolean
true if only existing initials should be normalized and uninitialized names should be kept as is
onlyNormalize
)

Parse the given name, split it into parts, and either convert them all to initials or only normalize existing initials

private static boolean

Returns:

true if the string contains only uppercase characters
isAllUppercase
(String
the string
s
)

Check if all characters in the given string are uppercase

public static int

Returns:

the number of overlapping characters
overlap
(CharSequence
the first string
a
,
CharSequence
the second string
b
)

Calculates how many characters overlap between a and b, i.e. how many characters at the end of a are equal to the ones at the beginning of b.

public static String

Returns:

the sanitized string
sanitize
(String
the string to sanitize
s
)

Sanitizes a string so it can be used as an identifier

private static boolean

Returns:

true if the string should be capitalized
shouldCapitalize
(String
the string
s
)

Check if a string should be capitalized

private static boolean
private static boolean

Returns:

true if the letters in the given string are all uppercase
titleAllUppercase
(String
the string
s
)

Check if all letters in the given string are uppercase

public static String

Returns:

the converted string
toTitleCase
(String
the string to convert
str
)

Converts the words in a given string to title case (according to the CSL specification)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEX_DIGITSback to summary
private static final char[] HEX_DIGITS

Hexadecimal characters

MAIL_PATTERNback to summary
private static final Pattern MAIL_PATTERN

Based on Markdown by John Gruber (https://daringfireball.net/projects/markdown/). Released under a BSD-style license.

POSSESSIVE_S_PATTERNback to summary
private static final Pattern POSSESSIVE_S_PATTERN
TITLECASE_STOPWORD_FOLLOWEDBYback to summary
private static final String TITLECASE_STOPWORD_FOLLOWEDBY

Words that should not converted to title-case See stop-words.json

TITLECASE_STOPWORD_PATTERNSback to summary
private static final Pattern[] TITLECASE_STOPWORD_PATTERNS
TLDsback to summary
private static final String TLDs

Based on John Gruber's URL regex (https://gist.github.com/gruber/8891611 or https://daringfireball.net/2010/07/improved_regex_for_matching_urls) released under public domain. Slightly simplified.

URL_PATTERNback to summary
private static final Pattern URL_PATTERN
WORD_PATTERNback to summary
private static final Pattern WORD_PATTERN

Constructor Detail

StringHelperback to summary
public StringHelper()

Method Detail

containsLatinScriptOnlyback to summary
public static boolean containsLatinScriptOnly(String s)

Check if a string contains no other characters than those from the Unicode scripts "Latin", "Common", or "Inherited"

Parameters
s:String

the string to check

Returns:boolean

if the string contains only latin, common, or inherited characters

escapeJavaback to summary
public static String escapeJava(String s)

Escapes characters in the given string according to Java rules

Parameters
s:String

the string to escape

Returns:String

the escpaped string

hex4back to summary
private static String hex4(char c)

Converts the given character to a four-digit hexadecimal string

Parameters
c:char

the character to convert

Returns:String

the string

initializeNameback to summary
public static String initializeName(String name, String initializeWith)

Parse the given name, split it into parts, and convert them to initials

Parameters
name:String

the name to convert

initializeWith:String

the string to append to each initial

Returns:String

the converted name

initializeNameback to summary
public static String initializeName(String name, String initializeWith, boolean onlyNormalize)

Parse the given name, split it into parts, and either convert them all to initials or only normalize existing initials

Parameters
name:String

the name to convert

initializeWith:String

the string to append to each initial

onlyNormalize:boolean

true if only existing initials should be normalized and uninitialized names should be kept as is

Returns:String

the converted name

isAllUppercaseback to summary
private static boolean isAllUppercase(String s)

Check if all characters in the given string are uppercase

Parameters
s:String

the string

Returns:boolean

true if the string contains only uppercase characters

overlapback to summary
public static int overlap(CharSequence a, CharSequence b)

Calculates how many characters overlap between a and b, i.e. how many characters at the end of a are equal to the ones at the beginning of b.

Examples:

overlap("abcd", "cdef")     = 2
overlap("abcd", "xyz")      = 0
overlap("a", "a")           = 1
overlap("ab", "b")          = 1
overlap("abcd", "bcdefg")   = 3
overlap("", "a")            = 0
overlap("a", "")            = 0
Parameters
a:CharSequence

the first string

b:CharSequence

the second string

Returns:int

the number of overlapping characters

sanitizeback to summary
public static String sanitize(String s)

Sanitizes a string so it can be used as an identifier

Parameters
s:String

the string to sanitize

Returns:String

the sanitized string

shouldCapitalizeback to summary
private static boolean shouldCapitalize(String s)

Check if a string should be capitalized

Parameters
s:String

the string

Returns:boolean

true if the string should be capitalized

shouldStopwordLowercaseback to summary
private static boolean shouldStopwordLowercase(String w, String str)
titleAllUppercaseback to summary
private static boolean titleAllUppercase(String s)

Check if all letters in the given string are uppercase

Parameters
s:String

the string

Returns:boolean

true if the letters in the given string are all uppercase

toTitleCaseback to summary
public static String toTitleCase(String str)

Converts the words in a given string to title case (according to the CSL specification)

Parameters
str:String

the string to convert

Returns:String

the converted string

de.undercouch.citeproc.helper back to summary

private Class StringHelper.NamePart

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final boolean
pack-priv final String

Constructor Summary

AccessConstructor and Description
pack-priv
NamePart(String part, boolean hyphen, boolean alreadyInitialized)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alreadyInitializedback to summary
pack-priv final boolean alreadyInitialized
hyphenback to summary
pack-priv final boolean hyphen
partback to summary
pack-priv final String part

Constructor Detail

NamePartback to summary
pack-priv NamePart(String part, boolean hyphen, boolean alreadyInitialized)