-
-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICU-22564 Java API for the host env to register a low level break eng… #2697
Open
FrankYFTang
wants to merge
3
commits into
unicode-org:main
Choose a base branch
from
FrankYFTang:JavaExternalBreakEngine
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+217
−3
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import com.ibm.icu.lang.UProperty; | ||
import com.ibm.icu.lang.UScript; | ||
import com.ibm.icu.util.CodePointTrie; | ||
import com.ibm.icu.util.ULocale; | ||
|
||
/** | ||
* Rule Based Break Iterator | ||
|
@@ -727,7 +728,7 @@ private LanguageBreakEngine getLanguageBreakEngine(int c) { | |
// We have a dictionary character. | ||
// Does an already instantiated break engine handle it? | ||
for (LanguageBreakEngine candidate : fBreakEngines) { | ||
if (candidate.handles(c)) { | ||
if (candidate.isFor(getRequestedLocale()) && candidate.handles(c)) { | ||
return candidate; | ||
} | ||
} | ||
|
@@ -737,7 +738,7 @@ private LanguageBreakEngine getLanguageBreakEngine(int c) { | |
// Check the global list, another break iterator may have instantiated the | ||
// desired engine. | ||
for (LanguageBreakEngine candidate : gAllBreakEngines) { | ||
if (candidate.handles(c)) { | ||
if (candidate.isFor(getRequestedLocale()) && candidate.handles(c)) { | ||
fBreakEngines.add(candidate); | ||
return candidate; | ||
} | ||
|
@@ -1081,6 +1082,39 @@ private static int CISetIndex32(CharacterIterator ci, int index) { | |
return ci.getIndex(); | ||
} | ||
|
||
/** | ||
* Register a new external break engine. The external break engine will be adopted. | ||
* Because ICU may choose to cache break engine internally, this must | ||
* be called at application startup, prior to any calls to | ||
* object methods of RuleBasedBreakIterator to avoid undefined behavior. | ||
* @param engine the ExternalBreakEngine instance to be adopted | ||
* @internal ICU 75 technology preview | ||
*/ | ||
public static void registerExternalBreakEngine(ExternalBreakEngine engine) { | ||
synchronized(gAllBreakEngines) { | ||
gAllBreakEngines.add(0, new LanguageBreakEngine() { | ||
@Override | ||
public boolean handles(int c) { | ||
return engine.handles(c); | ||
} | ||
@Override | ||
public boolean isFor(ULocale locale) { | ||
return engine.isFor(locale); | ||
} | ||
@Override | ||
public int findBreaks(CharacterIterator text, int startPos, int endPos, | ||
DictionaryBreakEngine.DequeI foundBreaks, boolean isPhraseBreaking) { | ||
List<Integer> found = new ArrayList<Integer>(); | ||
int result = engine.fillBreaks(text, startPos, endPos, found); | ||
for (Integer f : found) { | ||
foundBreaks.push(f); | ||
} | ||
return result; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** DictionaryCache stores the boundaries obtained from a run of dictionary characters. | ||
* Dictionary boundaries are moved first to this cache, then from here | ||
* to the main BreakCache, where they may inter-leave with non-dictionary | ||
|
@@ -1885,7 +1919,42 @@ void dumpCache() { | |
}; | ||
|
||
|
||
public interface ExternalBreakEngine { | ||
/** | ||
* <p>Indicate whether this engine is used for a particular locale. | ||
* This method is used by the RuleBasedBreakIterator to find a break engine.</p> | ||
* | ||
* @param locale The locale. | ||
* @return true if this engine handles the particular character for that locale. | ||
* @internal ICU 75 technology preview | ||
*/ | ||
public boolean isFor(ULocale locale); | ||
|
||
/** | ||
* <p>Indicate whether this engine handles a particular character.This method is | ||
* used by the RuleBasedBreakIterator after it already find a break engine to see which | ||
* characters after the first one can be handled by this break engine.</p> | ||
* @param c A character that the engine might handle. | ||
* @return true if this engine handles the particular character. | ||
* @internal ICU 75 technology preview | ||
*/ | ||
public boolean handles(int c); | ||
|
||
/** | ||
* <p>Divide up a range of text handled by this break engine.</p> | ||
* | ||
* @param text A CharacterIterator representing the text | ||
* @param rangeStart The start of the range of known characters | ||
* @param rangeEnd The end of the range of known characters | ||
* @param foundBreaks Output of a list of Integer to denote break positions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should specify whether the contents of the List must be cleared before calling, or whether the fillBreaks is required to clear internally. |
||
* @return The number of breaks found | ||
* @internal ICU 75 technology preview | ||
*/ | ||
public int fillBreaks(CharacterIterator text, | ||
int rangeStart, | ||
int rangeEnd, | ||
List<Integer> foundBreaks); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.