Package org.omegat.gui.editor
Class EditorUtils
java.lang.Object
org.omegat.gui.editor.EditorUtils
Some utilities methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddBidiAroundTags(String text, SourceTextEntry ste) Add RTL+LTR around tags.static StringdoChangeCase(String input, IEditor.CHANGE_CASE_TO toWhat) Change the case of the input string to the indicated case.static StringdoChangeCase(String input, IEditor.CHANGE_CASE_TO toWhat, Locale locale, ITokenizer tokenizer) Change the case of the input string to the indicated case.static intgetWordEnd(JTextComponent c, int offs) Deprecated.static intgetWordEnd(JTextComponent c, int offs, Locale locale) Determines the end of a word for the given model location.static intgetWordStart(JTextComponent c, int offs) Deprecated.static intgetWordStart(JTextComponent c, int offs, Locale locale) Determines the start of a word for the given model location.static booleanhasBidiAroundTag(String text, String tag, int pos) static StringremoveDirectionChars(String text) Remove invisible direction chars from string.static StringremoveDirectionCharsAroundTags(String text, SourceTextEntry ste) Remove bidi chars around tags only.static StringreplaceGlossaryEntries(String text) Convenience method forreplaceGlossaryEntries(String, List, Locale, ITokenizer).static StringreplaceGlossaryEntries(String text, List<GlossaryEntry> entries, 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.
-
Method Details
-
getWordStart
Deprecated.Determines the start of a word for the given model location. This method skips direction char.- Parameters:
c- TextComponent of the editor area.offs- offset of the text.- Returns:
- position of word start on the text component.
- Throws:
BadLocationException- when there is no line found in the text component.
-
getWordStart
public static int getWordStart(JTextComponent c, int offs, Locale locale) throws BadLocationException Determines the start of a word for the given model location. This method skips direction char.- Parameters:
c- TextComponent of the editor area.offs- offset of the text.locale- locale of the text.- Returns:
- position of word start on the text component.
- Throws:
BadLocationException- when there is no line found in the text component.
-
getWordEnd
Deprecated.Determines the end of a word for the given model location. This method skips direction char.- Parameters:
c- TextComponent of the editor area.offs- offset of the text.- Returns:
- position of the word end on the text component.
- Throws:
BadLocationException- when there is no line found in the text component.
-
getWordEnd
Determines the end of a word for the given model location. This method skips direction char.- Parameters:
c- TextComponent of the editor area.offs- offset of the text.locale- locale of the text.- Returns:
- position of the word end on the text component.
- Throws:
BadLocationException- when there is no line found in the text component.
-
removeDirectionChars
Remove invisible direction chars from string.- Parameters:
text- string with direction chars- Returns:
- string without direction chars
-
removeDirectionCharsAroundTags
Remove bidi chars around tags only.- Parameters:
text- string with direction chars- Returns:
- string without direction chars
-
doChangeCase
Change the case of the input string to the indicated case. When toWhat isIEditor.CHANGE_CASE_TO.CYCLEthe result will be UPPER > LOWER > SENTENCE > TITLE > UPPER.This is a convenience method for
doChangeCase(String, CHANGE_CASE_TO, Locale, ITokenizer). The locale and tokenizer will be taken from the current project's target language values.- Parameters:
input- The string to changetoWhat- The case to change to, orIEditor.CHANGE_CASE_TO.CYCLE- Returns:
- The modified string
-
doChangeCase
public static String doChangeCase(String input, IEditor.CHANGE_CASE_TO toWhat, Locale locale, ITokenizer tokenizer) Change the case of the input string to the indicated case. When toWhat isIEditor.CHANGE_CASE_TO.CYCLEthe result will be UPPER > LOWER > SENTENCE > TITLE > UPPER.- Parameters:
input- The string to changetoWhat- The case to change to, orIEditor.CHANGE_CASE_TO.CYCLElocale- The locale of the input stringtokenizer- A tokenizer for the input string language- Returns:
- The modified string
-
replaceGlossaryEntries
Convenience method forreplaceGlossaryEntries(String, List, Locale, ITokenizer). Glossary entries are retrieved fromGlossaryManager; 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 String replaceGlossaryEntries(String text, List<GlossaryEntry> entries, 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 entrieslocale- Locale with which to perform capitalization matching (assumed to be source locale)tokenizer- Tokenizer with which to a split text (assumed to be project's source tokenizer)- Returns:
- Text with source glossary terms replaced with target terms
-
addBidiAroundTags
Add RTL+LTR around tags. Used for display tags better in RTL text. -
hasBidiAroundTag
-