void CrossWordsField::InsertWord(CanPlace place, Word word) { if (place.CanTop) { InsertWord(word, Vertiacal, place.TopStart); } if (place.CanLeft) { InsertWord(word, Horisontal, place.LeftStart); } };
CPVT_WordPlace CPDF_VariableText::InsertText(const CPVT_WordPlace& place, const FX_WCHAR* text) { CFX_WideString swText = text; CPVT_WordPlace wp = place; for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { CPVT_WordPlace oldwp = wp; uint16_t word = swText.GetAt(i); switch (word) { case 0x0D: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0A) i += 1; wp = InsertSection(wp, nullptr, nullptr); } break; case 0x0A: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0D) i += 1; wp = InsertSection(wp, nullptr, nullptr); } break; case 0x09: word = 0x20; default: wp = InsertWord(wp, word, FXFONT_DEFAULT_CHARSET, nullptr); break; } if (wp == oldwp) break; } return wp; }
void CPDF_VariableText::SetText(const FX_WCHAR* text, int32_t charset, const CPVT_SecProps* pSecProps, const CPVT_WordProps* pWordProps) { DeleteWords(CPVT_WordRange(GetBeginWordPlace(), GetEndWordPlace())); CFX_WideString swText = text; CPVT_WordPlace wp(0, 0, -1); CPVT_SectionInfo secinfo; if (m_bRichText) { if (pSecProps) secinfo.pSecProps = new CPVT_SecProps(*pSecProps); if (pWordProps) secinfo.pWordProps = new CPVT_WordProps(*pWordProps); } if (CSection* pSection = m_SectionArray.GetAt(0)) pSection->m_SecInfo = secinfo; int32_t nCharCount = 0; for (int32_t i = 0, sz = swText.GetLength(); i < sz; i++) { if (m_nLimitChar > 0 && nCharCount >= m_nLimitChar) break; if (m_nCharArray > 0 && nCharCount >= m_nCharArray) break; uint16_t word = swText.GetAt(i); switch (word) { case 0x0D: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0A) i += 1; wp.nSecIndex++; wp.nLineIndex = 0; wp.nWordIndex = -1; AddSection(wp, secinfo); } break; case 0x0A: if (m_bMultiLine) { if (swText.GetAt(i + 1) == 0x0D) i += 1; wp.nSecIndex++; wp.nLineIndex = 0; wp.nWordIndex = -1; AddSection(wp, secinfo); } break; case 0x09: word = 0x20; default: wp = InsertWord(wp, word, charset, pWordProps); break; } nCharCount++; } }
void ClearWord(struct WordList *WL) { if(WL) { WL->Stack.Used = 0; WL->MaxLen = 0; ClearHash(&WL->Hash); if(WL->NonEmpty) InsertWord("", WL); } }
errorType CountWordFreq(char* line, bookType* book) { int i; char* pch; char delim[] = " ,.-\"'\n\t"; pch = strtok (line, delim); while (pch != NULL) { InsertWord(book, pch); pch = strtok (NULL, delim); } return ERROR_NONE; }
void ClearWord(struct WordList *WL) { char *Word; if (WL) { while ( (Word = StkPop( &WL->Stack )) ) { free(Word); } WL->Stack.Used = 0; WL->MaxLen = 0; ClearHash(&WL->Hash); if (WL->NonEmpty) InsertWord("", WL); } }
int main (void) { int pos; while (1) { word = GetNextWord(); if ( 0 == word.length() ) { DumpDictionary(dictionary,count); break; } if ((pos = LocateWord(dictionary,word)) >= 0 ) count[pos]++; else if (!InsertWord(dictionary,word)) cout << "dictionary full " << word << " cannot be added\n"; } return 0; }
void Dictionary::InsertWord(DictionaryItem* item, std::string word) { if(word.length() == 0) { item->endOfWord = true; return; } int children_idx = word[0]; if(item->children[children_idx] == NULL) { item->AddChildren(new DictionaryItem(word[0]), children_idx); } InsertWord(item->children[children_idx], word.substr(1, word.length() - 1)); }
int main (void) { ENTRY *pos; while (1) { word = GetNextWord(); if ( word.empty() ) { DumpDictionary(dictionary); break; } if ((pos = LocateWord(dictionary,word)) > 0 ) pos->count++; else if (!InsertWord(dictionary,word)) cout << "dictionary full" << word << "cannot be added\n"; } delete pos; return 0; }
Dictionary::Dictionary(std::string filename) { root = new DictionaryItem(); std::ifstream dict(filename); std::string word, word_utf8; while(!dict.eof()) { dict >> word_utf8; if(word_utf8.length() < 3) continue; //std::cout << "[Dictionary.cpp] " << word_utf8 << std::endl; InsertWord(EncodingUtils::UTF8ToIndex(word_utf8)); } dict.close(); }
FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { if (m_bMouseDown) return TRUE; CPWL_Wnd::OnChar(nChar, nFlag); // FILTER switch (nChar) { case 0x0A: case 0x1B: return FALSE; default: break; } FX_BOOL bCtrl = IsCTRLpressed(nFlag); FX_BOOL bAlt = IsALTpressed(nFlag); FX_BOOL bShift = IsSHIFTpressed(nFlag); uint16_t word = nChar; if (bCtrl && !bAlt) { switch (nChar) { case 'C' - 'A' + 1: CopyText(); return TRUE; case 'V' - 'A' + 1: PasteText(); return TRUE; case 'X' - 'A' + 1: CutText(); return TRUE; case 'A' - 'A' + 1: SelectAll(); return TRUE; case 'Z' - 'A' + 1: if (bShift) Redo(); else Undo(); return TRUE; default: if (nChar < 32) return FALSE; } } if (IsReadOnly()) return TRUE; if (m_pEdit->IsSelected() && word == FWL_VKEY_Back) word = FWL_VKEY_Unknown; Clear(); switch (word) { case FWL_VKEY_Back: Backspace(); break; case FWL_VKEY_Return: InsertReturn(); break; case FWL_VKEY_Unknown: break; default: InsertWord(word, GetCharSet()); break; } return TRUE; }
bool CrossWordsField::ProcessWordsBackTrack(std::vector<Word> words) { if (words.size() == 0) { if (PlacedWords.size() == _wordsToInsert) { std::cout << "all placed" << std::endl; return true; } else { return false; } } auto wordToPlace = words.front(); if (PlacedWords.size() == 0) { Point p = Point(); p.X = DimX / 2; p.Y = DimY / 2; InsertWord(wordToPlace, Horisontal, p); std::vector<Word>::iterator minusOne = words.erase(words.begin()); return ProcessWordsBackTrack(words); } else { auto next = words.front(); auto avalibelePos = CrossPositions(next); if (avalibelePos.size() == 0) { if (swapCount >= _wordsToInsert + 1) { return false; } swapCount++; auto inseted = RemoveLastWord()._word; words.push_back(inseted); return ProcessWordsBackTrack(words); } else { // try insert auto result = false; while (result == false) { if (avalibelePos.size() == 0) { break; } auto f = avalibelePos.front(); //if (f == nullptr avalibelePos.end().) // TODO: need to be implimented????? //{ //break; //} auto cPos = CanPlaceToCrossPos(f, next); if (cPos.Posible()) { InsertWord(cPos, next); words.erase(words.begin()); //Remove(next); result = true; } else { avalibelePos.erase(avalibelePos.begin());// Remove(f); result = false; } } if (!result) { RemoveLastWord(); auto it = words.erase(words.begin()); //Remove(next); words.push_back(next); } } return ProcessWordsBackTrack(words); } }
void Dictionary::InsertWord(const std::string& word) { InsertWord(root, word); }
int Parser::TagControl(string thecontent, int oldindex) { int tage; for(tage = oldindex; tage<oldindex+MAX_TAG_LEN && tage<(int)thecontent.length(); tage++) if(thecontent[tage] == TAGEND) break; if(tage == MAX_TAG_LEN || tage == thecontent.length()) { if(DEBUG_0) cout<<"sonda bulamadi"<<endl; return oldindex; } string tolook = Tolower(thecontent.substr(oldindex+1,tage-1-oldindex)); int index = 0; bool tagend = FALSE; // tAG Close!! therefore return tagend as new index if(thecontent[oldindex+1] == TAGCLOSE) { index++; tagend = TRUE; } int begin = index; while(tolook[index] != NULL && GetTypeOf(tolook[index]) == ALPHA) index++; int end = index; string rulename = tolook.substr(begin,end-begin); int i; for(i=0; i<NO_OF_TAGS; i++) if(TAGS[i] == rulename) break; // If sable is not enabled, do not consider any rule if(i != 6 && !rules->sableOn) return oldindex; ruleUpdate * ruleupdate = (ruleUpdate *) malloc(sizeof(ruleUpdate)); ruleupdate->valid = TRUE; if(tagend) { switch(i) { case 0: rules->RuleEmphC(ruleupdate); break; case 2: rules->RulePitchC(ruleupdate); break; case 3: rules->RuleRateC(ruleupdate); break; case 4: rules->RuleVolumeC(ruleupdate); break; case 5: rules->RuleEngineC(ruleupdate); break; case 6: rules->RuleSableC(); break; case 8: rules->RuleSayasC(ruleupdate); break; case 9: rules->RuleLangC(ruleupdate); break; case 10: rules->RuleSpeakerC(ruleupdate); break; case 11: rules->RulePronClosableC(); break; case 12: rules->RuleAudioC(ruleupdate); break; case 13: rules->RuleMarkerC(ruleupdate); break; case 14: rules->RuleDivC(ruleupdate); break; case 15: puncEnabled = true; break; default: if(DEBUG_0) cout<<"NOn recognized tag"<<endl; return oldindex; } switch(i) { case 0: case 1: case 2: case 3: case 4: case 5: case 9: case 10: case 12: case 13: if(ruleupdate->valid) { Word * tmpWord = new Word(" "); tmpWord->type = INFO; tmpWord->rule = ruleupdate; InsertWord(tmpWord); } else if(DEBUG_0) cout<<"--* Non valid rule or not implemented..."<<endl; break; } // we are done with the tag return tage+1; } else { switch(i) { case 0: rules->RuleEmph(ruleupdate,tolook); break; case 1: rules->RuleBreak(ruleupdate,tolook); break; case 2: rules->RulePitch(ruleupdate,tolook); break; case 3: rules->RuleRate(ruleupdate,tolook); break; case 4: rules->RuleVolume(ruleupdate,tolook); break; case 5: rules->RuleEngine(ruleupdate,tolook); break; case 6: rules->RuleSable(); break; case 7: rules->RulePron(ruleupdate,tolook); break; case 8: rules->RuleSayas(ruleupdate,tolook); break; case 9: rules->RuleLang(ruleupdate,tolook); break; case 10: rules->RuleSpeaker(ruleupdate,tolook); break; case 11: { Word * tmpWord = rules->RulePronClosable(tolook); while(tmpWord != NULL) { tmpWord->Update(this); InsertWord(tmpWord); tmpWord = tmpWord->next; } break; } case 12: rules->RuleAudio(ruleupdate,tolook); break; case 13: rules->RuleMarker(ruleupdate,tolook); break; case 14: rules->RuleDiv(ruleupdate,tolook); break; case 15: puncEnabled = false; break; default: if(DEBUG_0) cout<<"Non recognized tag"<<endl; return oldindex; } switch(i) { case 0: case 1: case 2: case 3: case 4: case 5: case 9: case 10: case 12: case 13: case 14: if(ruleupdate->valid) { Word * tmpWord = new Word(" "); tmpWord->type = INFO; tmpWord->rule = ruleupdate; InsertWord(tmpWord); } else if(DEBUG_0) cout<<"--* Non valid rule or not implemented..."<<endl; break; } return tage+1; } }
void Parser::Parse() { string thecontent = content; int index=0, pos = 0, size = 0; int len = (int)thecontent.length(); Word * tmpWord; isBusy = TRUE; CString sItem; double dNumber; char sNumber[256]; while(index <len) { // // KELIMELER if(GetTypeOf(thecontent[index]) == ALPHA) { int begin = index; index++; while(index<len && GetTypeOf(thecontent[index]) == ALPHA) index++; tmpWord = new Word(thecontent.substr(begin,(index-begin))); tmpWord->type = CUMLE; if(rules->pronounce.size() !=0) { tmpWord->Split(rules->pronounce); rules->pronounce.erase(); while(tmpWord != NULL) { tmpWord->Update(this); InsertWord(tmpWord); tmpWord = tmpWord->next; } } else if(rules->pronouncec.size() != 0) { // continue; } else { tmpWord->Update(this); InsertWord(tmpWord); } } // // SAYILAR else if(GetTypeOf(thecontent[index]) == NUMERIC) { int begin = index; if (thecontent[index] == '0') { tmpWord = new Word(thecontent.substr(index,1)); tmpWord->type = SAYI; index++; } else { /* //index++; pos = index; size = 0; memset(sNumber,0,256*sizeof(char)); while(pos<len && ((GetTypeOf(thecontent[pos]) == NUMERIC) || (thecontent[pos] == '.') ) ) { if (thecontent[pos] == '.'){ pos++; continue; } sNumber[size++] = thecontent[pos]; pos++; } dNumber = atof(sNumber); if (dNumber != 0) { index = pos; sItem.Format("%f",dNumber); tmpWord = new Word(sItem.GetString()); } else { pos = index; while(pos<len && GetTypeOf(thecontent[pos]) == NUMERIC) index++; tmpWord = new Word(thecontent.substr(begin,(index-begin))); } tmpWord->type = SAYI; if(rules->pronouncec.size() != 0) { // skip these word(s) continue; } int isdot = index; bool rankingnumber = FALSE; if(thecontent[isdot]=='.') { isdot++; while(thecontent[isdot]==' ') isdot++; if(thecontent[isdot] >'a' && thecontent[isdot] <'z') { if(DEBUG_0) cout<<"Ranking number"<<endl; rankingnumber = TRUE; tmpWord->type = DERECELISAYI; index++; } } */ while(index<len && GetTypeOf(thecontent[index]) == NUMERIC) index++; tmpWord = new Word(thecontent.substr(begin,(index-begin))); tmpWord->type = SAYI; if(rules->pronouncec.size() != 0) { // skip these word(s) continue; } int isdot = index; bool rankingnumber = FALSE; if(thecontent[isdot]=='.') { isdot++; while(thecontent[isdot]==' ') isdot++; if(thecontent[isdot] >'a' && thecontent[isdot] <'z') { if(DEBUG_0) cout<<"Ranking number"<<endl; rankingnumber = TRUE; tmpWord->type = DERECELISAYI; index++; } } } tmpWord->Update(this); while(tmpWord != NULL) { InsertWord(tmpWord); tmpWord = tmpWord->next; } } // // SEMBOLLER else if(GetTypeOf(thecontent[index]) == SYMBOLIC) { int begin = index; // control tags if(thecontent[begin] == ' ') { index++; continue; } if(ruleEnabled) if(thecontent[begin] == TAGSTART) { int newin = TagControl(thecontent,index); if(begin != newin) { index = newin; continue; } } index++; // capture ...'s while(GetTypeOf(thecontent[index]) == SYMBOLIC && thecontent[index] == '.' ) index++; if(rules->pronouncec.size() != 0) { // skip these word(s) continue; } tmpWord = new Word(thecontent.substr(begin,(index-begin))); tmpWord->type = SEMBOL; tmpWord->Update(this); if(tmpWord->GetType() == SEMBOL && puncEnabled) { while(tmpWord != NULL) { InsertWord(tmpWord); tmpWord = tmpWord->next; } } } } /* End of while ... */ isBusy = FALSE; }