GUIString ChatCommandParser::GetRestOfLine(const GUIString &s1, int thePos) { SkipWhitespace(s1,thePos); if(thePos>=s1.length()) return ""; GUIString aWord; if(s1.at(thePos)=='"') { int anEndQuotePos = s1.find('"',thePos+1); if(anEndQuotePos>=0) { aWord = s1.substr(thePos+1,anEndQuotePos-thePos-1); return aWord; } } int aPos = s1.length()-1; while(aPos>thePos) { if(s1.at(aPos)!=' ') break; aPos--; } if(aPos>thePos) return s1.substr(thePos,aPos-thePos+1); else return ""; }
bool ChatCommandParser::HandleInput(const GUIString &theInput) { mLastInputError = InputError_None; mLastTargetClient = NULL; mLastMatchName.erase(); if(mClientList.get()==NULL) { mLastInputError = InputError_NotLoggedIn; return false; } if(theInput.at(0)==mCommandChar) return HandleCommand(theInput); if(mDoColonEmote && theInput.at(0)==L':') { mLastChatCommand = LobbyChatCommand_Emote; mLastChat = theInput.substr(1); int aPos = 0; SkipWhitespace(mLastChat,aPos); if(aPos==mLastChat.length()) { mLastInputError = InputError_NoChat; return false; } // mServer->mConnection->SendChat(aChat,RoutingChatFlag_IsEmote,theGroupIdContext); return true; } mLastChatCommand = LobbyChatCommand_Broadcast; int aPos = 0; SkipWhitespace(theInput,aPos); if(aPos==theInput.length()) { mLastInputError = InputError_NoChat; return false; } mLastChat = theInput; // mServer->mConnection->SendChat(theInput,0,theGroupIdContext); return true; }
bool ChatCommandParser::Compare(const GUIString &s1, const GUIString &s2, bool &partialMatch) { partialMatch = false; int i1 = 0, i2 = 0; int len1 = s1.length(), len2 = s2.length(); while(i1<len1 && i2<len2) { if (towupper(s1.at(i1)) != towupper(s2.at(i2))) return false; i1++; i2++; } if(len1<=len2) partialMatch = true; return len1==len2; }
void TextArea::AddFormatedText(const GUIString &theText, bool lineBreak) { int aStartPos = 0; int anEndPos = 0; int aNextStartPos = 0; while(aStartPos < theText.length()) { int anEndPos = aStartPos; while(anEndPos < theText.length()) // find "\r", "\r\n", or "\n" { int aChar = theText.at(anEndPos); if(aChar=='\r') { if(anEndPos+1 < theText.length() && theText.at(anEndPos+1)=='\n') aNextStartPos = anEndPos + 2; else aNextStartPos = anEndPos + 1; break; } else if(aChar=='\n') { aNextStartPos = anEndPos + 1; break; } anEndPos++; } bool foundReturn = true; if(anEndPos>=theText.length()) { aNextStartPos = theText.length(); // Force it to exit next pass. foundReturn = lineBreak; } AddSegment(theText.substr(aStartPos,anEndPos-aStartPos),foundReturn); aStartPos = aNextStartPos; } }
void HTMLDocumentGen::printf(const GUIString &theText) { int aStartPos = 0; while(true) { int anEndPos = theText.find('%',aStartPos); if(anEndPos<0) break; if(theText.at(anEndPos+1)=='%') { anEndPos++; AddDoc(theText.substr(aStartPos,anEndPos-aStartPos),HTMLDocGenFlag_IsHTML); aStartPos = anEndPos+1; continue; } AddDoc(theText.substr(aStartPos,anEndPos-aStartPos),HTMLDocGenFlag_IsHTML); anEndPos++; aStartPos = anEndPos; while(anEndPos<theText.length() && theText.at(anEndPos)!='%') anEndPos++; GUIString aNumber = theText.substr(aStartPos,anEndPos-aStartPos); int aParamNum = aNumber.atoi()-1; if(aParamNum>=0 && aParamNum<mDocumentVector.size()) mDocument->AddDocument(mDocumentVector[aParamNum]); aStartPos = anEndPos+1; if(aStartPos>=theText.length()) break; } if(aStartPos<theText.length()) AddDoc(theText.substr(aStartPos),HTMLDocGenFlag_IsHTML); }
GUIString ChatCommandParser::GetWord(const GUIString &s1, int &thePos, bool doToUpper, bool checkQuotes) { SkipWhitespace(s1,thePos); if(thePos>=s1.length()) return ""; GUIString aWord; if(checkQuotes && s1.at(thePos)=='"') { int anEndQuotePos = s1.find('"',thePos+1); if(anEndQuotePos>=0) { aWord = s1.substr(thePos+1,anEndQuotePos-thePos-1); thePos = anEndQuotePos+1; if(doToUpper) aWord.toUpperCase(); return aWord; } } while(thePos<s1.length()) { wchar_t aChar = s1.at(thePos); if(doToUpper) aChar = towupper(aChar); if(aChar==' ') return aWord; aWord.append(aChar); thePos++; } return aWord; }
void ChatCommandParser::SkipWhitespace(const GUIString &s1, int &thePos) { while(thePos<s1.length() && iswspace(s1.at(thePos))) thePos++; }