protected BreakingEngine SelectEngine(char c) { if (_breakingEngine.CanHandle(c)) { return(_breakingEngine); } else { //find other engine for (int i = _otherEngines.Count - 1; i >= 0; --i) { //not the current engine //and can handle the character BreakingEngine engine = _otherEngines[i]; if (engine != _breakingEngine && engine.CanHandle(c)) { return(engine); } } //default #if DEBUG if (!_engBreakingEngine.CanHandle(c)) { //even default can't handle the char } #endif return(_engBreakingEngine); } }
public CustomBreaker() { ThrowIfCharOutOfRange = false; // _visitor = new WordVisitor(); _breakingEngine = _engBreakingEngine; //default eng-breaking engine }
public void BreakWords(char[] charBuff, int startAt, int len) { //conver to char buffer int j = charBuff.Length; if (j < 1) { _endAt = 0; return; } _endAt = startAt + len; _visitor.LoadText(charBuff, startAt, len); //---------------------------------------- BreakingEngine currentEngine = _breakingEngine = SelectEngine(charBuff[startAt]); //---------------------------------------- //select breaking engine int endAt = startAt + len; for (; ;) { //---------------------------------------- currentEngine.BreakWord(_visitor, charBuff, startAt, endAt - startAt); //please note that len is decreasing switch (_visitor.State) { default: throw new NotSupportedException(); case VisitorState.End: //ok return; case VisitorState.OutOfRangeChar: { //find proper breaking engine for current char BreakingEngine anotherEngine = SelectEngine(_visitor.Char); if (anotherEngine == currentEngine) { if (ThrowIfCharOutOfRange) { throw new NotSupportedException($"A proper breaking engine for character '{_visitor.Char}' was not found."); } startAt = _visitor.CurrentIndex + 1; _visitor.SetCurrentIndex(startAt); _visitor.AddWordBreakAtCurrentIndex(WordKind.Unknown); } else { currentEngine = anotherEngine; startAt = _visitor.CurrentIndex; } } break; } } }
public void BreakWords(char[] charBuff, int startAt, int len) { //conver to char buffer int j = charBuff.Length; if (j < 1) { visitor.ResetText(); _endAt = 0; return; } _endAt = startAt + len; visitor.LoadText(charBuff, startAt); //---------------------------------------- BreakingEngine currentEngine = breakingEngine = SelectEngine(charBuff[startAt]); //---------------------------------------- //select breaking engine int endAt = startAt + len; for (; ;) { //---------------------------------------- currentEngine.BreakWord(visitor, charBuff, startAt, endAt - startAt); //please note that len is decreasing switch (visitor.State) { default: throw new NotSupportedException(); case VisitorState.End: //ok return; case VisitorState.OutOfRangeChar: { //find proper breaking engine for current char BreakingEngine anotherEngine = SelectEngine(visitor.Char); if (anotherEngine == currentEngine) { throw new NotSupportedException(); } else { currentEngine = anotherEngine; startAt = visitor.CurrentIndex; } } break; } } }
public void BreakWords(char[] charBuff, int startAt) { //conver to char buffer int j = charBuff.Length; textLength = j; visitor.LoadText(charBuff, 0); //---------------------------------------- BreakingEngine currentEngine = breakingEngine = SelectEngine(charBuff[startAt]); //---------------------------------------- //select breaking engine for (;;) { //---------------------------------------- currentEngine.BreakWord(visitor, charBuff, startAt, charBuff.Length - startAt); switch (visitor.State) { default: throw new NotSupportedException(); case VisitorState.End: //ok return; case VisitorState.OutOfRangeChar: { //find proper breaking engine for current char BreakingEngine anotherEngine = SelectEngine(visitor.Char); if (anotherEngine == currentEngine) { throw new NotSupportedException(); } else { currentEngine = anotherEngine; startAt = visitor.CurrentIndex; } } break; } } }
BreakingEngine SelectEngine(char c) { if (breakingEngine.CanHandle(c)) { return(breakingEngine); } else { //find other engine for (int i = otherEngines.Count - 1; i >= 0; --i) { //not the current engine //and can handle the character BreakingEngine engine = otherEngines[i]; if (engine != breakingEngine && engine.CanHandle(c)) { return(engine); } } return(engBreakingEngine); } }
public CustomBreaker() { ThrowIfCharOutOfRange = false; _breakingEngine = _engBreakingEngine; //default eng-breaking engine }
public void AddBreakingEngine(BreakingEngine engine) { //TODO: make this accept more than 1 engine otherEngines.Add(engine); breakingEngine = engine; }
public CustomBreaker() { visitor = new WordVisitor(this); breakingEngine = engBreakingEngine; }