Пример #1
0
    bool findPattern(
            const std::vector<std::vector<wchar_t> >& matrix,
            const std::wstring& pattern,
            std::stack<LetterPoint>& path)
    {
        boost::unordered_map<wchar_t, std::vector<LetterPoint> > map;
        for (size_t i = 0 ; i < matrix.size() ; ++i)
        {
            for (size_t j = 0 ; j < matrix.at(i).size() ; ++j)
            {
                map_type::value_type initList(matrix.at(i).at(j), std::vector<LetterPoint>());
                map.insert(initList);
                map_type::iterator iterator = map.find(matrix.at(i).at(j));
                iterator->second.push_back(LetterPoint(i, j, matrix.at(i).at(j)));
            }
        }

        if (map.count(pattern.at(0)) == 0)
        {
            return false;
        }

        for (size_t i = 0 ; i < map.find(pattern.at(0))->second.size() ; ++i)
        {
            if (findInMap(map, pattern.substr(1), map.find(pattern.at(0))->second.at(i), path))
            {
                return true;
            }
        }

        return false;
    }
Пример #2
0
		/// 创建此路径上的所有目录
		BOOL CreateAllDirectory(std::wstring strPath)
		{
			if(strPath.length()==0)
			{
				return FALSE;
			}
			for (size_t i=0;i<strPath.length();i++)
			{
				std::wstring::reference r=strPath.at(i);
				if(r==L'/')
				{
					r=L'\\';
				}
			}
			if(strPath.at(strPath.length()-1)!=L'\\')
			{
				strPath+=L"\\";
			}

			std::wstring::size_type nPos=0;
			for(nPos = 0; nPos < strPath.length(); ++nPos)
			{
				nPos=strPath.find(L"\\",nPos);
				if(nPos<0)
				{
					break;
				}
				std::wstring strDir=strPath.substr(0,nPos);
				CreateDirectory(strDir.c_str(),NULL);
			}
			return TRUE;
		}
Пример #3
0
/* ComplexDMXMacro */
ComplexDMXMacro::ComplexDMXMacro(DMXController* controller, std::wstring address, DMXSource src, bool invert) {
	_controller = controller;
	_address = address;
	_source = src;
	_invert = invert;

	if(address.length()<1) return;

	if(address.at(0)==L'-') {
		address = address.substr(1);
	}

	if(address.at(0)==L'm') {
		address = address.substr(1);
	}
	// parse address
	std::vector<std::wstring> parts = Explode<std::wstring>(address, std::wstring(L","));
	std::vector<std::wstring>::iterator it = parts.begin();
	while(it!=parts.end()) {
		std::wstring nr = *it;
		DMXSlot channel = DMXController::ParseChannelNumber(nr);
		
		if(channel>-1 && channel < 514) {
			_controller->_highestChannelUsed = Util::Max(_controller->_highestChannelUsed, channel);
			_channels.push_back(channel);
		}

		++it;
	}
}
Пример #4
0
bool CRealTextParser::GetString(std::wstring& p_rszLine, unsigned int& p_riPos, std::wstring& p_rszString, const std::wstring& p_crszEndChars)
{
    while (p_rszLine.length() > p_riPos && p_crszEndChars.find(p_rszLine.at(p_riPos)) == std::wstring::npos) {
        p_rszString += p_rszLine.at(p_riPos);
        ++p_riPos;
    }

    return p_rszLine.length() > p_riPos;
}
Пример #5
0
 void moveWordRight(bool modifySelection)
 {
     while (caretPos < text.length() && std::iswspace(text.at(caretPos)))
         ++caretPos;
     
     while (caretPos < text.length() && !std::iswspace(text.at(caretPos)))
         ++caretPos;
     
     if (modifySelection)
         selectionStart = caretPos;
 }
Пример #6
0
 void moveWordLeft(bool modifySelection)
 {
     if (caretPos == text.length())
         --caretPos;
     
     while (caretPos > 0 && std::iswspace(text.at(caretPos - 1)))
         --caretPos;
     
     while (caretPos > 0 && !std::iswspace(text.at(caretPos - 1)))
         --caretPos;
     
     if (modifySelection)
         selectionStart = caretPos;
 }
