Package org.omegat.gui.editor
Class EditorUtils
- java.lang.Object
-
- org.omegat.gui.editor.EditorUtils
-
public final class EditorUtils extends java.lang.Object
Some utilities methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
addBidiAroundTags(java.lang.String text, SourceTextEntry ste)
Add RTL+LTR around tags.static java.lang.String
doChangeCase(java.lang.String input, IEditor.CHANGE_CASE_TO toWhat)
Change the case of the input string to the indicated case.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.static int
getWordEnd(javax.swing.text.JTextComponent c, int offs)
Determines the end of a word for the given model location.static int
getWordStart(javax.swing.text.JTextComponent c, int offs)
Determines the start of a word for the given model location.static boolean
hasBidiAroundTag(java.lang.String text, java.lang.String tag, int pos)
static java.lang.String
removeDirectionChars(java.lang.String text)
Remove invisible direction chars from string.static java.lang.String
removeDirectionCharsAroundTags(java.lang.String text, SourceTextEntry ste)
Remove bidi chars around tags only.static java.lang.String
replaceGlossaryEntries(java.lang.String text)
Convenience method forreplaceGlossaryEntries(String, List, Locale, ITokenizer)
.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.
-
-
-
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)
Change the case of the input string to the indicated case. When toWhat isIEditor.CHANGE_CASE_TO.CYCLE
the 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 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 isIEditor.CHANGE_CASE_TO.CYCLE
the result will be UPPER > LOWER > SENTENCE > TITLE > UPPER.- Parameters:
input
- The string to changetoWhat
- The case to change to, orIEditor.CHANGE_CASE_TO.CYCLE
locale
- The locale of the input stringtokenizer
- A tokenizer for the input string language- Returns:
- The modified string
-
replaceGlossaryEntries
public static java.lang.String replaceGlossaryEntries(java.lang.String text)
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 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 entrieslocale
- 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)
-
-