Пример #1
0
wstring urlSuitableForTestResult(const wstring& url)
{
    if (!url.c_str() || url.find(L"file://") == wstring::npos)
        return url;

    return PathFindFileNameW(url.c_str());
}
Пример #2
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;
}
Пример #3
0
/*
 * Adds table header info for a single cell which explicitly defines headers
 * using the Headers attribute.
 */
inline void fillExplicitTableHeadersForCell(AdobeAcrobatVBufStorage_controlFieldNode_t& cell, int docHandle, wstring& headersAttr, TableInfo& tableInfo) {
	wostringstream colHeaders, rowHeaders;

	// The Headers attribute string is in the form "[[id id ... ]]"
	// Loop through all the ids.
	// Ignore the "[[" prefix and the " ]]" suffix.
	size_t lastPos = headersAttr.length() - 3;
	size_t startPos = 2;
	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)
			break;
		// 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());
}
Пример #4
0
int WinContactSIF::parse(const wstring & data) {

    if (!sifFields) {
        LOG.error("%s", ERR_SIFFIELDS_NULL);
        return 1;
    }
    propertyMap.clear();

    // Check if <contact> tag is present...
    wstring::size_type pos = 0;
    wstring itemTypeTag = L"<contact>";    
    pos = data.find(itemTypeTag, 0);
    if (pos == wstring::npos) {
        LOG.error("Tag '%ls' not found", itemTypeTag.c_str());
        return 1;
    }
    wstring propertyValue;
       
    for (int i=0; sifFields[i]; i++) {
        // Set only properties found!
        if (!getElementContent(data, sifFields[i], propertyValue, 0)) {

            replaceAll(L"&lt;",  L"<", propertyValue);
            replaceAll(L"&gt;",  L">", propertyValue);
            replaceAll(L"&amp;", L"&", propertyValue);
            
            setProperty(sifFields[i], propertyValue);
        }
    }   
    return 0;
}
Пример #5
0
bool IsURL(wstring const &str)
{
	if(str.find(TEXT(" "), 0) != wstring::npos)
	{
		return false;
	}

	wstring upr(UpperCase(str));

	if(upr.compare(0, 7, TEXT("HTTP://")) == 0 || upr.compare(0, 8, TEXT("HTTPS://")) == 0)
	{
		return true;
	}

	WCHAR **tld = gTopLevelDomains;
	while(*tld != nullptr)
	{
		if(upr.find(*tld, 0) != wstring::npos)
		{
			return true;
		}
		++tld;
	}
	return false;
}
Пример #6
0
bool FileList::setCurrentFile(const wstring &current_file)
{
    wstring base_path = FilePath::cleanUpPath(_baseDirectory.getPath()) + L"\\";;
    if (current_file.find(base_path) != 0) {
        return false;
    }

    if (base_path.length() == current_file.length()) {
        return false;
    }

    vector<wstring> split_path;
    FilePath::splitFilePath(current_file.substr(base_path.length()), split_path);

    wstring current_path = base_path;
    for (vector<wstring>::iterator i = split_path.begin(); i != split_path.end(); ++i) {
        wstring name = *i;
        current_path += name + L"\\";

        FileInfo fileInfo(current_path);
        if (fileInfo.isDirectory()) {
            Directory *next_directory = new Directory(current_path);
            _directories.top()->setCurrentSubDirectory(name);
            _directories.push(next_directory);
        }
        else if (fileInfo.isFile()) {
            return _directories.top()->setCurrentFile(name);
        }
        else {
            return false;
        }
    }
    return false;
}
Пример #7
0
wstring QueryAssembler::interpolate(const wstring& rule, const shared_ptr<IMatch>& match, const NetEvaluator& evaluator)
{
	unordered_map<wstring, wstring> evaluation = evaluator.Evaluate(match, currentFrameTense); //evaluator calculates all values which could be interpolated into the template

	wstring filler;
	
	wstring toReturn = rule;

	size_t c_pos = 0;
	size_t pos = 0;

	while((pos = rule.find(L"${", c_pos)) != wstring::npos) //replace all placeholders in the template with calculated values
	{
		size_t pos2 = rule.find(L"}", pos);
		if(pos2 == wstring::npos)
		{
			throw EInvalidSlotRule(match->GetNetName().c_str());
		}

		wstring placeHolder = rule.substr(pos + 2, pos2 - pos - 2);

		size_t point_pos;

		if((point_pos = placeHolder.find(L".")) != wstring::npos) //reference to subfield ".field" is supported
		{
			wstring field = placeHolder.substr(point_pos + 1);
			if(evaluation.find(field) == evaluation.end())
			{
				throw ENoExistingFieldReference(match->GetNetName().c_str());
			}
			filler = evaluation.at(field);
		}
		else
		{
			filler = evaluation.at(NetEvaluator::VALUE); //if no field is referenced field .VALUE is referenced by default
		}

		c_pos = pos2;

		size_t repl1 = toReturn.find(L"${");
		size_t repl2 = toReturn.find(L"}") + 1;

		toReturn.replace(repl1, repl2 - repl1, filler);
	}

	return toReturn;
}
Пример #8
0
void CParseSearchChgText::ChgText(wstring& chgText)
{
	for( size_t i = 0; i<this->chgKey.size(); i++ ){
		if( chgText.find( this->chgKey[i].oldText ) != string::npos ){
			Replace(chgText, this->chgKey[i].oldText, this->chgKey[i].newText);
		}
	}
}
Пример #9
0
wstring substr_after(const wstring& s, const wstring& skip) {
	size_t p = s.find(skip);
	if (p == wstring::npos) {
		return NULL;
	}
	
	return s.substr(skip.length() + p);
}
Пример #10
0
wstring 
Utils::get_tag_value(wstring tags, wstring values) {
  vector<wstring> pval=StringUtils::split_wstring(values,L"|");

  for(wstring::size_type i=0; i<pval.size(); i++) {
    if (tags.find(pval[i]) != wstring::npos)
    {
		int pos=tags.find(pval[i]);
		if( (pos==0 || tags[pos-1]==L'.') && (pos==tags.size()-1 || tags[pos+1]==L'.'))
			return pval[i];
		else
			return L"";
    }
  }

  return L"";
}
Пример #11
0
			// 根据相对路径获取绝对路径
			// 如果relativePath已经是绝对路径,则直接返回
			// 否则将返回appPath+relativePath
			wstring getAbsolutePath(wstring &relativePath, wstring &appPath){
				if (relativePath.find(L":") == -1){// 如果指定的路径是相对路径
					wstring _path(appPath);
					_path.append(relativePath);
					return _path;
				}
				return relativePath;
			}
