// Path: app/src/main/java/ee/ioc/phon/android/speechutils/editor/Constants.java
// public class Constants {
// 
//     // Symbols that should not be preceded by space in a written text.
//     public static final Set<Character> CHARACTERS_STICKY_LEFT =
//             new HashSet<>(Arrays.asList(',', ':', ';', '.', '!', '?', '-', ')'));
// 
//     // Symbols after which the next word should be capitalized.
//     // We include ) because ;-) often finishes a sentence.
//     public static final Set<Character> CHARACTERS_EOS =
//             new HashSet<>(Arrays.asList('.', '!', '?', ')'));
// 
//     // These symbols stick to the next symbol, i.e. no whitespace is added in front of the
//     // following string.
//     public static final Set<Character> CHARACTERS_STICKY_RIGHT =
//             new HashSet<>(Arrays.asList('(', '[', '{', '<', '-'));
// 
//     // TODO: review these
//     public static final int REWRITE_PATTERN_FLAGS = Pattern.CASE_INSENSITIVE
//             | Pattern.UNICODE_CASE
//             | Pattern.MULTILINE
//             | Pattern.DOTALL;
// 
//     // Characters that are transparent (but not whitespace) when deciding if a word follows an EOS
//     // character and should thus be capitalized.
//     private static final Set<Character> CHARACTERS_TRANSPARENT =
//             new HashSet<>(Arrays.asList('(', '[', '{', '<'));
// 
//     public static final boolean isTransparent(char c) {
//         return Constants.CHARACTERS_TRANSPARENT.contains(c) || Character.isWhitespace(c);
//     }
// }


import ee.ioc.phon.android.speechutils.editor.Constants;
package ee.ioc.phon.android.speechutils.utils;


public class TextUtils {

    private TextUtils() {
    }

    /**
     * Pretty-prints the string returned by the server to be orthographically correct (Estonian),
     * assuming that the string represents a sequence of tokens separated by a single space character.
     * Note that a text editor (which has additional information about the context of the cursor)
     * will need to do additional pretty-printing, e.g. capitalization if the cursor follows a
     * sentence end marker.
     *
     * @param str String to be pretty-printed
     * @return Pretty-printed string (never null)
     */
    public static String prettyPrint(String str) {
        boolean isSentenceStart = false;
        boolean isWhitespaceBefore = false;
        String text = "";
        for (String tok : str.split(" ")) {
            if (tok.length() == 0) {
                continue;
            }
            String glue = " ";
            char firstChar = tok.charAt(0);
            if (isWhitespaceBefore
                    || Character.isWhitespace(firstChar)
                    || Constants.CHARACTERS_STICKY_LEFT.contains(firstChar)) {
                glue = "";
            }

            if (isSentenceStart) {
                tok = Character.toUpperCase(firstChar) + tok.substring(1);
            }

            if (text.length() == 0) {
                text = tok;
            } else {
                text += glue + tok;
            }

            isWhitespaceBefore = Character.isWhitespace(firstChar);

            // If the token is not a character then we are in the middle of the sentence.
            // If the token is an EOS character then a new sentences has started.
            // If the token is some other character other than whitespace (then we are in the
            // middle of the sentences. (The whitespace characters are transparent.)
            if (tok.length() > 1) {
                isSentenceStart = false;
// Path: app/src/main/java/ee/ioc/phon/android/speechutils/editor/Constants.java
// public class Constants {
// 
//     // Symbols that should not be preceded by space in a written text.
//     public static final Set<Character> CHARACTERS_STICKY_LEFT =
//             new HashSet<>(Arrays.asList(',', ':', ';', '.', '!', '?', '-', ')'));
// 
//     // Symbols after which the next word should be capitalized.
//     // We include ) because ;-) often finishes a sentence.
//     public static final Set<Character> CHARACTERS_EOS =
//             new HashSet<>(Arrays.asList('.', '!', '?', ')'));
// 
//     // These symbols stick to the next symbol, i.e. no whitespace is added in front of the
//     // following string.
//     public static final Set<Character> CHARACTERS_STICKY_RIGHT =
//             new HashSet<>(Arrays.asList('(', '[', '{', '<', '-'));
// 
//     // TODO: review these
//     public static final int REWRITE_PATTERN_FLAGS = Pattern.CASE_INSENSITIVE
//             | Pattern.UNICODE_CASE
//             | Pattern.MULTILINE
//             | Pattern.DOTALL;
// 
//     // Characters that are transparent (but not whitespace) when deciding if a word follows an EOS
//     // character and should thus be capitalized.
//     private static final Set<Character> CHARACTERS_TRANSPARENT =
//             new HashSet<>(Arrays.asList('(', '[', '{', '<'));
// 
//     public static final boolean isTransparent(char c) {
//         return Constants.CHARACTERS_TRANSPARENT.contains(c) || Character.isWhitespace(c);
//     }
// }


// Path: app/src/main/java/ee/ioc/phon/android/speechutils/utils/TextUtils.java
import ee.ioc.phon.android.speechutils.editor.Constants;

package ee.ioc.phon.android.speechutils.utils;


public class TextUtils {

    private TextUtils() {
    }

    /**
     * Pretty-prints the string returned by the server to be orthographically correct (Estonian),
     * assuming that the string represents a sequence of tokens separated by a single space character.
     * Note that a text editor (which has additional information about the context of the cursor)
     * will need to do additional pretty-printing, e.g. capitalization if the cursor follows a
     * sentence end marker.
     *
     * @param str String to be pretty-printed
     * @return Pretty-printed string (never null)
     */
    public static String prettyPrint(String str) {
        boolean isSentenceStart = false;
        boolean isWhitespaceBefore = false;
        String text = "";
        for (String tok : str.split(" ")) {
            if (tok.length() == 0) {
                continue;
            }
            String glue = " ";
            char firstChar = tok.charAt(0);
            if (isWhitespaceBefore
                    || Character.isWhitespace(firstChar)
                    || Constants.CHARACTERS_STICKY_LEFT.contains(firstChar)) {
                glue = "";
            }

            if (isSentenceStart) {
                tok = Character.toUpperCase(firstChar) + tok.substring(1);
            }

            if (text.length() == 0) {
                text = tok;
            } else {
                text += glue + tok;
            }

            isWhitespaceBefore = Character.isWhitespace(firstChar);

            // If the token is not a character then we are in the middle of the sentence.
            // If the token is an EOS character then a new sentences has started.
            // If the token is some other character other than whitespace (then we are in the
            // middle of the sentences. (The whitespace characters are transparent.)
            if (tok.length() > 1) {
                isSentenceStart = false;
            } else if (Constants.CHARACTERS_EOS.contains(firstChar)) {