void CALLBACK callback(MethodID methodID, int callID, wstring& address, Cause cause, wstring* callInfo) {
    static HANDLE hMutex = CreateMutex(NULL, FALSE, "callbackMutex");
    DWORD dwWaitResult = WaitForSingleObject(hMutex, 5000L);
	logger->debug("Entering callback method %d: callID=%d, address=%S...", methodID, callID, address.c_str());
    if(dwWaitResult == WAIT_OBJECT_0) {
	    try{
		    JNIEnv *localEnv = NULL;
		    g_javaVM->AttachCurrentThread((void**)&localEnv, NULL);
		    jclass cls = localEnv->GetObjectClass(g_thisObj);

            jmethodID callbackID = NULL;
			for (int retry = 0; callbackID == NULL && retry < 5; retry++) {
				callbackID = localEnv->GetMethodID(cls, "callback", "(IILjava/lang/String;I[Ljava/lang/String;)V");
				// if we have to try again, delay for 250 ms
				if (callbackID == NULL && retry < 5) {
					Sleep(250);
				}
				logger->debug("callback methodID: %p, retry=%d", callbackID, retry);
			}

		    if (callbackID == NULL) {
			    logger->fatal("Callback method not available.");
		    } else {
			    jint jMethodID = methodID;
			    jint jCallID = callID;
			    jstring jAddress = localEnv->NewString(((jchar *)address.c_str()), (jsize)address.length());
			    jint jCause = cause;

			    jobjectArray objCallInfo = NULL;
			    if(callInfo != NULL) {
				    logger->debug("Setting callInfo...");
				    jclass oCls = localEnv->FindClass("java/lang/String");
				    objCallInfo = localEnv->NewObjectArray(4, oCls, NULL);
				    for (int i=0; i<4; i++) {
					    jstring jInfo = localEnv->NewString(((jchar *)callInfo[i].c_str()), (jsize)callInfo[i].length());
					    localEnv->SetObjectArrayElement(objCallInfo, i, jInfo);
				    }
			    } else {
				    logger->debug("No callInfo for this callback.");
			    }
			    localEnv->CallVoidMethod(g_thisObj, callbackID, jMethodID, jCallID, jAddress, jCause, objCallInfo);
				g_javaVM->DetachCurrentThread();
			    logger->debug("Java callback successfully called.");
		    }
	    } catch(...){
		    logger->fatal("Callback failed.");
		}
        ReleaseMutex(hMutex);
    } else {
		logger->fatal("Cannot obtain callback mutex: dwWaitResult=%08X.", dwWaitResult);
    }
}
示例#2
0
XercesString::XercesString(const wstring& in)
    : basic_string<XMLCh>()
{
    for(unsigned int i=0; i<in.length(); ++i) {
        wchar_t utf32 = in[i];
        if (utf32 >= 0x10000UL) {
            push_back(0xD800 - 0x40 + (utf32 >> 10));
            push_back(0xDC00 + (utf32 & 0x3FF));
        }
        else
示例#3
0
std::string W2Ansi( const wstring& wszIn )
{
	string szRet;
	if (wszIn.length() <= 0) 
	{
		return szRet;
	}
	LPCWSTR pwszSrc = wszIn.c_str();
	int nWLen = wszIn.length();
	int nLen = WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, NULL, 0, NULL, NULL);
	
	char* pszDst = new char[nLen+1];
	assert(NULL != pszDst);
	WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszDst, nLen, NULL, NULL);
	pszDst[nLen] = '\0';
	szRet =pszDst;
	delete [] pszDst;
	return szRet;
}
示例#4
0
文件: Helpers.cpp 项目: Baron59/boss
	wstring Tidy(wstring filename) {						//Changes uppercase to lowercase and removes trailing spaces to do what Windows filesystem does to filenames.	
		size_t endpos = filename.find_last_not_of(L" \t");
	
		if (filename.npos == endpos) return (L""); 			//sanity check for empty string
		else {
			filename = filename.substr(0, endpos+1);
			for (unsigned int i = 0; i < filename.length(); i++) filename[i] = tolower(filename[i]);
			return (filename);
		}
	}
示例#5
0
/**
 * predict MorphologicalInfo by suffix
 */