Пример #12
0
bool Inet::StatusCodeAnalysis(wstring sctext,int* res){
	int i,n,pos;
	wchar_t *err;
	if(pos=sctext.find(' ')==wstring::npos){
		return false;
	}
	sctext.erase(0,pos+1);
	if(pos=sctext.find(' ')==wstring::npos){
		return false;
	}
	sctext.erase(pos);
	*res=wcstol(sctext.c_str(),&err,10);
	if(lstrlen(err)!=0){
		return false;
	}
	return true;
}
Пример #13
0
wstring
Utils::get_tags(wstring word) {
  wstring::size_type p=word.find(L"<",0);
  if (p!=wstring::npos)
    return word.substr(p, word.size()-p);
  else //Unknown word, no tags for it
    return L"";
}
Пример #14
0
bool CRealTextParser::GetString(wstring& p_rszLine, unsigned int& p_riPos, wstring& p_rszString, const wstring& p_crszEndChars)
{
    while (p_rszLine.length() > p_riPos && p_crszEndChars.find(p_rszLine.at(p_riPos)) == wstring::npos) {
        p_rszString += p_rszLine.at(p_riPos);
        ++p_riPos;
    }

    return p_rszLine.length() > p_riPos;
}
Пример #15
0
wstring NBTools::doReplace(wstring text, wstring find, wstring replace)
{
    while (true)
    {
        size_t pos = text.find(find);
        if (0 > pos || pos > text.length()) return text;
        text = text.replace(pos, find.length(), replace);
    }
}
Пример #16
0
	template<> void WXML::constructKey(wstring &str)
	{
		long startX = str.find('<') + 1;
		long endX =
			Math::calcMin<long>
			(
		{
			indexFilter(str.find(' ', startX)),
			indexFilter(str.find('\n', startX)),
			indexFilter(str.find('\t', startX)),
			indexFilter(str.find('>', startX)),
			indexFilter(str.find('/', startX))
		}
		).getValue();

		//Determinate the KEY
		key = move(WStringUtil::substring(str, startX, endX));
	}
