void TestCommunicationChannel::SplitHelpExamples(string& buffer, 
								string& result, const string token)
{
	ACE_TRACE(ACE_TEXT("[TestCommunicationChannel::SplitHelpExamples()]"));
	
	string::size_type pos = 0;
	string replace_str("");
	char rm_buff[150];
	
	pos = buffer.find(token, pos);
	
	if (pos	== string::npos)
	{
		return;
	}
	
	++pos;
		
	int length = buffer.copy(rm_buff, pos, 0);
 	rm_buff[length] = '\0';
 	FindAndReplace(buffer, rm_buff, "");

	result = rm_buff;
	FindAndReplace(result, token, "");
	
	return;
}
示例#2
0
TEST_F(UpdateCheckTest, RequestFailure)
{
  webRequest->response.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE;

  appInfo.name = "1";
  appInfo.id = "2";
  appInfo.version = "3";
  appInfo.application = "4";
  appInfo.applicationVersion = "5";
  appInfo.developmentBuild = false;

  Reset();
  ForceUpdateCheck();

  AdblockPlus::Sleep(100);

  ASSERT_FALSE(eventCallbackCalled);
  ASSERT_TRUE(updateCallbackCalled);
  ASSERT_FALSE(updateError.empty());

  std::string expectedUrl(filterEngine->GetPref("update_url_release")->AsString());
  std::string platform = jsEngine->Evaluate("require('info').platform")->AsString();
  std::string platformVersion = jsEngine->Evaluate("require('info').platformVersion")->AsString();

  FindAndReplace(expectedUrl, "%NAME%", appInfo.name);
  FindAndReplace(expectedUrl, "%TYPE%", "1");   // manual update
  expectedUrl += "&addonName=" + appInfo.name +
                 "&addonVersion=" + appInfo.version +
                 "&application=" + appInfo.application +
                 "&applicationVersion=" + appInfo.applicationVersion +
                 "&platform=" + platform +
                 "&platformVersion=" + platformVersion +
                 "&lastVersion=0";
  ASSERT_EQ(expectedUrl, previousRequestUrl);
}
示例#3
0
string FixWildcard (const string sWildcard,       // the wildcard
                     const bool bMakeLowerCase,   // true to make lower case
                     const int iSendTo,           // where it is going to
                     const CString strLanguage)   // what script language

  {
  string sResult = sWildcard;

  // force to lower-case if that is what they want
  if (bMakeLowerCase)
     sResult = tolower (sResult);

  // escape out strings if we are sending to script
  if (iSendTo == eSendToScript || iSendTo == eSendToScriptAfterOmit)
    {
    if (strLanguage.CompareNoCase ("vbscript") == 0)
      // " becomes ""
      sResult = FindAndReplace (sResult, "\"", "\"\"");
    else
      {  // not VBscript
      // escape out backslashes first (ie. \ becomes \\ )
      sResult = FindAndReplace (sResult, "\\", "\\\\");
      // now turn " to \"
      sResult = FindAndReplace (sResult, "\"", "\\\"");
      // finally better escape out the $ signs
      if (strLanguage.CompareNoCase ("perlscript") == 0)
        sResult = FindAndReplace (sResult, "$", "\\$");
      } // end of not VBscript
    } // end of sending to script

  return sResult;
  } // end of FixWildcard