vector<MorphologicalInfo> SuffixModelTrie::getMorphologicalPredictionBySuffix(wstring _word)
{
	vector<MorphologicalInfo> result = vector<MorphologicalInfo>();
	SuffixModelNode* currentNode = root;
	int suffixLength = 0;
	for (int i = (int) _word.length() - 1; i >= 0; --i)
	{
		SuffixModelNode* tmpNode = currentNode->findChildNode(_word.at(i));
		if (tmpNode == NULL)
		{
			break;
		}
		currentNode = tmpNode;
		suffixLength++;
        //wcout << _word.at(i) << " : " << currentNode->getFeatureFrequencyMap().size() << endl;
	}
	if (suffixLength == 0)
	{
		return result;
	}
    //wcout << "Suffix length = " << suffixLength << endl;
	map<int, int> _featureFrequencyMap = currentNode->getFeatureFrequencyMap();
    //wcout << "_featureFrequencyMap's size = " << _featureFrequencyMap.size() << endl;
	map<int, int>::iterator iter;
    //@TODO : \u043f\u0435\u0440\u0440\u0441\u0441\u043e\u043d//here was cyrrilic symbols: перрссон
	for (iter = _featureFrequencyMap.begin(); iter != _featureFrequencyMap.end(); ++iter)
	{
		int _featureId = iter->first;
		int _frequency = iter->second;
		int _basicFeatureListId = _featureId / 1000;
		int _featureListId = _featureId % 1000;
		wstring _initial_form = suffixLength < (int) _word.length() ? L"-" + _word.substr(_word.length() - suffixLength) : _word;
		MorphologicalInfo _morphologicalInfo;
		_morphologicalInfo.basicFeatureListId = _basicFeatureListId;
		_morphologicalInfo.featureListId = _featureListId;
		_morphologicalInfo.frequency = _frequency;
		_morphologicalInfo.initial_form = _initial_form;
		_morphologicalInfo.lemmaId = 0;
		_morphologicalInfo.suffix_length = suffixLength;
		result.push_back(_morphologicalInfo);
	}
	return result;
}
示例#6
0
void sbuf_stream::getUTF16(wstring &utf16_string) {
    sbuf.getUTF16(offset, utf16_string);
    size_t num_bytes = utf16_string.length() * 2;
    if (num_bytes > 0) {
        // if anything was read then also skip \U0000
        num_bytes += 2;
    }
    offset += num_bytes;
    return;
}
示例#7
0
BOOL base_string::IsDigitalW(wstring wstrSrc)
{
	int nIndex = 0;
	size_t nPos = wstrSrc.find('.');
	if (wstrSrc.empty())
	{
		return FALSE;
	}
	else if (nPos == wstring::npos)
	{
		for (nIndex = 0; nIndex < wstrSrc.length(); nIndex++)
		{
			if (wstrSrc[nIndex] < '0' || wstrSrc[nIndex] > '9')
			{
				return FALSE;
			}
		}
	}
	else if (nPos == wstrSrc.length() - 1)
	{
		return FALSE;
	}
	else if (nPos != wstring::npos)
	{
		for (nIndex = 0; nIndex < nPos; nIndex++)
		{
			if (wstrSrc[nIndex] < '0' || wstrSrc[nIndex] > '9')
			{
				return FALSE;
			}
		}
		for (nIndex = nPos + 1; nIndex < wstrSrc.length(); nIndex++)
		{
			if (wstrSrc[nIndex] < '0' || wstrSrc[nIndex] > '9')
			{
				return FALSE;
			}
		}
	}

	return TRUE;
}
示例#8
0
文件: gfx.cpp 项目: Greathood/taiga
COLORREF HexToARGB(const wstring& text) {
  int i = text.length() - 6;
  if (i < 0) return 0;

  unsigned int r, g, b;
  r = wcstoul(text.substr(i + 0, 2).c_str(), NULL, 16);
  g = wcstoul(text.substr(i + 2, 2).c_str(), NULL, 16);
  b = wcstoul(text.substr(i + 4, 2).c_str(), NULL, 16);

  return RGB(r, g, b);
}
示例#9
0
WinRegKeyExeption::WinRegKeyExeption(LONG errorcode, HKEY rootkey, wstring subkey, wstring label=L"")
:m_errorcode(errorcode),m_key(towstring<HKEY>(rootkey))
{
	m_key.append(L"\\");
	m_key.append(subkey);
	if(label.length()>0)
	{
		m_key.append(L"\\");
		m_key.append(label);
	}
}
示例#10
0
wstring ConnectedShortcut::disconnectFileName(const wstring& shortcutName)
{
	const wstring suffix = L" + " SHORT_APP_NAME L".lnk";
	if (PathMatchSpec(shortcutName.data(), (L"*" + suffix).data()) == FALSE)
		return shortcutName;

	wstring newName = shortcutName;
	newName.erase(newName.length() - suffix.length());
	newName.append(L".lnk");
	return newName;
}
示例#11
0
文件: string.cpp 项目: vjcagay/taiga
void Trim(wstring& str, const wchar_t trim_chars[],
          bool trim_left, bool trim_right) {
  if (str.empty())
    return;

  const size_t index_begin =
      trim_left ? str.find_first_not_of(trim_chars) : 0;
  const size_t index_end =
      trim_right ? str.find_last_not_of(trim_chars) : str.length() - 1;

  if (index_begin == wstring::npos || index_end == wstring::npos) {
    str.clear();
    return;
  }

  if (trim_right)
    str.erase(index_end + 1, str.length() - index_end + 1);
  if (trim_left)
    str.erase(0, index_begin);
}
示例#12
0
double stringToNumber( wstring& text )
{
    wstring::size_type endptr;
    double number = std::stod( text, &endptr );
    // the conversion is successful only when no text remains after the number
    if( endptr != text.length() )
    {
        throw new std::invalid_argument( "stringToNumber called on a text that contains characters after the number" );
    }
    return( number );
}
wstring 
TransferRule::category_name(const wstring& lemma, const wstring& tags) {
  wstring catname=L"";

  if (lemma.length()>0)//TODO: codificar bien el caracter extraño
    catname+=StringUtils::substitute(StringUtils::substitute(StringUtils::substitute(lemma,L"#",L"_"),L"\u2019",L"_"),L"'",L"QUOT")+L"_";

  catname+=StringUtils::substitute(StringUtils::substitute(StringUtils::substitute(StringUtils::substitute(tags,L".",L""),L"*",L"_"),L"+",L"plus"),L"@",L"arroba");

  return catname;
}
示例#14
0
void qtDLGDetailInfo::OnException(wstring functionName, wstring moduleName, quint64 exceptionOffset, quint64 exceptionCode, DWORD processID, DWORD threadID)
{
	qtDLGNanomite *pMainWindow = qtDLGNanomite::GetInstance();
	pMainWindow->lExceptionCount++;

	tblExceptions->insertRow(tblExceptions->rowCount());
		
	tblExceptions->setItem(tblExceptions->rowCount() - 1,0,
		new QTableWidgetItem(QString("%1").arg(exceptionOffset,16,16,QChar('0'))));
		
	tblExceptions->setItem(tblExceptions->rowCount() - 1,1,
		new QTableWidgetItem(QString("%1").arg(exceptionCode,8,16,QChar('0'))));

	tblExceptions->setItem(tblExceptions->rowCount() - 1,2,
		new QTableWidgetItem(QString().sprintf("%08X / %08X",processID,threadID)));

	if(functionName.length() > 0 )
		tblExceptions->setItem(tblExceptions->rowCount() - 1,3,
			new QTableWidgetItem(QString::fromStdWString(moduleName).append(".").append(QString::fromStdWString(functionName))));


	QString logMessage;

	if(functionName.length() > 0 && moduleName.length() > 0)
		logMessage = QString("[!] Exception - PID: %1 TID: %2 - ExceptionCode: %3 - ExceptionOffset: %4 - %5@%6")
		.arg(processID,6,16,QChar('0'))
		.arg(threadID,6,16,QChar('0'))
		.arg(exceptionCode,8,16,QChar('0'))
		.arg(exceptionOffset,16,16,QChar('0'))
		.arg(QString::fromStdWString(functionName))
		.arg(QString::fromStdWString(moduleName));
	else
		logMessage = QString("[!] Exception - PID: %1 TID: %2 - ExceptionCode: %3 - ExceptionOffset: %4")
		.arg(processID,6,16,QChar('0'))
		.arg(threadID,6,16,QChar('0'))
		.arg(exceptionCode,8,16,QChar('0'))
		.arg(exceptionOffset,16,16,QChar('0'));

	pMainWindow->logView->OnLog(logMessage);
	pMainWindow->UpdateStateBar(1);
}
示例#15
0
word_frequency_t getWeightedFrequency(wstring const &text)
{
    word_frequency_t freq;
    for(int i = 0; i < text.length() - WORD_MAXIMUM; i++) {
        wstring candidate = L"";
        for(int j = WORD_MINIMUM; j <= WORD_MAXIMUM; j++) {
            assert(i + j <= text.length() && "access violation");
            candidate.push_back(text[i + j - 1]);
            auto it = freq.find(candidate);
            if(it != freq.end())
                it->second += 1.0;
            else
                freq[candidate] = 1.0;
        }
    }
    for(auto &it : freq) {
        int len = it.first.length();
        it.second = it.second * len * len - 0.3;
    }
    return freq;
}
示例#16
0
void NRRDWriter::Save(wstring filename, int mode)
{
   if (!m_data)
      return;

   if (m_use_spacings &&
         m_data->dim == 3)
   {
      nrrdAxisInfoSet(m_data, nrrdAxisInfoSpacing, m_spcx, m_spcy, m_spcz);
      nrrdAxisInfoSet(m_data, nrrdAxisInfoMax,
            m_spcx*m_data->axis[0].size,
            m_spcy*m_data->axis[1].size,
            m_spcz*m_data->axis[2].size);
   }

   string str;
   str.assign(filename.length(), 0);
   for (int i=0; i<(int)filename.length(); i++)
      str[i] = (char)filename[i];
   nrrdSave(str.c_str(), m_data, NULL);
}
示例#17
0
//=====================================================================
void ofTrueTypeFontWS::drawStringAsShapes(wstring c, float x, float y) {
  
  if (!bLoadedOk){
    ofLog(OF_LOG_ERROR,"Error : font not allocated -- line %d in %s", __LINE__,__FILE__);
    return;
  };
  
	//----------------------- error checking
	if (!bMakeContours){
		ofLog(OF_LOG_ERROR,"Error : contours not created for this font - call loadFont with makeContours set to true");
		return;
	}
  
  int len = (int)c.length();
  // if (less_func(NUM_MAX_CHARACTERS, len + getLoadedCharsNum())) {
  //   ofLog(OF_LOG_ERROR,"Error : too many typefaces already loaded");
  //   return;
  // }
  
	GLint		index	= 0;
	GLfloat		X		= 0;
	GLfloat		Y		= 0;
  
	glPushMatrix();
	glTranslatef(x, y, 0);
  
	while(index < len){
		int cy = getCharID(c[index]);
    if (cps[cy].value == TYPEFACE_UNLOADED){
      loadEachChar(cy);
    }
		if (cy < nCharacters){ 			// full char set or not?
		  if (c[index] == L'\n') {
        
				Y = lineHeight;
				X = 0 ; //reset X Pos back to zero
        
		  }else if (c[index] == L' ') {
        cy = getCharID(L'p');
        X += cps[cy].width;
        //glTranslated(cps[cy].width, 0, 0);
		  } else {
				drawCharAsShape(cy, X, Y);
				X += cps[cy].setWidth;
				//glTranslated(cps[cy].setWidth, 0, 0);
		  }
		}
		index++;
	}
  
	glPopMatrix();
  
}
示例#18
0
vector<wstring> StringUtils::splitLast(const wstring& wstr, const wstring& stuff)
{
	vector<wstring> strList;
	int pos = wstr.rfind(stuff);
	if (-1 != pos){
		strList.push_back(wstr.substr(0,pos));
		strList.push_back(wstr.substr(pos+1, wstr.length()));

	}
	strList.push_back(wstr);
	return strList;
}
示例#19
0
void writePlainText(wstring input, map<wstring, char> alphabetMap){
    char previousCharacter = NULL;
    wstring currentMorse = (L"");

    for(int x = 0; x < input.length(); x++){

        if((previousCharacter == ' ' && input[x] != ' ') || (previousCharacter != ' ' && input[x] == ' ')){
            cout << alphabetMap[currentMorse];
            currentMorse = L"";
        } else if (x == (input.length()- 1)){
            currentMorse += input[x];
            cout << alphabetMap[currentMorse];
            break;
        }

        currentMorse += input[x];
        previousCharacter = input[x]; // for comparison
    }

    cout << endl << endl;
}
示例#20
0
int compare_string(const wstring &s, const wstring &t) {
	int score = 0;
	int n = t.length();
	for (int j = 1; j <= n; ++ j)
		for (int i = 0; i + j < n; ++ i) {
			wstring sub = t.substr(i, j);
			if (s.find(sub) != wstring::npos) {
				score += sub.length();
			}
		}
	return score;
}
示例#21
0
文件: string.cpp 项目: vjcagay/taiga
wstring SubStr(const wstring& str, const wstring& sub_begin,
               const wstring& sub_end) {
  size_t index_begin = str.find(sub_begin, 0);
  if (index_begin == wstring::npos)
    return L"";

  size_t index_end = str.find(sub_end, index_begin);
  if (index_end == wstring::npos)
    index_end = str.length();

  return str.substr(index_begin + 1, index_end - index_begin - 1);
}
示例#22
0
static int write_log(const wstring &src){
	ofstream out_log("client_log.txt", ios::app);
	char buffer[1024];
	//memset(buffer, 0, sizeof(buffer));
	int writeLen = wcstombs(buffer, src.c_str(), src.length());
	buffer[writeLen] = 0;

	//write_log(buffer);
	cout << buffer << endl;
	out_log << buffer << endl;
	out_log.close();
}
示例#23
0
static int split_next(const wstring &src, wstring &des, char ch, int start){
	int pos = 0;
	pos = src.find(ch, start);
	des.clear();
	if(pos < start){
		pos = src.length();
	}
	if(pos > start){
		des.assign(src, start, pos - start);
	}
	return pos;
}
示例#24
0
文件: Machine.cpp 项目: Suckzoo/CS322
bool Machine::isValidPattern(wstring pattern)
{
	int i;
	for (i = 0; i < pattern.length(); i++)
	{
		if (m_pLanguageSet.find(pattern[i]) == m_pLanguageSet.end())
		{
			return false;
		}
	}
	return true;
}
示例#25
0
//可同时处理目录和文件:path可以是路径,也可以是文件名,或者文件通配符
wstring find(wstring path,bool cursive)
{ 
     //取路径名最后一个"//"之前的部分,包括"//"
	replace_allW(path,L"\\",L"/");
	UINT index=path.find_last_of('/');
	if(index+1==path.length()){
		path.append(L"*.*");
	}
    wstring prefix=path.substr(0,path.find_last_of('/')+1);

    WIN32_FIND_DATA FindFileData;
    HANDLE hFind=::FindFirstFile(path.data(),&FindFileData);
	std::wstringstream ss;
    if(INVALID_HANDLE_VALUE == hFind)
    {
       ss<<L"[]";
	   FindClose(hFind);
	   return ss.str();
    }
	else{
		ss<<L"[";
	}
    while(TRUE)
    {
		bool flag=false;;
      //目录
        if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            //不是当前目录,也不是父目录
            if(cursive&&FindFileData.cFileName[0]!='.')
            {
				wstring temp=prefix+FindFileData.cFileName;
				ss<<L"{\"name\":\""<<FindFileData.cFileName<<L"\",\"list\":"<<find(temp+L"/*.*",cursive).data()<<L"}";
				flag=true;
            }
        }
        //文件
        else
        {   
             ss<<L"\""<<FindFileData.cFileName<<L"\"";
			flag=true;
        }
        if(!FindNextFile(hFind,&FindFileData))
              break;
		else if(flag){
			ss<<L",";
		}
    }
	ss<<L"]";
    FindClose(hFind);
	return ss.str();
}
示例#26
0
文件: string.cpp 项目: vjcagay/taiga
bool CheckFileExtension(wstring extension, const vector<wstring>& extension_list) {
  if (extension.empty() || extension_list.empty())
    return false;

  for (size_t i = 0; i < extension.length(); i++)
    extension[i] = toupper(extension[i]);

  for (size_t i = 0; i < extension_list.size(); i++)
    if (extension == extension_list[i])
      return true;

  return false;
}
示例#27
0
    string stdWstringToStdString(const wstring & wstr)
    {
      string   str;

      const size_t l = wstr.length();
      str.resize(l);
      for(size_t i = 0; i < l; i++)
      {
        str[i] = char(wstr[i]);
      }

      return str;
    }
