int FindInWordSpans(WordVisitor visitor, WordGroup wordGroup) { WordSpan[] wordSpans = wordGroup.GetWordSpans(); if (wordSpans == null) { throw new NotSupportedException(); } //at this wordgroup //no subground anymore //so we should find the word one by one //start at prefix //and select the one that int readLen = visitor.CurrentIndex - visitor.LatestBreakAt; int nwords = wordSpans.Length; //only 1 that match TextBuffer currentTextBuffer = CurrentCustomDic.TextBuffer; //we sort unindex string *** //so we find from longest one( last) to begin for (int i = nwords - 1; i >= 0; --i) { //loop test on each word WordSpan w = wordSpans[i]; #if DEBUG //string dbugstr = w.GetString(currentTextBuffer); #endif int savedIndex = visitor.CurrentIndex; char c = visitor.Char; int wordLen = w.len; int matchCharCount = 0; if (wordLen > readLen) { for (int p = readLen; p < wordLen; ++p) { char c2 = w.GetChar(p, currentTextBuffer); if (c2 == c) { matchCharCount++; //match //read next if (!visitor.IsEnd) { visitor.SetCurrentIndex(visitor.CurrentIndex + 1); c = visitor.Char; } else { //no more data in visitor break; } } else { break; } } } //reset if (readLen + matchCharCount == wordLen) { int newBreakAt = visitor.LatestBreakAt + wordLen; visitor.SetCurrentIndex(newBreakAt); //-------------------------------------------- if (visitor.State == VisitorState.End) { return newBreakAt; } //check next char can be the char of new word or not //this depends on each lang char canBeStartChar = visitor.Char; if (CanHandle(canBeStartChar)) { if (CanBeStartChar(canBeStartChar)) { return newBreakAt; } else { //back to savedIndex visitor.SetCurrentIndex(savedIndex); return savedIndex; } } else { visitor.State = VisitorState.OutOfRangeChar; return newBreakAt; } } visitor.SetCurrentIndex(savedIndex); } return 0; }
int FindInWordSpans(WordVisitor visitor, WordGroup wordGroup) { WordSpan[] wordSpans = wordGroup.GetWordSpans(); if (wordSpans == null) { throw new NotSupportedException(); } //at this wordgroup //no subground anymore //so we should find the word one by one //start at prefix //and select the one that int readLen = visitor.CurrentIndex - visitor.LatestBreakAt; int nwords = wordSpans.Length; //only 1 that match TextBuffer currentTextBuffer = CurrentCustomDic.TextBuffer; //we sort unindex string *** //so we find from longest one( last) to begin for (int i = nwords - 1; i >= 0; --i) { //loop test on each word WordSpan w = wordSpans[i]; #if DEBUG //string dbugstr = w.GetString(currentTextBuffer); #endif int savedIndex = visitor.CurrentIndex; char c = visitor.Char; int wordLen = w.len; int matchCharCount = 0; if (wordLen > readLen) { for (int p = readLen; p < wordLen; ++p) { char c2 = w.GetChar(p, currentTextBuffer); if (c2 == c) { matchCharCount++; //match //read next if (!visitor.IsEnd) { visitor.SetCurrentIndex(visitor.CurrentIndex + 1); c = visitor.Char; } else { //no more data in visitor break; } } else { break; } } } //reset if (readLen + matchCharCount == wordLen) { int newBreakAt = visitor.LatestBreakAt + wordLen; visitor.SetCurrentIndex(newBreakAt); //-------------------------------------------- if (visitor.State == VisitorState.End) { return(newBreakAt); } //check next char can be the char of new word or not //this depends on each lang char canBeStartChar = visitor.Char; if (CanHandle(canBeStartChar)) { if (CanBeStartChar(canBeStartChar)) { return(newBreakAt); } else { //back to savedIndex visitor.SetCurrentIndex(savedIndex); return(savedIndex); } } else { visitor.State = VisitorState.OutOfRangeChar; return(newBreakAt); } } visitor.SetCurrentIndex(savedIndex); } return(0); }