示例#4
0
文件: main.cpp 项目: Jane1408/OOP
int main(int argc, char *argv[])
{
	if (argc == 3)
	{
		std::string subject;
		std::string search = argv[1];
		std::string replace = argv[2];

		while (std::getline(std::cin, subject))
		{
			if (subject.empty())
			{
				break;
			}
			std::cout << FindAndReplace(subject, search, replace) << std::endl;
		}
	}
	else if ((argc == 2) && (argv[1] == "help"))
	{
		std::cout << "FindAndReplace.exe <search> <replace>" << std::endl;
	}
	else if (argc > 3)
	{
		std::cout << "Error. The number of arguments exceeds the limit. Use 'help' for more information." << std::endl;
	}
	else if (argc < 3)
	{
		std::cout << "Error. Not enough arguments. Use 'help' for more information." << std::endl;
	}
	return 0;
}
示例#5
0
文件: helper.cpp 项目: rleofield/dogs
bool writeLog( int line, const char* function, std::string content, bool trim ) {

   std::stringstream ss;

   // time
   ss.width( 6 );
   ss << getTime() << " ms T:0x";

   // thread
   ss.fill( '0' );
   ss.width( 6 );
   ss << boost::this_thread::get_id();

   // line
   ss.fill( ' ' );
   ss << " L:";
   ss.width( 4 );
   ss.setf( std::ios::right );
   ss << line << " F:";

   // function
   ss.width( 20 );
   ss.setf( std::ios::left );
   ss << function << " : ";

   // beautify
   std::string alignment = std::string( ss.str().size(), ' ' );
   std::string formatted = trim ? boost::trim_right_copy( content ) : content;
   formatted = SanitizeAllWhiteSpaces<std::string>( formatted );
   formatted = FindAndReplace( formatted, std::string( "\n" ), std::string( "\n" ) + alignment );

   ss << formatted << std::endl;

   // write to logfile
   {
      boost::lock_guard<boost::mutex> lock( MUTEX );

      std::ofstream ofs( "boost_threads.log", std::ios::out | std::ios::app );

      if( ofs.is_open() ) {

         // 2 newlines at start
         static bool start = false;

         if( !start ) {
            ofs << "\n\n";
            start = true;
         }

         ofs << ss.str();

         return true;

      } else {
         return false;
      }
   }
}
示例#6
0
void MedSLTPatWindow::SplitHelpExamples(string& buffer, 
										string& result, 
										const string token) const
{
	ACE_TRACE("[MedSLTPatWindow::SplitHelpExamples()]");

	string::size_type pos = 0;
	string replace_str("");
	char rm_buff[150];
	
	pos = buffer.find(token, pos);
	
	if (pos	== string::npos)
	{
		return;
	}
	
	++pos;
	
	if (pos >= 150)
 	{
 		pos = 150 - 1;
 	}
 		
	int length = buffer.copy(rm_buff, pos, 0);
	
	if (length >= 150)
 	{
 		length = 150 - 1;
 	}
 	 	
 	rm_buff[length] = '\0';
 	
 	FindAndReplace(buffer, rm_buff, "");

	result = rm_buff;
	FindAndReplace(result, token, "");
	
	return;
}
示例#7
0
TEST_F(UpdateCheckTest, UpdateAvailable)
{
  webRequest->response.status = AdblockPlus::WebRequest::NS_OK;
  webRequest->response.responseStatus = 200;
  webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"https://foo.bar/\"}}";

  appInfo.name = "1";
  appInfo.id = "2";
  appInfo.version = "3";
  appInfo.application = "4";
  appInfo.applicationVersion = "5";
  appInfo.developmentBuild = true;

  Reset();
  ForceUpdateCheck();

  AdblockPlus::Sleep(100);

  ASSERT_TRUE(eventCallbackCalled);
  ASSERT_EQ(1u, eventCallbackParams.size());
  ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString());
  ASSERT_TRUE(updateCallbackCalled);
  ASSERT_TRUE(updateError.empty());

  std::string expectedUrl(filterEngine->GetPref("update_url_devbuild")->AsString());
  std::string platform = jsEngine->Evaluate("require('info').platform")->AsString();
  std::string platformVersion = jsEngine->Evaluate("require('info').platformVersion")->AsString();

  FindAndReplace(expectedUrl, "%NAME%", appInfo.name);
  FindAndReplace(expectedUrl, "%TYPE%", "1");   // manual update
  expectedUrl += "&addonName=" + appInfo.name +
                 "&addonVersion=" + appInfo.version +
                 "&application=" + appInfo.application +
                 "&applicationVersion=" + appInfo.applicationVersion +
                 "&platform=" + platform +
                 "&platformVersion=" + platformVersion +
                 "&lastVersion=0";
  ASSERT_EQ(expectedUrl, previousRequestUrl);
}
示例#8
0
S3Params S3BucketReader::constructReaderParams(BucketContent& key) {
    // encode the key name but leave the "/"
    // "/encoded_path/encoded_name"
    string keyEncoded = UriEncode(key.getName());
    FindAndReplace(keyEncoded, "%2F", "/");

    S3Params readerParams = this->params.setPrefix(keyEncoded);

    readerParams.setKeySize(key.getSize());

    S3DEBUG("key: %s, size: %" PRIu64, readerParams.getS3Url().getFullUrlForCurl().c_str(),
            readerParams.getKeySize());
    return readerParams;
}
示例#9
0
void StringReplace::Replace(String &str)
{
	// test for environment variables
	Int32 lStart, lEnd, lStartSearch = 0;
	Int32 lStringLen;
	String strExpr;
	char* pchEnvVar;
	char pszVar[1000];
	BaseContainer bc;

	while (str.FindFirst("($", &lStart, lStartSearch))
	{
		if (!str.FindFirst("$)", &lEnd, lStart))
			return;
		lStartSearch = lStart + 1;

		strExpr = str.SubStr(lStart + 2, lEnd - lStart - 2);
		lStringLen = strExpr.GetCStringLen(STRINGENCODING_8BIT);
		Char* pchString = NewMem(Char,lStringLen + 2);
		if (!pchString)
			return;
		strExpr.GetCString(pchString, lStringLen + 1, STRINGENCODING_8BIT);
		pchEnvVar = GetOSEnvironmentVariable(pchString, pszVar, 1000);
		DeleteMem(pchString);
		if (pchEnvVar)
			str = str.SubStr(0, lStart) + String(pchEnvVar) + str.SubStr(lEnd + 2, str.GetLength() - lEnd - 2);
	}

	FindAndReplace(str, String("($CINEMA_4D_ROOT$)"), m_strStartupPath);
	FindAndReplace(str, String("($CINEMA_4D_PLUGIN$)"), m_strPluginPath);
	FindAndReplace(str, String("($CINEMA_4D_VERSION$)"), m_strCurrentVersion);
	FindAndReplace(str, String("($CURRENT_DATE$)"), m_strDate);
	FindAndReplace(str, String("($CURRENT_TIME$)"), m_strTime);
	FindAndReplace(str, String("($CURRENT_DATE_TIME$)"), m_strDateTime);
	FindAndReplace(str, String("($BUILD_VERSION$)"), m_strBuildVersion);
	FindAndReplace(str, String("($RELEASE_LINE$)"), m_strReleaseLine);
	FindAndReplace(str, String("($BUILD_ID$)"), m_strBuildID);
}
示例#10
0
void ShowHelp (const CString strPrefix, const CString strTopic)
  {
CWinApp* pApp = AfxGetApp();
ASSERT_VALID(pApp);
ASSERT(pApp->m_pszHelpFilePath != NULL);

  CString strFull = strPrefix;    // eg. FNC_
  strFull += strTopic;            // eg. Note

// WinHelp will treat backslashes as special, so double them
string sPath = FindAndReplace (pApp->m_pszHelpFilePath, "\\", "\\\\");

CString strCommand;

  strCommand.Format ("JI(\"%s\",\"%s\")",   // jump to help topic by ID (JumpID)
                   sPath.c_str (),          // path of help file
                   strFull);                // topic, eg. FNC_Note

  // show the help
  ::WinHelp (Frame, pApp->m_pszHelpFilePath, HELP_COMMAND, (DWORD) (LPCTSTR) strCommand);

  } // end of ShowHelp 
