Beispiel #1
0
wstring CharRight(const wstring& str, int length) {
  if (length > static_cast<int>(str.length())) {
    return str.substr(0, str.length());
  } else {
    return str.substr(str.length() - length, length);
  }
}
bool CaffeineClientHandler::RenameOldFile(wstring filename)
{
    //  Determine if the file already exists.  We do this because of the fugly extension
    //  API we're using.
#ifdef __APPLE__
    return renameOldFile(filename);
#else
    bool retval = false;
    struct _stat buf = {0,};
    if(_wstat(filename.c_str(), &buf) == 0)
    {
        wstring fileExt = L"";

        unsigned index = filename.find_last_of('.');
        if (index != wstring::npos)
        {
            fileExt = filename.substr(index);
        }

        wstringstream newFileName;
        newFileName << filename.substr(0, index) << ".old" << fileExt;

        RenameOldFile(newFileName.str());
        _wrename(filename.c_str(), newFileName.str().c_str());
        retval = true;
    }

    return retval;
#endif

}
Beispiel #3
0
	//////////////////////////////////////////////////////////////////////////
	// parse_val
	//////////////////////////////////////////////////////////////////////////
	data_ptr parse_val(wstring key, data_map &data)
	{
		// quoted string
		if (key[0] == L'\"')
		{
			return make_data(boost::trim_copy_if(key, boost::is_any_of(L"\""))) ;
		}
		// check for dotted notation, i.e [foo.bar]
		size_t index = key.find(L".") ;
		if (index == wstring::npos)
		{
			if (!data.has(key))
			{
				return make_data(L"{$" + key + L"}") ;
			}
			return data[key] ;
		}

		wstring sub_key = key.substr(0, index) ;
		if (!data.has(sub_key))
		{
			return make_data(L"{$" + key + L"}") ;
		}
		data_ptr item = data[sub_key] ;
		return parse_val(key.substr(index+1), item->getmap()) ;
	}
Beispiel #4
0
boost::optional< pair<wstring,wstring> > HTMLParser::AnalyzeLink( const wstring& rHtml, size_t uStartPos )
{
	size_t uPos1 = rHtml.find( L"<a ", uStartPos );
	if( uPos1 != wstring::npos )
	{
		size_t uPos2 = rHtml.find( L"href=\"", uPos1 );
		if( uPos2 != wstring::npos )
		{
			uPos2 += 6;
			uPos1 = rHtml.find( L"\"", uPos2 );
			if( uPos1 != wstring::npos )
			{
				wstring sLinkUrl = rHtml.substr( uPos2, uPos1 - uPos2 );

				uPos1 = rHtml.find( L">", uPos1 );
				if( uPos1 != wstring::npos )
				{
					uPos1 += 1;
					uPos2 = rHtml.find( L"</a>", uPos1 );
					wstring sLinkText = rHtml.substr( uPos1, uPos2 - uPos1 );
					boost::algorithm::trim( sLinkText );

					return boost::optional< pair<wstring,wstring> >( make_pair( sLinkText, sLinkUrl ) );
				}
			}
		}
	}
	return boost::optional< pair<wstring,wstring> >();
}
Beispiel #5
0
wstring CStaticPubFunc::GetFileExtendName(wstring strFileName)
{
	int intCharPosition;

	//Find "\\",Get The File's Name
	intCharPosition = strFileName.rfind(L'\\');
	if(-1 != intCharPosition)
	{
		strFileName = strFileName.substr(intCharPosition - 1);
	}
	//AfxMessageBox(strFileName);

	//Find ".",Get the file's extend name
	intCharPosition = strFileName.rfind(L'.');
	if(-1 != intCharPosition)
	{
		strFileName = strFileName.substr(intCharPosition - 1);
		return strFileName;
	}
	else
	{
		//No extend name
		return L"";
	}
}
Beispiel #6
0
	filePathLinkW(const wstring& path) :m_ntType(L"\\??\\")
	{
		if (path.length() > 4 && path.substr(0, 4) == L"\\??\\")
		{
			m_ntType.append(path.substr(4));
		}
		else
		{
			m_ntType.append(path);
		}
		static DWORD tick = 0;
		wchar_t tmpBuffer[100];
		StringCbPrintfW(tmpBuffer, 100, L"%x%x%x%x", GetCurrentThreadId(), GetTickCount(), rand(), ++tick);
		m_pathDefine = wstring(FS_BYPASS_DEFINE_PREFIX_W) + tmpBuffer;
		if (DefineDosDeviceW(DDD_RAW_TARGET_PATH, m_pathDefine.c_str(), m_ntType.c_str()))
		{
			m_pathLink = wstring(L"\\\\.\\") + FS_BYPASS_DEFINE_PREFIX_W + tmpBuffer;
			m_transformed = true;
		}
		else
		{
			m_pathLink = path;
			m_transformed = false;
		}
	}