void CSalsitaExtensionHelper::ResourcesDirNormalize(std::wstring &resourcesDir)
{
  if (resourcesDir.size() && resourcesDir.at(resourcesDir.size()-1) != L'\\')
  {
    resourcesDir.append(L"\\");
  }
}
Пример #8
0
void replace(std::wstring &s, wchar_t before, wchar_t after)
{
    const std::wstring::size_type size = s.size();
    for (std::wstring::size_type i = 0; i < size; ++i)
        if (s.at(i) == before)
            s[i] = after;
}
Пример #9
0
void EjectOSD::EjectDrive(std::wstring driveLetter) {
    std::wstring name = L"\\\\.\\" + driveLetter + L":";
    CLOG(L"Ejecting %s", name.c_str());

    HANDLE dev = CreateFile(name.c_str(),
        GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
    if (dev == INVALID_HANDLE_VALUE) {
        CLOG(L"Failed to get device handle");
        return;
    }

    DWORD bytesReturned = 0;
    bool success = DeviceIoControl(dev, FSCTL_LOCK_VOLUME,
        NULL, NULL, NULL, NULL, &bytesReturned, NULL)
    && DeviceIoControl(dev, FSCTL_DISMOUNT_VOLUME,
        NULL, NULL, NULL, NULL, &bytesReturned, NULL)
    && DeviceIoControl(dev, IOCTL_STORAGE_EJECT_MEDIA,
        NULL, NULL, NULL, NULL, &bytesReturned, NULL);

    if (success) {
        std::wstring rootPath = driveLetter + L":\\";
        if (GetDriveType(rootPath.c_str()) != DRIVE_CDROM) {
            int driveBit = (int) pow(2, (driveLetter.at(0) - 65));
            _ignoreDrives |= driveBit;
            CLOG(L"Added drive bit %d to ignore list", driveBit);
        }
        HideOthers(Eject);
        _mWnd.Show();
    }

    CloseHandle(dev);
}
Пример #10
0
bool CRegUtil::GetValue(const wchar_t* const name, std::wstring& strValue)
{
    const int nSize = 1024;
    std::vector<BYTE> buffer;
    DWORD dwLength = 0;
    DWORD dwType = REG_NONE;

    buffer.resize(nSize);
    void* pBuffer = &buffer[0];
    LONG lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
    if((lResult != ERROR_MORE_DATA && lResult != ERROR_SUCCESS)
        || (dwType != REG_SZ)
        || dwLength == 0)
    {
        return false;
    }

    if(lResult == ERROR_MORE_DATA)
    {
        buffer.resize(dwLength);
        pBuffer = &buffer[0];
        lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
    }

    if(lResult != ERROR_SUCCESS)
        return false;

    strValue.assign((const wchar_t*)pBuffer, dwLength / sizeof(wchar_t));
    if(strValue.at(strValue.size() - 1) == 0)
        strValue.resize(strValue.size() - 1);
    return true;
}
Пример #11
0
std::wstring getTemplateFilter(const std::wstring & templateContent)
{
    size_t idx_template = templateContent.find(L"$TEMPLATE_FILEFILTER:");
    std::wstring line;
    if(idx_template != std::wstring::npos)
    {
        idx_template += wcslen(L"$TEMPLATE_FILEFILTER:");
        size_t EOL = templateContent.find(L"\n", idx_template);
        if(EOL == std::wstring::npos)
            EOL = templateContent.size() - idx_template - 1;
        if(templateContent.at(EOL - 1) == L'\r')
            EOL--;
        if(EOL < idx_template)
            EOL = idx_template;
        line = templateContent.substr(idx_template, EOL - idx_template);
    }
    else
    {
        line = LoadWideString(IDS_FILTER);
    }
    for(size_t i = 0; i < line.size(); i++)
        if(line[i] == L'|')
            line[i] = L'\0';
    line.push_back(L'\0');
    return line;
}
Пример #12
0
bool CRealTextParser::SkipSpaces(std::wstring& p_rszLine, unsigned int& p_riPos)
{
    while (p_rszLine.length() > p_riPos && iswspace(p_rszLine.at(p_riPos))) {
        ++p_riPos;
    }

    return p_rszLine.length() > p_riPos;
}
Пример #13
0
std::wstring CRealTextParser::StringToLower(const std::wstring& p_crszString)
{
    std::wstring szLowercaseString;
    for (unsigned int i = 0; i < p_crszString.length(); ++i) {
        szLowercaseString += towlower(p_crszString.at(i));
    }
    return szLowercaseString;
}
Пример #14
0
bool BaseConverter::ReadHex(const std::wstring& src, unsigned int defaultVal, unsigned int& val)
{
	if(src.size()<=0||CheckHexString(src)==false)
	{
		val = defaultVal;
		return false;
	}

	std::wstring src2 = src;
	if (src.size() > 1 && src.at(0) == L'0' && (src.at(1) == L'X' || src.at(1) == L'x'))
	{
		std::wstring str2 = L"";
		for (size_t i = 2; i < src.size(); ++i)
			str2 += src[i];

		src2 = str2;
	}

	// Convert to lower case
	std::wstring src3 = L"";
	for (size_t i = 0; i < src2.size(); ++i)
	{
		if(src2.at(i)==L'A')
			src3 += L'a';
		else if(src2.at(i)==L'B')
			src3 += L'b';
		else if(src2.at(i)==L'C')
			src3 += L'c';
		else if(src2.at(i)==L'D')
			src3 += L'd';
		else if(src2.at(i)==L'E')
			src3 += L'e';
		else if(src2.at(i)==L'F')
			src3 += L'f';
		else
			src3 += src2.at(i);
	}


	std::wstringstream ss;
	ss << std::setbase(16) << src3;
	ss >> val;

	return true;
}
Пример #15
0
// String to integer
int toInt(std::wstring s)
{
	int val = 0;
	
	for(unsigned int i = 0; i < s.length(); i++)
	{
		switch(s.at(i))
		{
			case L'0':
				val = val * 10 + 0;
				break;
			
			case L'1':
				val = val * 10 + 1;
				break;
			
			case L'2':
				val = val * 10 + 2;
				break;
			
			case L'3':
				val = val * 10 + 3;
				break;
			
			case L'4':
				val = val * 10 + 4;
				break;
			
			case L'5':
				val = val * 10 + 5;
				break;
			
			case L'6':
				val = val * 10 + 6;
				break;
			
			case L'7':
				val = val * 10 + 7;
				break;
			
			case L'8':
				val = val * 10 + 8;
				break;
			
			case L'9':
				val = val * 10 + 9;
				break;
			
			// Not an integer
			default:
				return -1;
		}
	}
	
	return val;
};
Пример #16
0
// Return a hash of the encoded data
// Provides mechanism to map DataElement discriminants to variants
// in VariantRecord.
Integer64 HLAunicodeString::hash() const
{
	Integer64 hash = 7;

	const std::wstring value = this->get();
	for( size_t i = 0 ; i < value.length() ; ++i )
		hash = 31 * hash + value.at(i);

	return hash;
}
Пример #17
0
/**
 * Decrypt an encrypted password.
 * 
 * Depending on the N value, the password is decrypted using algorithm 1 or 2.
 * 
 * @param[in]	strCrypted
 * 					The wide character encrypted password to decrypt.
 * 
 * @return	THe decrypted password encoded in UTF-8.
 */
std::string SymmetricDecrypt(const std::wstring &wstrCrypted)
{
	if(!SymmetricIsCrypted(wstrCrypted))
		return "";

	// Remove prefix
	std::string strBase64 = convert_to<std::string>(wstrCrypted.substr(4));
	std::string strXORed = base64_decode(strBase64);

	return SymmetricDecryptBlob(wstrCrypted.at(1) - '0', strXORed);
}
Пример #18
0
std::string wStringToString(const std::wstring &w)
{
    if (w.empty())
        return std::string();
    const std::string::size_type size = w.size();
    std::string rc;
    rc.reserve(size);
    for (std::string::size_type i = 0; i < size; ++i)
        rc.push_back(char(w.at(i)));
    return rc;
}
Пример #19
0
bool ValidateDirectory (std::wstring& aName, const bool aMustExist)
	{
	if (! ValidateFileName (aName, aMustExist)) 
		{
		return false;
		}
	if (aName.at (aName.size () - 1) != L'/') 
		{
		aName += L'/';
		}
	return true;
	}
Пример #20
0
bool
MSCalibrationForm::parse_formula( const std::wstring& text, std::wstring& formula
							, std::wstring& adduct_lose, bool& isPositive ) const
{
    adduct_lose.clear();

    std::wstring::size_type pos = text.find_first_of( L"+-" );
    if ( pos == std::wstring::npos ) {
        formula = text;
        return !formula.empty();
    } else {
		formula = text.substr( 0, pos);
		if ( text.at( pos ) == L'+' )
			isPositive = true;
		else if ( text.at( pos ) == L'-' )
			isPositive = false;
		else
			return false;
		adduct_lose = text.substr( pos + 1 );
	}
    return true;
}
Пример #21
0
//判断字符串中是否有汉字
bool CCommonInterface::HaveChineseChar(std::wstring arg)
{
	bool bHaveChineseChar = FALSE;
	for (size_t i = 0; i < arg.length(); i++)
	{
		if (arg.at(i) > 255)
		{
			bHaveChineseChar = TRUE;
			break;
		}
	}
	return bHaveChineseChar;
}
Пример #22
0
//=================================================================================================
std::wstring eve::files::normalize_path(const std::wstring & p_path)
{
	std::wstring str(p_path);

#if defined(EVE_OS_WIN)
	size_t inc = 0;
	for (size_t i = 0; i < p_path.length(); i++)
	{
		if (p_path.at(i) == EVE_TXT('\\'))
		{
			str.insert(i + inc, EVE_TXT("\\"));
			inc++;
		}
		else if (p_path.at(i) == EVE_TXT('/'))
		{
			str.replace(i + inc, 1, EVE_TXT("\\"));
		}
	}
#endif

	return str;
}
Пример #23
0
void odf_lists_styles_context::set_bullet_char(std::wstring val)
{
	if ( lists_format_array_.empty() ) return;
	if ( lists_format_array_.back().elements.empty() ) return ;
	
	if ( val.empty() ) return;
	
	text_list_level_style_bullet *style_bullet_ = dynamic_cast<text_list_level_style_bullet *>(lists_format_array_.back().elements.back().get());

	if (style_bullet_ == NULL) return;
	wchar_t char_ = convert_bullet_char(val.at(0));
	style_bullet_->text_list_level_style_bullet_attr_.text_bullet_char_ = char_;
}
Пример #24
0
int CRealTextParser::GetTimecode(const std::wstring& p_crszTimecode)
{
    int iTimecode(0);
    int iMultiplier(1);

    // Exception: if the timecode doesn't contain any separators, assume the time code is in seconds (and change multiplier to reflect that)
    if (p_crszTimecode.find_first_of('.') == std::wstring::npos && p_crszTimecode.find_first_of(':') == std::wstring::npos) {
        iMultiplier = 1000;
    }

    std::wstring szCurrentPart;

    for (ptrdiff_t i = p_crszTimecode.length() - 1; i >= 0; --i) {
        if (p_crszTimecode.at(i) == '.' || p_crszTimecode.at(i) == ':') {
            if (iMultiplier == 1) {
                while (szCurrentPart.length() < 3) {
                    szCurrentPart += L"0";
                }
            }

            iTimecode += iMultiplier * ::_wtoi(szCurrentPart.c_str());

            if (iMultiplier == 1) {
                iMultiplier = 1000;
            } else {
                iMultiplier *= 60;
            }

            szCurrentPart = L"";
        } else {
            szCurrentPart = p_crszTimecode.substr(i, 1) + szCurrentPart;
        }
    }

    iTimecode += iMultiplier * ::_wtoi(szCurrentPart.c_str());

    return iTimecode;
}
Пример #25
0
void EjectOSD::EjectDrive(std::wstring driveLetter) {
    std::wstring name = L"\\\\.\\" + driveLetter + L":";
    CLOG(L"Ejecting %s", name.c_str());

    HANDLE dev = CreateFile(
        name.c_str(),
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        NULL,
        NULL);

    if (dev == INVALID_HANDLE_VALUE) {
        CLOG(L"Failed to get device handle");
        return;
    }

    DWORD bytesReturned = 0;

    DeviceIoControl(dev, FSCTL_LOCK_VOLUME,
        NULL, NULL, NULL, NULL, &bytesReturned, NULL);

    PREVENT_MEDIA_REMOVAL pmr = { 0 };
    pmr.PreventMediaRemoval = FALSE;
    DeviceIoControl(dev, IOCTL_STORAGE_MEDIA_REMOVAL,
        &pmr, sizeof(PREVENT_MEDIA_REMOVAL), NULL, 0, &bytesReturned, NULL);

    DeviceIoControl(dev, FSCTL_DISMOUNT_VOLUME,
        NULL, NULL, NULL, NULL, &bytesReturned, NULL);

    BOOL ejected = FALSE;
    ejected = DeviceIoControl(dev, IOCTL_STORAGE_EJECT_MEDIA,
        NULL, NULL, NULL, NULL, &bytesReturned, NULL);

    if (ejected != FALSE) {
        std::wstring rootPath = driveLetter + L":\\";
        if (GetDriveType(rootPath.c_str()) != DRIVE_CDROM) {
            int driveBit = (int) pow(2, (driveLetter.at(0) - 65));
            _ignoreDrives |= driveBit;
            CLOG(L"Added drive bit %d to ignore list", driveBit);
        }
        if (OSD::Enabled()) {
            HideOthers(Eject);
            _mWnd.Show();
        }
    }

    CloseHandle(dev);
}
Пример #26
0
IniStream::IniStream(std::wstring const& filepath_or_name) {
	if (L':' != filepath_or_name.at(1)) {//2文字目が':'ならフルパス
		wchar_t dir[MAX_PATH];
		if (!GetCurrentDirectory(MAX_PATH, dir)) throw std::runtime_error("IniStream::IniStream : getcurrentdirctory error.");
		//".\\[filepath_or_name]だとファイルが無いときにcreate_UTF16_fileがCurrent Directoryに生成しない"
		this->filefullpath = dir + (L"\\" + filepath_or_name);
	}
	else {
		this->filefullpath = filepath_or_name;
	}
	this->was_no_exist = (!PathFileExists(filefullpath.c_str()));
	if (was_no_exist) {
		create_UTF16_file();
	}
}
Пример #27
0
std::wstring ELStripLeadingSpaces(std::wstring input)
{
  size_t i = 0;

  //< Search input for the first non-space character
  while (i < input.length())
  {
    if (input.at(i) != ' ')
    {
      break;
    }

    i++;
  }

  return input.substr(i, std::wstring::npos);
}
Пример #28
0
bool BaseConverter::CheckHexString(const std::wstring& str)
{
	for(size_t i=0; i<str.size(); ++i)
	{
		wchar_t ch = str.at(i);
		if(ch==L'A'||ch==L'B'||ch==L'C'||ch==L'D'||ch==L'E'||ch==L'F')
			continue;
		if(ch==L'a'||ch==L'b'||ch==L'c'||ch==L'd'||ch==L'e'||ch==L'f')
			continue;
		if(ch==L'0'||ch==L'1'||ch==L'2'||ch==L'3'||ch==L'4'||ch==L'5'||ch==L'6'||ch==L'7'||ch==L'8'||ch==L'9')
			continue;
		if(i==1 && (ch==L'x' || ch==L'X') )
			continue;

		return false;
	}

	return true;
}
Пример #29
0
bool CRealTextParser::ExtractString(std::wstring& p_rszLine, std::wstring& p_rszString)
{
    if (p_rszLine.empty() || 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;
}
Пример #30
0
bool BaseConverter::GetBool(const std::wstring& src, bool defaultVal, bool& val)
{
	if(src.size()<=0)
	{
		val = defaultVal;
		return false;
	}

	std::wstring src2 = L"";
	for(size_t i=0; i<src.size(); ++i)
		src2 += towlower(src.at(i));

	if(src2==L"true"||src2==L"yes"||src2==L"1"||src2==L"ok")
		val = true;
	else if(src2==L"false"||src2==L"no"||src2==L"0"||src2==L"cancel")
		val = false;
	else
	{
		val = defaultVal;
		return false;
	}

	return true;
}