void NASCToolBox::WstringToWchars( wstring temp, wchar_t *WC ) const
{
	int L = temp.length( );
	try {
		for( int i = 0; i < L; i ++ ) WC[ i ] = temp[ i ];
		WC[ L ] = L'\0';
	}
	catch( ... ) {
		cerr << "ERROR_TB002 - Out of Array Size." << endl;//数组越界
		system( "PAUSE" );
	}
	return;
}
示例#29
0
void GraphicsInterface::Replace(wstring & wstrText, wstring wstrFind, wstring wstrReplace)
{
	size_t pos = 0;

	pos = wstrText.find(wstrFind);
	while (pos != wstring::npos)
	{
		wstrText.replace(pos, wstrFind.length(), wstrReplace);
		pos = wstrText.find(wstrFind);
	}

	return;
}
示例#30
0
文件: TextBase.cpp 项目: Jackovic/Gem
/////////////////////////////////////////////////////////
// textMess
//
/////////////////////////////////////////////////////////
void TextBase :: breakLine(wstring line)
{
  // split the string wherever there is a '\n'
  while(line.length()>0){
    size_t pos=line.find('\n');
    
    // if not found, we're done
    if(wstring::npos == pos)break;
    wstring lin=line.substr(0,pos);

    m_theText.push_back(gem::string::getVisualLine(lin));
    line=line.erase(0,pos+1);
  }

  // if there is still a text append it
  if(line.length()) {
    //m_theText.push_back(line);
    m_theText.push_back(gem::string::getVisualLine(line));
  }
  makeLineDist();
  setModified();
}