示例#11
0
TEST(Utils, FindAndReplace) {
    string str1 = "This is a simple & short test.";

    FindAndReplace(str1, "simple", "");
    EXPECT_EQ("This is a  & short test.", str1);

    FindAndReplace(str1, "short ", "");
    EXPECT_EQ("This is a  & test.", str1);

    FindAndReplace(str1, "test.", "");
    EXPECT_EQ("This is a  & ", str1);

    FindAndReplace(str1, "This", "");
    EXPECT_EQ(" is a  & ", str1);

    FindAndReplace(str1, "is a", "abcdefghijklmn");
    EXPECT_EQ(" abcdefghijklmn  & ", str1);

    FindAndReplace(str1, " a", "a");
    EXPECT_EQ("abcdefghijklmn  & ", str1);

    FindAndReplace(str1, "abc", "abcabc");
    EXPECT_EQ("abcabcdefghijklmn  & ", str1);
}
示例#12
0
//++ ------------------------------------------------------------------------------------
// Details: Remove all '\n' from the string and replace with a space. It does not alter
//          *this string.
// Type:    Method.
// Args:    None.
// Return:  CMIUtilString - New version of the string.
// Throws:  None.
//--
CMIUtilString
CMIUtilString::StripCRAll(void) const
{
    return FindAndReplace("\n", " ");
}
示例#13
0
bool MedSLTDocWindow::ExtractOutput(string& buffer, 
									const string left, 
									const string right)
{
	ACE_TRACE(ACE_TEXT("[MedSLTDocWindow::ExtractOutput()]"));
		
	string::size_type pos = 0;
	string replace_str("");
	char rm_buff[1000];
	
	pos = buffer.find(left, pos);
	
	if (pos	== string::npos)
	{
		return false;
	}
	
	pos = pos + left.size();

	if (pos >= 1000)
 	{
 		pos = 1000 - 1;
 	}
	
	int length = buffer.copy(rm_buff, pos, 0);
	
	if (length >= 1000)
 	{
 		length = 1000 - 1;
 	}
 	 	
 	rm_buff[length] = '\0';
 	 	
 	if (FindAndReplace(buffer, rm_buff, replace_str) == false)
 	{
 		return false;
 	}
 	
 	pos = buffer.find(right, 0);
	
	if (pos	== string::npos)
	{
		return false;
	}
	
	if (pos >= 1000)
 	{
 		pos = 1000 - 1;
 	}
	
	length = buffer.copy(rm_buff, pos, 0);
	
	if (length >= 1000)
 	{
 		length = 1000 - 1;
 	}
 	
 	rm_buff[length] = '\0';
 	
	if (FindAndReplace(buffer, rm_buff, replace_str) == false)
 	{
 		return false;
 	}
 	
	buffer = rm_buff;
		
#if _DEBUG
	ACE_DEBUG((LM_DEBUG, ACE_TEXT("%I[DEBUG] [MedSLTDocWindow::ExtractOutput()] "
			"[Ouput: %s]\n"), buffer.c_str()));				
#endif
	
	return true;
}
示例#14
0
UINT __stdcall ZTokenReplace(MSIHANDLE hInstall) {
	HRESULT hr = S_OK;
	UINT er = ERROR_SUCCESS;

	hr = WcaInitialize(hInstall, "ZTokenReplace");
	ExitOnFailure(hr, "Failed to initialize");
	WcaLog(LOGMSG_STANDARD, "Initialized.");

    UINT rc;
	char file[2048];
    char prop[1024];
	DWORD filesize = sizeof(file);
    DWORD propsize = sizeof(prop);

    rc = MsiGetProperty(hInstall, "File", &file[0], &filesize);
    if (rc != ERROR_SUCCESS) {
		WcaLog(LOGMSG_STANDARD, "Unable to get property: File");
        return WcaFinalize(ERROR_INSTALL_FAILURE);
    }

    rc = MsiGetProperty(hInstall, "NumberOfTokens", &prop[0], &propsize);
    if (rc != ERROR_SUCCESS) {
		WcaLog(LOGMSG_STANDARD, "Unable to get property: NumberOfTokens");
        return WcaFinalize(ERROR_INSTALL_FAILURE);
    }

	int num = atoi(prop);
	if (num > 0) {
		char **tokens = new char *[num];
		char **values = new char *[num];
		for (int i = 0; i < num; ++i) {
			char key[32];

			propsize = sizeof(prop);
			sprintf(key, "Token%u", i + 1);
			MsiGetProperty(hInstall, key, &prop[0], &propsize);
			tokens[i] = strdup(prop);

			propsize = sizeof(prop);
			sprintf(key, "Value%u", i + 1);
			MsiGetProperty(hInstall, key, &prop[0], &propsize);
			values[i] = strdup(prop);
			if (values[i][propsize - 1] == '\\')
				values[i][propsize - 1] = '\0';
		}

		int ret = FindAndReplace(file, num, tokens, values);
	
		for (int i = 0; i < num; ++i) {
			free(tokens[i]);
			free(values[i]);
		}

		if (ret)
			return WcaFinalize(ERROR_INSTALL_FAILURE);
	}

LExit:
	er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
	return WcaFinalize(er);
}