Beispiel #7
0
vector<int> CJPWordsVector::makeTone(wstring str)
{
	//目标整形数组
	vector<int> tone;
	//分割符为英文逗号
	wchar_t flag = ',';
	//起始位置
	size_t start = 0;
	//结束位置
	size_t end = 0 ;
	for( ; end<str.size(); end++ )
	{
		//当前符号位分隔符
		if(str.at( end )== flag)
		{
			//截取子串
			wstring numStr = str.substr(start,end-start);
			//转换成数字加入数组
			int num = _wtoi(numStr.c_str());
			tone.push_back(num);
			//跳过分割符
			end++;
			//移动开始位置
			start = end;
		}
	}
	//截取子串
	wstring numStr = str.substr(start,end-start);
	//转换成数字加入数组
	int num = _wtoi(numStr.c_str());
	tone.push_back(num);
	return tone;
}
    /**
        Extract a vector of the substrings that are separated by the delimter string

        \param    str          String to tokenize
        \param    tokens       Return a vector of tokens
        \param    delimiter    Delimeter string
        \param    trim         true if all tokens should be trimmed (default), otherwise false
        \param    emptyTokens  false if empty tokens should be removed from the result (default), otherwise true.

    */
    void StrTokenizeStr(const wstring& str, vector<std::wstring>& tokens, const wstring& delimiter, bool trim/*=true*/, bool emptyTokens/*=false*/)
    {
        tokens.clear();

        wstring::size_type lastPos = 0;
        wstring::size_type pos = delimiter.empty()?wstring::npos:str.find(delimiter, lastPos);

        while (wstring::npos != pos)
        {
            wstring tmp = str.substr(lastPos, pos - lastPos);
            if ( ! tmp.empty() && trim)
            {
                tmp = StrTrim(tmp);
            }
            if ( ! tmp.empty() || emptyTokens)
            {
                tokens.push_back(tmp);
            }
            lastPos = pos + delimiter.length();
            //if (pos != wstring::npos)
            {
                pos = str.find(delimiter, lastPos);
            }
        }
        wstring tmp = str.substr(lastPos, wstring::npos);
        if ( ! tmp.empty() && trim)
        {
            tmp = StrTrim(tmp);
        }
        if ( ! tmp.empty() || emptyTokens)
        {
            tokens.push_back(tmp);
        }
    }
Beispiel #9
0
/*!
	sakura.iniの1行を処理する.

	1行の読み込みが完了するごとに呼ばれる.
	
	@param line [in] 読み込んだ行
*/
void CProfile::ReadOneline(
	const wstring& line
)
{
	//	空行を読み飛ばす
	if( line.empty() )
		return;

	//コメント行を読みとばす
	if( 0 == line.compare( 0, 2, LTEXT("//") ))
		return;

	// セクション取得
	//	Jan. 29, 2004 genta compare使用
	if( line.compare( 0, 1, LTEXT("[") ) == 0 
			&& line.find( LTEXT("=") ) == line.npos
			&& line.find( LTEXT("]") ) == ( line.size() - 1 ) ) {
		Section Buffer;
		Buffer.strSectionName = line.substr( 1, line.size() - 1 - 1 );
		m_ProfileData.push_back( Buffer );
	}
	// エントリ取得
	else if( !m_ProfileData.empty() ) {	//最初のセクション以前の行のエントリは無視
		wstring::size_type idx = line.find( LTEXT("=") );
		if( line.npos != idx ) {
			m_ProfileData.back().mapEntries.insert( PAIR_STR_STR( line.substr(0,idx), line.substr(idx+1) ) );
		}
	}
}
Beispiel #10
0
/***************************************************************************
 *      bindBuiltinVariable
 ***************************************************************************/