Пример #17
0
vector<wstring> UnitConverter::StringToVector(const wstring& w, const wchar_t * delimiter, bool addRemainder)
{
    size_t delimiterIndex = w.find(delimiter);
    size_t startIndex = 0;
    vector<wstring> serializedTokens = vector<wstring>();
    while (delimiterIndex != w.npos)
    {
        serializedTokens.push_back(w.substr(startIndex, delimiterIndex - startIndex));
        startIndex = delimiterIndex + (int)wcslen(delimiter);
        delimiterIndex = w.find(delimiter, startIndex);
    }
    if (addRemainder)
    {
        delimiterIndex = w.size();
        serializedTokens.push_back(w.substr(startIndex, delimiterIndex - startIndex));
    }
    return serializedTokens;
}
Пример #18
0
wstring GetNewVersion(wstring txt)
{
    wstring startTag = L"<version>";

    size_t spos = txt.find(startTag);
    if (spos == wstring::npos)
    {
        return L"";
    }

    size_t epos = txt.find(L"</version>", spos);
    if (epos == wstring::npos)
    {
        return L"";
    }

    spos += startTag.length();
    return txt.substr(spos, epos - spos);
}
Пример #19
0
wstring
Utils::get_lemma(wstring word) {
  wstring s=L"";

  wstring::size_type p=word.find(L"<",0);
  if (p!=wstring::npos)
    s=word.substr(0, p);

  return s;
}
Пример #20
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;
}
Пример #21
0
wstring CWaveSession::GetKeyFromSessionResponse(wstring szKey, wstring & szResponse) const
{
	// TODO: Extend the Json library to include this functionality.

	ASSERT(!szKey.empty());

	INT nOffset = 0;

	while (nOffset != string::npos)
	{
		nOffset = szResponse.find(szKey + L":'", nOffset);

		if (nOffset != string::npos)
		{
			CHAR cBefore = nOffset == 0 ? '\0' : szResponse[nOffset - 1];

			nOffset += szKey.length() + 1;

			if (!iswalnum(cBefore) && cBefore != '_')
			{
				break;
			}
		}
	}

	if (nOffset != string::npos)
	{
		nOffset = szResponse.find(L'\'', nOffset) + 1;
	}

	if (nOffset != string::npos)
	{
		INT nEnd = szResponse.find(L'\'', nOffset);

		if (nEnd != string::npos)
		{
			return szResponse.substr(nOffset, nEnd - nOffset);
		}
	}

	return L"";
}
Пример #22
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;
}
Пример #23
0
/* -----------------------------------------------------------------------
 *  関数名  :  ws_replace
 *  機能概要:  str内のbeforeをすべてafterに置換します
 * -----------------------------------------------------------------------
 */
void	ws_replace(wstring &str, const wstring &before, const wstring &after)
{
	int	sz_bef = before.size();
	int	sz_aft = after.size();
	for(int rp_pos = 0; ; rp_pos += sz_aft) {
		rp_pos = str.find(before, rp_pos);
		if (rp_pos == -1)
			break;
		str.replace(rp_pos, sz_bef, after);
	}
}
Пример #24
0
inline wstring VertifyFilename( const wstring& sFilename )
{
	static wstring wsCHarMap1 = L"\\/:*\"|<>?!'";
	static wstring wsCHarMap2 = SConv("\xEF\xBC\xBC\xEF\xBC\x8F\xEF\xBC\x9A\xEF\xBC\x8A\xEF\xBC\x82\xEF\xBD\x9C\xEF\xBC\x9C\xEF\xBC\x9E\xEF\xBC\x9F\xEF\xBC\x81\xE2\x80\x99");

	wstring sNewName = sFilename;
	while( true )
	{
		size_t uPos = sNewName.find_first_of( wsCHarMap1 );
		if( uPos == wstring::npos )
			break;

		auto x1 = sNewName[uPos];
		auto x2 = wsCHarMap1.find( sNewName[uPos] );
		auto x3 = wsCHarMap1[ wsCHarMap1.find( sNewName[uPos] ) ];

		sNewName[uPos] = wsCHarMap2[ wsCHarMap1.find( sNewName[uPos] ) ];
	}
	return sNewName;
}
void StringUtilities::ReplaceAll(wstring &str, const wstring &search, const wstring &replace)
{
    for (size_t pos = 0;; pos += replace.length() - 1)
    {
        pos = str.find(search, pos);
        if (pos == string::npos) break;

        str.erase(pos, search.length());
        str.insert(pos, replace);
    }
}
Пример #26
0
void string_replace( wstring& strBig, const wstring& strSrc, const wstring& strDst )
{
	wstring::size_type pos=0;
	wstring::size_type srclen = strSrc.size();
	wstring::size_type dstlen = strDst.size();
	while( (pos=strBig.find(strSrc, pos)) != wstring::npos)
	{
		strBig.replace(pos, srclen, strDst);
		pos += dstlen;
	}
}
Пример #27
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;
}
Пример #28
0
wstring extract_version_number(const wstring& text, const wstring& ver_name) {
  size_t pos = text.find(ver_name);
  CHECK(pos != wstring::npos);
  pos += ver_name.size();
  while (pos < text.size() && (text[pos] == L' ' || text[pos] == L'\t'))
    pos++;
  size_t start_pos = pos;
  while (pos < text.size() && text[pos] >= L'0' && text[pos] <= L'9')
    pos++;
  size_t end_pos = pos;
  return text.substr(start_pos, end_pos - start_pos);
}
// & の削除
static wstring	RemoveAmpersand( wstring sLavel)
{
	size_t	nPos =0;
	while ((nPos = sLavel.find( L"&", nPos)) != wstring::npos) {
		if (sLavel[nPos+1] == L'&') {
			// &&
			sLavel.replace( nPos, 1, L"");
		}
		nPos ++;
	}
	return sLavel;
}
Пример #30
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;
}