Class EditorUtils


  • public final class EditorUtils
    extends java.lang.Object
    Some utilities methods.
    • Method Detail

      • getWordStart

        public static int getWordStart​(javax.swing.text.JTextComponent c,
                                       int offs)
                                throws javax.swing.text.BadLocationException
        Determines the start of a word for the given model location. This method skips direction char. TODO: change to use document's locale
        Parameters:
        c -
        offs -
        Returns:
        Throws:
        javax.swing.text.BadLocationException
      • getWordEnd

        public static int getWordEnd​(javax.swing.text.JTextComponent c,
                                     int offs)
                              throws javax.swing.text.BadLocationException
        Determines the end of a word for the given model location. This method skips direction char. TODO: change to use document's locale
        Parameters:
        c -
        offs -
        Returns:
        Throws:
        javax.swing.text.BadLocationException
      • removeDirectionChars

        public static java.lang.String removeDirectionChars​(java.lang.String text)
        Remove invisible direction chars from string.
        Parameters:
        text - string with direction chars
        Returns:
        string without direction chars
      • removeDirectionCharsAroundTags

        public static java.lang.String removeDirectionCharsAroundTags​(java.lang.String text,
                                                                      SourceTextEntry ste)
        Remove bidi chars around tags only.
        Parameters:
        text - string with direction chars
        Returns:
        string without direction chars
      • doChangeCase

        public static java.lang.String doChangeCase​(java.lang.String input,
                                                    IEditor.CHANGE_CASE_TO toWhat,
                                                    java.util.Locale locale,
                                                    ITokenizer tokenizer)
        Change the case of the input string to the indicated case. When toWhat is IEditor.CHANGE_CASE_TO.CYCLE the result will be UPPER > LOWER > SENTENCE > TITLE > UPPER.
        Parameters:
        input - The string to change
        toWhat - The case to change to, or IEditor.CHANGE_CASE_TO.CYCLE
        locale - The locale of the input string
        tokenizer - A tokenizer for the input string language
        Returns:
        The modified string
      • replaceGlossaryEntries

        public static java.lang.String replaceGlossaryEntries​(java.lang.String text)
        Convenience method for replaceGlossaryEntries(String, List, Locale, ITokenizer). Glossary entries are retrieved from GlossaryManager; the locale and tokenizer are taken from the project's current values for the source language.
        Parameters:
        text - Text in which to replace glossary hits. Assumed to be in the project's source language.
        Returns:
        Text with source glossary terms replaced with target terms
      • replaceGlossaryEntries

        public static java.lang.String replaceGlossaryEntries​(java.lang.String text,
                                                              java.util.List<GlossaryEntry> entries,
                                                              java.util.Locale locale,
                                                              ITokenizer tokenizer)
        Given a list of glossary entries, replace any instances of the source term appearing in the given text with the target term. When there are multiple target terms, the first one is used.
        Parameters:
        text - Text in which to replace glossary hits (assumed to be in the project's source language)
        entries - List of glossary entries
        locale - Locale with which to perform capitalization matching (assumed to be source locale)
        tokenizer - Tokenizer with which to split text (assumed to be project's source tokenizer)
        Returns:
        Text with source glossary terms replaced with target terms
      • addBidiAroundTags

        public static java.lang.String addBidiAroundTags​(java.lang.String text,
                                                         SourceTextEntry ste)
        Add RTL+LTR around tags. Used for display tags better in RTL text.
      • hasBidiAroundTag

        public static boolean hasBidiAroundTag​(java.lang.String text,
                                               java.lang.String tag,
                                               int pos)