bool CCilVm::bindBuiltinVariable( const wstring& strQualifiedName,
                                  CVariable* const pvar )
{
    bool bReturn = true;

    //Bind the var

    if( strQualifiedName.find( STRING_INTERNAL_SCOPEDELIMITER ) != wstring::npos )
    {
        wstring strRoot = strQualifiedName.substr( 0, strQualifiedName.rfind( STRING_INTERNAL_SCOPEDELIMITER ) );
        assert( strRoot.find( STRING_INTERNAL_SCOPEDELIMITER ) == wstring::npos );

        wstring strLeaf = strQualifiedName.substr( strQualifiedName.rfind( STRING_INTERNAL_SCOPEDELIMITER ) + 1,
                          strQualifiedName.length() );
        RID ridObject = getMetaData().queryBuiltinObjectRid( strRoot );
        if( ridObject == RID_NOTDEFINED )
            return false;

        //Create property
        getPrototypeObject( ridObject ).setProperty( strLeaf,
                *pvar );
    }

    return bReturn;
}
      /// <summary>Parses the file ID of a language file</summary>
      /// <param name="fn">The filename including extension</param>
      LanguageFilenameReader::LanguageFilenameReader(const wstring& fn) : HasLanguage(false), FileID(0), Valid(false)
      {
         try
         {
            // Ensure extension is XML/PCK
            if (Path(fn).HasExtension(L".xml") || Path(fn).HasExtension(L".pck"))
            {
               // No language ID: nnnn.pck
               if (fn.length() == 4+4)
                  FileID = ParseFileID(fn.substr(0,4));

               // X3R: LLnnnn.pck
               else if (fn.length() == 6+4)
               {
                  FileID = ParseFileID(fn.substr(2,4));
                  Language = ParseLanguageID(fn.substr(0,2));
                  HasLanguage = true;
               }
               // X3TC: nnnn-L0nn.pck
               else if (fn.length() == 9+4)
               {
                  FileID = ParseFileID(fn.substr(0,4));
                  Language = ParseLanguageID(fn.substr(7,2));
                  HasLanguage = true;
               }
            
               // Validate
               Valid = FileID > 0;
            }
         }
         catch (...)
         {
            Valid = false;
         }
      }
    /**
    Gather the Major and Minor version from Product version

    Parameters:  version - Product version, its format like 11.23.32, REV- or 0.4b41

    */
    void InstalledSoftwareInstance::SetDetailedVersion(const wstring& version)
    {
        size_t pos = version.find_first_of('.');
        if( pos != wstring::npos )
        {
            wstring left = version.substr(0, pos);
            wstring right = version.substr(pos+1);
            try
            {
                m_versionMajor = StrToUInt(left);
                // Exclude characters
                for(pos = 0; pos< right.size(); pos++)
                {
                    if( right[pos] < '0' || right[pos] > '9' ) {
                        break;
                    }
                }
                if(pos > 0) {
                    left = right.substr(0, pos);
                    m_versionMinor = StrToUInt(left);
                }
            }
            catch (const SCXException& e)
            {
                SCX_LOGWARNING(m_log, StrAppend(L"parse InstalledSoftwareInstance version fails:", version).append(L" - ").append(e.What()));
            }
        }
    }
