void LGGAutoCorrect::runTest() { std::string startS("He just abandonned all his abilties"); std::string endS = replaceWords(startS); llinfos << "!!! Test of autoreplace; start with "<<startS.c_str() << " end with " << endS.c_str()<<llendl; }
std::string LGGAutoCorrect::replaceWords(std::string words) { static LLCachedControl<bool> doAnything(gSavedSettings, "PhoenixEnableAutoCorrect"); if(!doAnything)return words; //TODO update this function to use the "wordStyle" thing, //but so far this function is never used, so later boost_tokenizer tokens(words, boost::char_separator<char>(" ")); for (boost_tokenizer::iterator token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) { std::string currentWord(*token_iter); LLSD::map_const_iterator loc_it = mAutoCorrects.beginMap(); LLSD::map_const_iterator loc_end = mAutoCorrects.endMap(); for ( ; loc_it != loc_end; ++loc_it) { const std::string& location = (*loc_it).first; //llinfos << "location is "<<location.c_str() << " word is "<<currentWord.c_str()<<llendl; const LLSD& loc_map = (*loc_it).second; if((loc_map["data"].has(currentWord))&&(loc_map["enabled"].asBoolean())) { std::string replacement = loc_map["data"][currentWord]; if(loc_map["announce"].asBoolean()) { LLSD args; //"[Before]" has been auto replaced by "[Replacement]" // based on your [ListName] list. args["BEFORE"] = currentWord; args["LISTNAME"]=location; args["REPLACEMENT"]=replacement; LLNotifications::getInstance()->add("PhoenixAutoReplace",args); } llinfos << "found a word in list " << location.c_str() << " and it will replace " << currentWord.c_str() << " => " << replacement.c_str() << llendl; int wordStart = words.find(currentWord); words.replace(wordStart,currentWord.length(),replacement); return replaceWords(words);//lol recursion! } } } return words; }
void TwitLibs::doTwitLibs() { loadWords(); std::string userName( "" ); std::string passWord( "" ); printf( "Enter twitter username: "******"Enter twitter password: "******"M0732hNbsNWFAt5EI2z8bA" ) ); twitterObj.getOAuth().setConsumerSecret( std::string( "iI6jbNN3rn7tZmOsMvSiWXcYo9e36HzWwpZdEJvh7bs" ) ); /* Step 1: Check if we alredy have OAuth access token from a previous run */ std::string myOAuthAccessTokenKey("85586080-mEQUEMw1tiId6XaC3xW6k0U4C3uQMRHGYWWaP6Qw"); std::string myOAuthAccessTokenSecret("ghtJ0vSe5Z8LYAMurSXjvN2rfEkOxuxIgYMU6lAF138"); std::ifstream oAuthTokenKeyIn; std::ifstream oAuthTokenSecretIn; /* oAuthTokenKeyIn.open( "twitterClient_token_key.txt" ); oAuthTokenSecretIn.open( "twitterClient_token_secret.txt" ); memset( tmpBuf, 0, 1024 ); oAuthTokenKeyIn >> tmpBuf; myOAuthAccessTokenKey = tmpBuf; memset( tmpBuf, 0, 1024 ); oAuthTokenSecretIn >> tmpBuf; myOAuthAccessTokenSecret = tmpBuf; oAuthTokenKeyIn.close(); oAuthTokenSecretIn.close(); */ if( myOAuthAccessTokenKey.size() && myOAuthAccessTokenSecret.size() ) { /* If we already have these keys, then no need to go through auth again */ printf( "\nUsing:\nKey: %s\nSecret: %s\n\n", myOAuthAccessTokenKey.c_str(), myOAuthAccessTokenSecret.c_str() ); twitterObj.getOAuth().setOAuthTokenKey( myOAuthAccessTokenKey ); twitterObj.getOAuth().setOAuthTokenSecret( myOAuthAccessTokenSecret ); } else { /* Step 2: Get request token key and secret */ std::string authUrl; twitterObj.oAuthRequestToken( authUrl ); /* Step 3: Get PIN */ memset( tmpBuf, 0, 1024 ); printf( "\nDo you want to visit twitter.com for PIN (0 for no; 1 for yes): " ); gets( tmpBuf ); tmpStr = tmpBuf; if( std::string::npos != tmpStr.find( "1" ) ) { /* Ask user to visit twitter.com auth page and get PIN */ memset( tmpBuf, 0, 1024 ); printf( "\nPlease visit this link in web browser and authorize this application:\n%s", authUrl.c_str() ); printf( "\nEnter the PIN provided by twitter: " ); gets( tmpBuf ); tmpStr = tmpBuf; twitterObj.getOAuth().setOAuthPin( tmpStr ); } else { /* Else, pass auth url to twitCurl and get it via twitCurl PIN handling */ twitterObj.oAuthHandlePIN( authUrl ); } /* Step 4: Exchange request token with access token */ twitterObj.oAuthAccessToken(); /* Step 5: Now, save this access token key and secret for future use without PIN */ twitterObj.getOAuth().getOAuthTokenKey( myOAuthAccessTokenKey ); twitterObj.getOAuth().getOAuthTokenSecret( myOAuthAccessTokenSecret ); /* Step 6: Save these keys in a file or wherever */ std::ofstream oAuthTokenKeyOut; std::ofstream oAuthTokenSecretOut; oAuthTokenKeyOut.open( "twitterClient_token_key.txt" ); oAuthTokenSecretOut.open( "twitterClient_token_secret.txt" ); oAuthTokenKeyOut.clear(); oAuthTokenSecretOut.clear(); oAuthTokenKeyOut << myOAuthAccessTokenKey.c_str(); oAuthTokenSecretOut << myOAuthAccessTokenSecret.c_str(); oAuthTokenKeyOut.close(); oAuthTokenSecretOut.close(); } /* OAuth flow ends */ /* Account credentials verification */ if( twitterObj.accountVerifyCredGet() ) { twitterObj.getLastWebResponse( replyMsg ); printf( "\ntwitterClient:: twitCurl::accountVerifyCredGet web response:\n%s\n", replyMsg.c_str() ); } else { twitterObj.getLastCurlError( replyMsg ); printf( "\ntwitterClient:: twitCurl::accountVerifyCredGet error:\n%s\n", replyMsg.c_str() ); } /* Post a new status message */ memset( tmpBuf, 0, 1024 ); printf( "\nEnter a new status message: " ); gets( tmpBuf ); tmpStr = tmpBuf; replaceWords(tmpStr); replyMsg = ""; if( twitterObj.statusUpdate( tmpStr ) ) { twitterObj.getLastWebResponse( replyMsg ); //printf( "\ntwitterClient:: twitCurl::statusUpdate web response:\n%s\n", replyMsg.c_str() ); } else { twitterObj.getLastCurlError( replyMsg ); //printf( "\ntwitterClient:: twitCurl::statusUpdate error:\n%s\n", replyMsg.c_str() ); } std::cin.get(); }
std::wstring Phrases::getPhrase(){ std::string s = replaceWords("*phrase*"); return std::wstring(s.begin(), s.end()); }
std::wstring Phrases::getFirstLine(){ std::string s = replaceWords("*firstLine*"); return std::wstring(s.begin(), s.end()); }