Ejemplo n.º 1
0
/*************************************************************************
 * StrRStrIA	[COMCTL32.372]
 *
 * Find the last occurrence of a substring within a string.
 *
 * PARAMS
 *  lpszStr    [I] String to search in
 *  lpszEnd    [I] End of lpszStr
 *  lpszSearch [I] String to look for
 *
 * RETURNS
 *  The last occurrence lpszSearch within lpszStr, or NULL if not found.
 */
LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch)
{
  LPSTR lpszRet = NULL;
  WORD ch1, ch2;
  INT iLen;
 
  TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch));
 
  if (!lpszStr || !lpszSearch || !*lpszSearch)
    return NULL;

  if (!lpszEnd)
    lpszEnd = lpszStr + lstrlenA(lpszStr);

  if (IsDBCSLeadByte(*lpszSearch))
    ch1 = *lpszSearch << 8 | lpszSearch[1];
  else
    ch1 = *lpszSearch;
  iLen = lstrlenA(lpszSearch);

  while (lpszStr <= lpszEnd  && *lpszStr)
  {
    ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr;
    if (!COMCTL32_ChrCmpIA(ch1, ch2))
    {
      if (!StrCmpNIA(lpszStr, lpszSearch, iLen))
        lpszRet = (LPSTR)lpszStr;
    }
    lpszStr = CharNextA(lpszStr);
  }
  return lpszRet;
}
Ejemplo n.º 2
0
static void test_StrCmpA(void)
{
  static const char str1[] = {'a','b','c','d','e','f'};
  static const char str2[] = {'a','B','c','d','e','f'};
  ok(0 != StrCmpNA(str1, str2, 6), "StrCmpNA is case-insensitive\n");
  ok(0 == StrCmpNIA(str1, str2, 6), "StrCmpNIA is case-sensitive\n");
  if (pChrCmpIA) {
    ok(!pChrCmpIA('a', 'a'), "ChrCmpIA doesn't work at all!\n");
    ok(!pChrCmpIA('b', 'B'), "ChrCmpIA is not case-insensitive\n");
    ok(pChrCmpIA('a', 'z'), "ChrCmpIA believes that a == z!\n");
  }
  else
    win_skip("ChrCmpIA() is not available\n");

  if (pStrIsIntlEqualA)
  {
    ok(pStrIsIntlEqualA(FALSE, str1, str2, 5), "StrIsIntlEqualA(FALSE,...) isn't case-insensitive\n");
    ok(!pStrIsIntlEqualA(TRUE, str1, str2, 5), "StrIsIntlEqualA(TRUE,...) isn't case-sensitive\n");
  }
  else
    win_skip("StrIsIntlEqualA() is not available\n");

  if (pIntlStrEqWorkerA)
  {
    ok(pIntlStrEqWorkerA(FALSE, str1, str2, 5), "IntlStrEqWorkerA(FALSE,...) isn't case-insensitive\n");
    ok(!pIntlStrEqWorkerA(TRUE, str1, str2, 5), "pIntlStrEqWorkerA(TRUE,...) isn't case-sensitive\n");
  }
  else
    win_skip("IntlStrEqWorkerA() is not available\n");
}
Ejemplo n.º 3
0
/**
* 生成一个easy curl对象,进行一些简单的设置操作
*/
CURL * curl_easy_handler(const std::string & sUrl,
	const std::string & sProxy,
	const std::string & sData,
	FILE* fp,
	const unsigned int& uiTimeout,
	const bool& post,
	const std::string & header,
	struct curl_slist ** chunk)
{

	CURL * curl = curl_easy_init();

	curl_easy_setopt(curl, CURLOPT_URL, sUrl.c_str());
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

	if (uiTimeout > 0)
	{
		curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, uiTimeout);
	}
	if (!sProxy.empty())
	{
		curl_easy_setopt(curl, CURLOPT_PROXY, sProxy.c_str());
	}

	// write function //
	fseek(fp, 0, SEEK_SET);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writer);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
	curl_easy_setopt(curl, CURLOPT_HEADER, 1);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
	if (!StrCmpNIA(sUrl.c_str(), "https", 5))
	{
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
	}
	if ( post )
	{
		curl_easy_setopt(curl, CURLOPT_POST, 1);
		if (!sData.empty())
		{
			curl_easy_setopt(curl, CURLOPT_POSTFIELDS, sData.c_str());
		}
	}	

	if ( !header.empty() )
	{
		//curl_easy_setopt(curl, CURLOPT_HEADER, 1);
		/* Remove a header curl would otherwise add by itself */
		//chunk = curl_slist_append(chunk, "Accept:");
		//*chunk = curl_slist_append(*chunk, "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
		//*chunk = curl_slist_append(*chunk, "Accept-Encoding:gzip, deflate");
		//*chunk = curl_slist_append(*chunk, header.c_str());
		/* set our custom set of headers */
		Json::Value root;
		Json::Reader read;
		if (read.parse(header.c_str(), root) && root.isArray()){
			int len = root.size();
			for (int i = 0; i < len; ++i)
			{
				std::string val = root[i].asString();
				*chunk = curl_slist_append(*chunk, val.c_str());
			}
		}
	}
	if (post)
	{
		char szbuf[256];
		sprintf_s(szbuf, "Content-length: %d", sData.size());
		*chunk = curl_slist_append(*chunk, szbuf);
	}
	if (*chunk)
	{
		curl_easy_setopt(curl, CURLOPT_HTTPHEADER, *chunk);
	}
	return curl;
}
Ejemplo n.º 4
0
	inline int win32_strcmpnia(const char * s1, const char * s2, int size)
	{
		return StrCmpNIA(s1, s2, size);
	}