private static void processEmoticonsToRegex ( ) { List < String > emoticons = new ArrayList < String > ( ) ; for ( Emoji e : emojiData ) { if ( e . getEmoticons ( ) != null ) { emoticons . addAll ( e . getEmoticons ( ) ) ; } } //List of emotions should be pre-processed to handle instances of subtrings like :-) :- //Without this pre-processing, emoticons in a string won't be processed properly for ( int i = 0 ; i < emoticons . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < emoticons . size ( ) ; j ++ ) { String o1 = emoticons . get ( i ) ; String o2 = emoticons . get ( j ) ; if ( o2 . contains ( o1 ) ) { String temp = o2 ; emoticons . remove ( j ) ; emoticons . add ( i , temp ) ; } } } StringBuilder sb = new StringBuilder ( ) ; for ( String emoticon : emoticons ) { if ( sb . length ( ) != 0 ) { sb . append ( "|" ) ; } sb . append ( Pattern . quote ( emoticon ) ) ; } emoticonRegexPattern = Pattern . compile ( sb . toString ( ) ) ; }
Processes the Emoji data to emoticon regex