Beispiel #13
0
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParamarg, int cmdShow) {
	openLog();

#ifdef _NEED_WIN_GENERATE_DUMP
	_oldWndExceptionFilter = SetUnhandledExceptionFilter(_exceptionFilter);
#endif

	writeLog(L"Updaters started..");

	LPWSTR *args;
	int argsCount;

	bool needupdate = false, autostart = false, debug = false;
	args = CommandLineToArgvW(GetCommandLine(), &argsCount);
	if (args) {
		for (int i = 1; i < argsCount; ++i) {
			if (equal(args[i], L"-update")) {
				needupdate = true;
			} else if (equal(args[i], L"-autostart")) {
				autostart = true;
			} else if (equal(args[i], L"-debug")) {
				debug = _debug = true;
				openLog();
			}
		}
		if (needupdate) writeLog(L"Need to update!");
		if (autostart) writeLog(L"From autostart!");

		exeName = args[0];
		writeLog(L"Exe name is: " + exeName);
		if (exeName.size() > 11) {
			if (equal(exeName.substr(exeName.size() - 11), L"Updater.exe")) {
				exeDir = exeName.substr(0, exeName.size() - 11);
				writeLog(L"Exe dir is: " + exeDir);
				if (needupdate && update()) {
					updateRegistry();
				}
			} else {
				writeLog(L"Error: bad exe name!");
			}
		} else {
			writeLog(L"Error: short exe name!");
		}
		LocalFree(args);
	} else {
		writeLog(L"Error: No command line arguments!");
	}

	wstring targs = L"-noupdate";
	if (autostart) targs += L" -autostart";
	if (debug) targs += L" -debug";

	ShellExecute(0, 0, (exeDir + L"Telegram.exe").c_str(), targs.c_str(), 0, SW_SHOWNORMAL);

	writeLog(L"Executed Telegram.exe, closing log and quiting..");
	closeLog();

	return 0;
}
Beispiel #14
0
HRESULT CDataTuple::GetNextValue(int &iVal, wstring &line, size_t &start)
{
	HRESULT hRet = E_FAIL;
	size_t	 end;
	wstring	sep(TEXT(" \t"), 1);

	if (start >= line.length())
	{
		return hRet;
	}

	end = line.find_first_of (sep, start+1);

	wstring substr;

	if (string::npos != end && end > start)
	{
		substr = line.substr(start, end -start);
	}
	else
	{
		substr = line.substr(start, line.length() -start);
	}

	if (substr.length() > 0)
	{
		float val;
		if (1 == _stscanf_s(substr.c_str(), TEXT("%f"), &val))
		{
			iVal = (int)val;
			hRet = S_OK;
		}
	}
	else
	{
		start = string::npos;
	}

	if (SUCCEEDED(hRet) && end != string::npos)
	{
		start = line.find(sep, end);

		while (start < line.length() && line[start +1] == ' ')
		{
			++start;
		}

	}
	else
	{
		start = string::npos;
	}

	return hRet;
}
Beispiel #15
0
static bool resolveCygwinPath(const wstring& cygwinPath, wstring& windowsPath)
{
    wstring fileProtocol = L"file://";
    bool isFileProtocol = cygwinPath.find(fileProtocol) != string::npos;
    if (cygwinPath[isFileProtocol ? 7 : 0] != '/')  // ensure path is absolute
        return false;

    // Get the Root path.
    WCHAR rootPath[MAX_PATH];
    DWORD rootPathSize = _countof(rootPath);
    DWORD keyType;
    DWORD result = ::SHGetValueW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/"), TEXT("native"), &keyType, &rootPath, &rootPathSize);

    if (result != ERROR_SUCCESS || keyType != REG_SZ) {
        // Cygwin 1.7 doesn't store Cygwin's root as a mount point anymore, because mount points are now stored in /etc/fstab.
        // However, /etc/fstab doesn't contain any information about where / is located as a Windows path, so we need to use Cygwin's
        // new registry key that has the root.
        result = ::SHGetValueW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Cygwin\\setup"), TEXT("rootdir"), &keyType, &rootPath, &rootPathSize);
        if (result != ERROR_SUCCESS || keyType != REG_SZ)
            return false;
    }

    windowsPath = wstring(rootPath, rootPathSize);

    int oldPos = isFileProtocol ? 8 : 1;
    while (1) {
        int newPos = cygwinPath.find('/', oldPos);

        if (newPos == -1) {
            wstring pathComponent = cygwinPath.substr(oldPos);

            if (!appendComponentToPath(windowsPath, pathComponent))
               return false;

            if (!followShortcuts(windowsPath))
                return false;

            break;
        }

        wstring pathComponent = cygwinPath.substr(oldPos, newPos - oldPos);
        if (!appendComponentToPath(windowsPath, pathComponent))
            return false;

        if (!followShortcuts(windowsPath))
            return false;

        oldPos = newPos + 1;
    }

    if (isFileProtocol)
        windowsPath = fileProtocol + windowsPath;

    return true;
}
Beispiel #16
0
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);
}
Beispiel #17
0
void CAvi2Flv::InsertMediaInfo(const wstring &strIn, const wstring& strOut)
{
	AVIFILEINFO aviInfo = CAviHelper::AVI_GetFileInfo(strIn);
	//转码成功后插数据库
	DVRMEDIA_INFO mi;
	CString strT;
	strT.Format(_T("%d"), aviInfo.dwWidth);
	mi.strViewWidth = strT.GetString();
	strT.Format(_T("%d"), aviInfo.dwHeight);
	mi.strViewHeight = strT.GetString();
	wstring strPath = strIn.substr( SHAREDATA.g_strFilePath.GetLength() + 1);
	wstring str = strPath.substr(0, strPath.find(_T("\\")) );
	mi.strDvrNumber = str;

	CTime tm = CTime::GetCurrentTime();
	mi.strDataUploadTime = tm.Format(_T("%Y-%m-%d %H:%M:%S"));
	mi.strDataIp = SHAREDATA.g_pMainFrame->GetIpAddr().c_str();
	mi.strFileName = strIn.substr(strIn.rfind(_T("\\")) + 1);

	CFile localFile;
	if(!localFile.Open(strIn.c_str(), CFile::modeRead|CFile::shareDenyNone))
	{
		strT.Format(_T("%s"), 0);
	}
	else
	{
		strT.Format(_T("%d"), localFile.GetLength());
		localFile.Close();
	}
	mi.strFileSize = strT;

	mi.strFileType = _T("AVI");
	strT.Format(_T("%d"), aviInfo.dwRate / aviInfo.dwScale);
	mi.strFrameRate = strT;

	//wstring sFtpip, sFtpport, sIISip, sIISport;
	//bool bRlt = DB.QueryIpPortByDevId(SHAREDATA.g_strDeviceId.GetString(), sFtpip, sFtpport, sIISip, sIISport);

	strPath = strOut.substr(SHAREDATA.g_strFilePath.GetLength() + 1);
	mi.strFtpFileUrl = strPath; //_T("ftp://") + sFtpip + _T(":") + sFtpport  + _T("//") +  strPath;
	mi.strIISFileUrl = strPath; //_T("http://") + sIISip + _T(":") + sIISport + _T("//") + strPath;
	mi.strLocateFilePath = strIn.c_str();
	strT.Format(_T("%d"), aviInfo.dwRate / aviInfo.dwScale * aviInfo.dwLength);
	mi.strMediaDuration = strT;	//毫秒

	mi.strMediaStartTime = GetStartTime(strIn);
	mi.strMediaEndTime = AddTime(mi.strMediaStartTime, mi.strMediaDuration);
	mi.strRecordTime = mi.strMediaStartTime;

	mi.strRemark = _T(" ");
	mi.strVideoType = _T("AVI");

	DB.InsertMediaInfo(mi);
}
Beispiel #18
0
wstring CrabStringFindWholeWord(const wstring &t, size_t pos, const wstring &BreakupMark, const wstring &BreakupMarkOnceMore)
{
    wstring foundstr;
    if(0==pos) {
        wstring strR = t;
        size_t foundposL = 0;
        size_t foundposR = t.find(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposR){foundposR = strR.find(BreakupMarkOnceMore);}else{
                if(strR.find(BreakupMarkOnceMore)<foundposR){foundposR=strR.find(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposR){foundposR=t.length()-1;}else{
            foundposR=foundposR-1;
        }
        foundstr = t.substr(foundposL,foundposR-foundposL+1);
    } else if(t.length()-1==pos) {
        wstring strL = t;
        size_t foundposL = t.rfind(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposL){foundposL = strL.rfind(BreakupMarkOnceMore);}else{
                if(strL.rfind(BreakupMarkOnceMore)>foundposL){foundposL=strL.rfind(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposL){foundposL=0;}else{
            foundposL=foundposL+1;
        }
        size_t foundposR = t.length()-1;
        foundstr = t.substr(foundposL,foundposR-foundposL+1);
    } else if(0<pos && t.length()-1>pos) {
        wstring strL = t.substr(0,pos);
        wstring strR = t.substr(pos);
        size_t foundposL = strL.rfind(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposL){foundposL = strL.rfind(BreakupMarkOnceMore);}else{
                if(strL.rfind(BreakupMarkOnceMore)>foundposL){foundposL=strL.rfind(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposL){foundposL=0;}else{
            foundposL=foundposL+1;
        }
        size_t foundposR = strR.find(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposR){foundposR = strR.find(BreakupMarkOnceMore);}else{
                if(strR.find(BreakupMarkOnceMore)<foundposR){foundposR=strR.find(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposR){foundposR=t.length()-1;}else{
            foundposR=foundposR-1+pos;
        }
        foundstr = t.substr(foundposL,foundposR-foundposL+1);
    }
    return foundstr;
}
Beispiel #19
0
/**
Remove leading and trailing spaces from the string ~FlakCommon by Motah.
*/
wstring Trim(wstring wscIn)
{
	while(wscIn.length() && (wscIn[0]==L' ' || wscIn[0]==L'	' || wscIn[0]==L'\n' || wscIn[0]==L'\r') )
	{
		wscIn = wscIn.substr(1);
	}
	while(wscIn.length() && (wscIn[wscIn.length()-1]==L' ' || wscIn[wscIn.length()-1]==L'	' || wscIn[wscIn.length()-1]==L'\n' || wscIn[wscIn.length()-1]==L'\r') )
	{
		wscIn = wscIn.substr(0, wscIn.length()-1);
	}
	return wscIn;
}
Beispiel #20
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;
}
wstring extract_file_path(const wstring& path) {
  size_t pos = path.rfind(L'\\');
  if (pos == wstring::npos) {
    pos = 0;
  }
  size_t path_root_len;
  bool is_unc_path;
  locate_path_root(path, path_root_len, is_unc_path);
  if ((pos <= path_root_len) && (path_root_len != 0))
    return path.substr(0, path_root_len).append(1, L'\\');
  else
    return path.substr(0, pos);
}
Beispiel #22
0
void Split(wstring str, vector<wstring>& tokens, const TCHAR delim = ' ') {
	if (str.size() == 0) return;
	int start = 0;
	for(uint i = 0; i < str.size(); i++) {
		if (str[i] == delim) {
			if (i != 0) 
				tokens.push_back(str.substr(start,i-start));
			start = i+1;
		}
	}
	if (str[str.size()-1] != delim) {
		tokens.push_back(str.substr(start, str.size()-start));
	}
}
Beispiel #23
0
 CTaskInfo::CTaskInfo(wstring filePath)
 {
 	m_Index = 0;
 	m_strFilePath = filePath;
 	int nPos = filePath.rfind('.');
 	m_strFileExtent = filePath.substr(nPos);
 	nPos = filePath.rfind('\\');
 	m_strFileName = filePath.substr(nPos+1);
 	m_strFileNameWithoutExt = m_strFileName.substr(0,m_strFileName.find('.'));
 	wstring strFileExtent = _tcslwr((wchar_t*)m_strFileExtent.c_str());
 //	map<wstring,int>::iterator Iter = theApp.m_pConfig->m_MapFileType.find(strFileExtent);
 // 	if (Iter!=theApp.m_pConfig->m_MapFileType.end())
 // 	{
 // 		//说明找到
 // 		m_nFileType = theApp.m_pConfig->m_MapFileType[m_strFileExtent];
 // 	}
 // 	else
 // 	{
 // 		g_Logger.Debug(__FILE__,__LINE__,_T("没有对应的文件类型%s"),m_strFileExtent.c_str());
 // 	}
 // 	if (_tcsicmp(m_strFileExtent.c_str(),_T(".doc")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_DOC;
 // 	}
 // 	else if(_tcsicmp(m_strFileExtent.c_str(),_T(".docx")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_DOCX;
 // 
 // 	}
 // 	else if(_tcsicmp(m_strFileExtent.c_str(),_T(".wps")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_WPS;
 // 	}
 // 	else if(_tcsicmp(m_strFileExtent.c_str(),_T(".xls")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_XLS;
 // 	}
 // 	else if(_tcsicmp(m_strFileExtent.c_str(),_T(".xlt")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_XLT;
 // 	}
 // 	else if(_tcsicmp(m_strFileExtent.c_str(),_T(".xlsx")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_XLSX;
 // 	}
 // 	else if(_tcsicmp(m_strFileExtent.c_str(),_T(".et")) ==0)
 // 	{
 // 		m_nFileType = FILETYPE_ET;
 // 	}
 }
Beispiel #24
0
static bool resolveCygwinPath(const wstring& cygwinPath, wstring& windowsPath)
{
    wstring fileProtocol = L"file://";
    bool isFileProtocol = cygwinPath.find(fileProtocol) != string::npos;
    if (cygwinPath[isFileProtocol ? 7 : 0] != '/')  // ensure path is absolute
        return false;

    // Get the Root path.
    WCHAR rootPath[MAX_PATH];
    DWORD rootPathSize = _countof(rootPath);
    DWORD keyType;
    DWORD result = ::SHGetValueW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/"), TEXT("native"), &keyType, &rootPath, &rootPathSize);

    if (result != ERROR_SUCCESS || keyType != REG_SZ)
        return false;

    windowsPath = wstring(rootPath, rootPathSize);

    int oldPos = isFileProtocol ? 8 : 1;
    while (1) {
        int newPos = cygwinPath.find('/', oldPos);

        if (newPos == -1) {
            wstring pathComponent = cygwinPath.substr(oldPos);

            if (!appendComponentToPath(windowsPath, pathComponent))
               return false;

            if (!followShortcuts(windowsPath))
                return false;

            break;
        }

        wstring pathComponent = cygwinPath.substr(oldPos, newPos - oldPos);
        if (!appendComponentToPath(windowsPath, pathComponent))
            return false;

        if (!followShortcuts(windowsPath))
            return false;

        oldPos = newPos + 1;
    }

    if (isFileProtocol)
        windowsPath = fileProtocol + windowsPath;

    return true;
}
wstring
TransferRule::get_attribute_for_tag(wstring &tag, wstring &pos) {
	wstring attrname=L"";
	if(tag.size() >= 10 && tag.substr(0,10)==L"empty_tag_")
		attrname=L"learned_"+tag.substr(10);
	else
	{
		for ( map<wstring, pair< set<wstring>, set<wstring> > >::iterator  it=  attributes.begin() ; it != attributes.end(); it++ ){
			//wcerr<<L"looking for '"+tag+L"' in '"+(*it).first+L"'"<<endl;
			if ((*it).second.first.find(tag)!=(*it).second.first.end() && ((*it).second.second.size() ==0 || (*it).second.second.find(pos) != (*it).second.second.end() ) )
				attrname=L"learned_"+(*it).first;
		}
	}
	return attrname;
}
Beispiel #26
0
/***************************************************************************
 *      bindBuiltinMethod
 ***************************************************************************/
bool CCilVm::bindBuiltinMethod( const wstring& strQualifiedName,
                                PMETHOD const pMethod,
                                const int32_t iLength )
{
    bool bReturn = true;
    RID ridMethod = getMetaData().queryBuiltinMethodRid( strQualifiedName );
    if( ridMethod == RID_NULL )
        return false;

    //Bind the API
    METHOD_DEF& method = getMetaData().getMethod( ridMethod );
    if( method.MethodType != METHOD_NATIVE )
        return false;
    method.lpFunction = pMethod;

    if( strQualifiedName.find( STRING_INTERNAL_SCOPEDELIMITER ) != wstring::npos )
    {
        wstring strRoot = strQualifiedName.substr( 0, strQualifiedName.rfind( STRING_INTERNAL_SCOPEDELIMITER ) );
        assert( strRoot.find( STRING_INTERNAL_SCOPEDELIMITER ) == wstring::npos );

        wstring strLeaf = strQualifiedName.substr( strQualifiedName.rfind( STRING_INTERNAL_SCOPEDELIMITER ) + 1,
                          strQualifiedName.length() );
        RID ridObject = getMetaData().queryBuiltinObjectRid( strRoot );
        if( ridObject == RID_NOTDEFINED )
            return false;

        //Create property
        getPrototypeObject( ridObject ).setProperty( this,
                strLeaf,
                ridMethod,
                iLength );
    }
    else
    {
        //Global method
        //e.g. print, eval etc
        //Those one need to have correspond static field to keep properties
        CG_SYMBOL_INFORMATION& info = querySymbolInformation( strQualifiedName + STRING_OBJECTNAME_POSTFIX );
        assert( info.Flags == CG_SYMBOL_FLAG_GLOBAL );

        RID rid = info.rid;
        assert( rid != RID_NOTDEFINED );
        if( rid )
            setStaticFieldFunctionObject( rid, ridMethod );
    }

    return bReturn;
}
Beispiel #27
0
bool FixPath(wstring& path) {
	// Fix unix paths
	std::replace( path.begin(), path.end(), L'/', L'\\' );

	// Remove double slashes
	while(true) {
		size_t p = path.find(L"\\\\");
		if (p == string::npos) break;
		path.replace(p, 2, L"\\");
	}


	// Are we pointing at a real destination?
	if (DirectoryExists(path)) {
		if (path[path.length()-1] != L'\\')
			path += L'\\';
		return true;
	} else if (path.at(path.length() - 1) == L'\\') {
		// It says its a directory but it's not, must be a file
		path = path.substr(0, path.length() - 1);
	}

	return FileExists(path);
	
}
Beispiel #28
0
bool CRealTextParser::ExtractString(wstring& p_rszLine, wstring& p_rszString)
{
	if (p_rszLine.length() == 0 || p_rszLine.at(0) == '<')
	{
		if (m_bTryToIgnoreErrors)
		{
			p_rszString = L"";
			return true;
		}
		else
		{
			return false;
		}
	}

	unsigned int iPos = 0;

	if (!SkipSpaces(p_rszLine, iPos))
		return false;

	if (!GetString(p_rszLine, iPos, p_rszString, L"<"))
		return false;

	p_rszLine = p_rszLine.substr(iPos);
	return true;
}
Beispiel #29
0
inline void fillExplicitTableHeadersForCell(VBufStorage_controlFieldNode_t& cell, int docHandle, wstring& headersAttr, fillVBuf_tableInfo& tableInfo) {
	wostringstream colHeaders, rowHeaders;

	// The Headers attribute string is in the form "id id ..."
	// Loop through all the ids.
	size_t lastPos = headersAttr.length();
	size_t startPos = 0;
	while (startPos < lastPos) {
		// Search for a space, which indicates the end of this id.
		size_t endPos = headersAttr.find(L' ', startPos);
		if (endPos == wstring::npos)
			endPos=lastPos;
		// headersAttr[startPos:endPos] is the id of a single header.
		// Find the info for the header associated with this id string.
		map<wstring, TableHeaderInfo>::const_iterator it = tableInfo.headersInfo.find(headersAttr.substr(startPos, endPos - startPos));
		startPos = endPos + 1;
		if (it == tableInfo.headersInfo.end())
			continue;

		if (it->second.type & TABLEHEADER_COLUMN)
			colHeaders << docHandle << L"," << it->second.uniqueId << L";";
		if (it->second.type & TABLEHEADER_ROW)
			rowHeaders<< docHandle << L"," << it->second.uniqueId << L";";
	}

	if (colHeaders.tellp() > 0)
		cell.addAttribute(L"table-columnheadercells", colHeaders.str());
	if (rowHeaders.tellp() > 0)
		cell.addAttribute(L"table-rowheadercells", rowHeaders.str());
}
      /// <summary>Parses the page identifier</summary>
      /// <param name="pageid">The pageid</param>
      /// <param name="v">The associated game version</param>
      /// <returns>Normalised page ID</returns>
      /// <exception cref="Logic::InvalidValueException">Invalid pageID</exception>
      UINT  LanguageFileReader::ParsePageID(const wstring&  pageid, GameVersion&  v)
      {
         // X2: nnnn 
         if (pageid.length() <= 4)
         {
            v = GameVersion::Threat;
            return _wtoi(pageid.c_str());
         }
         // X3: NNnnnn
         else if (pageid.length() != 6)
            throw InvalidValueException(HERE, VString(L"Invalid page ID '%s'", pageid.c_str()) );

         // X3R: 30nnnn
         else if (pageid.compare(0, 2, L"30") == 0)
            v = GameVersion::Reunion;
         
         // X3TC: 35nnnn
         else if (pageid.compare(0, 2, L"35") == 0)
            v = GameVersion::TerranConflict;

         // X3AP: 38nnnn
         else if (pageid.compare(0, 2, L"38") == 0)
            v = GameVersion::AlbionPrelude;
         else
            throw InvalidValueException(HERE, VString(L"Invalid page ID '%s'", pageid.c_str()) );

         // Convert last four digits of page ID
         return _wtoi(pageid.substr(2).c_str());
      }