Пример #1
0
//---------------------------------------------------------------------------
Ztring& FileName::Name_Set(const Ztring &Name)
{
    #ifdef ZENLIB_USEWX
        wxFileName FN(c_str());
        if (FN==FN.GetName()) //Bug of WxWidgets? if C:\\dir\\(no name), name is C:\\dir\\(no name)
            FN.SetPath(c_str());
        FN.SetName(Name.c_str());
        assign ((FN.GetFullPath()+FN.GetPathSeparator()/*FileName_PathSeparator*/+FN.GetFullName()).c_str());
    #else //ZENLIB_USEWX
        #ifdef WINDOWS
            //Path limit
            size_t Pos_Path=rfind(_T('\\'));
            if (Pos_Path==Ztring::npos)
                Pos_Path=0; //Not found
            //Extension limit
            size_t Pos_Ext=rfind(_T('.'));
            if (Pos_Ext==Ztring::npos || Pos_Ext<Pos_Path)
                Pos_Ext=size(); //Not found
            replace(Pos_Path+1, Pos_Ext-Pos_Path-1, Name, 0, Ztring::npos);
        #else
            //Not supported
        #endif
    #endif //ZENLIB_USEWX
    return *this;
}
Пример #2
0
//---------------------------------------------------------------------------
Ztring& FileName::Extension_Set(const Ztring &Extension)
{
    #ifdef ZENLIB_USEWX
        wxFileName FN(c_str());
        FN.SetExt(Extension.c_str());
        assign (FN.GetFullPath().c_str());
    #else //ZENLIB_USEWX
        #ifdef WINDOWS
            //Path limit
            size_t Pos_Path=rfind(_T('\\'));
            if (Pos_Path==Ztring::npos)
                Pos_Path=0; //Not found
            //Extension limit
            size_t Pos_Ext=rfind(_T('.'));
            if (Pos_Ext==Ztring::npos || Pos_Ext<Pos_Path)
            {
                append(1, _T('.')); //Not found
                Pos_Ext=size()-1;
            }
            replace(Pos_Ext+1, size()-Pos_Ext-1, Extension, 0, Ztring::npos);
        #else
            //Not supported
        #endif
    #endif //ZENLIB_USEWX
    return *this;
}
Пример #3
0
void RuntimeEngine::setupRuntime()
{
    //
    // 1. get project type fron config.json
    // 2. init Lua / Js runtime
    //

    updateConfigParser();
    auto entryFile = ConfigParser::getInstance()->getEntryFile();
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
    ConfigParser::getInstance()->readConfig();
    entryFile = ConfigParser::getInstance()->getEntryFile();
#endif

    // Lua
    if ((entryFile.rfind(".lua") != std::string::npos) ||
        (entryFile.rfind(".luac") != std::string::npos))
    {
        _launchEvent = "lua";
        _runtime = _runtimes[kRuntimeEngineLua];
    }
    // Js
    else if ((entryFile.rfind(".js") != std::string::npos) ||
             (entryFile.rfind(".jsc") != std::string::npos))
    {
        _launchEvent = "js";
        _runtime = _runtimes[kRuntimeEngineJs];
    }
}
Пример #4
0
static void get_domain(const struct phishcheck* pchk,struct string* dest,struct string* host)
{
	char* domain;
	char* tld = strrchr(host->data,'.');
	if(!tld) {
		cli_dbgmsg("Phishcheck: Encountered a host without a tld? (%s)\n",host->data);
		string_assign(dest,host);
		return;
	}
	if(isCountryCode(pchk,tld+1)) {
		const char* countrycode = tld+1;
		tld = rfind(host->data,'.',tld-host->data-1);
		if(!tld) {
			cli_dbgmsg("Phishcheck: Weird, a name with only 2 levels (%s)\n",
				host->data);
			string_assign(dest,host);
			return;
		}
		if(!isTLD(pchk,tld+1,countrycode-tld-1)) {
			string_assign_ref(dest,host,tld+1);
			return;/*it was a name like: subdomain.domain.uk, return domain.uk*/
		}
	}
	/*we need to strip one more level, this is the actual domain*/
	domain = rfind(host->data,'.',tld-host->data-1);
	if(!domain) {
		string_assign(dest,host);
		return;/* it was like sourceforge.net?*/
	}
	string_assign_ref(dest,host,domain+1);
}
Пример #5
0
FileName FileName::removeFileFormat() const
{
    size_t found = rfind(NUM);
    if (found != String::npos)
        return substr(0, found);
    found = rfind(COLON);
    if (found != String::npos)
        return substr(0, found);
    return *this;
}
Пример #6
0
static vector< vector< string > > getChunksOfLocalizedDescriptions(
		const Config& config, const IndexEntry& entry)
{
	vector< vector< string > > result;

	if (entry.category != IndexEntry::Binary)
	{
		return result;
	}

	vector< string > chunksBase;
	if (!entry.component.empty())
	{
		chunksBase.push_back(entry.component);
	}
	chunksBase.push_back("i18n");

	set< string > alreadyAddedTranslations;
	auto addTranslation = [&chunksBase, &alreadyAddedTranslations, &result](const string& locale)
	{
		if (alreadyAddedTranslations.insert(locale).second)
		{
			auto chunks = chunksBase;
			chunks.push_back(string("Translation-") + locale);
			result.push_back(chunks);
		}
	};

	auto translationVariable = config.getString("cupt::languages::indexes");
	auto translations = split(',', translationVariable);
	FORIT(translationIt, translations)
	{
		auto locale = (*translationIt == "environment") ?
				setlocale(LC_MESSAGES, NULL) : *translationIt;
		if (locale == "none")
		{
			continue;
		}

		// cutting out an encoding
		auto dotPosition = locale.rfind('.');
		if (dotPosition != string::npos)
		{
			locale.erase(dotPosition);
		}
		addTranslation(locale);

		// cutting out an country specificator
		auto underlinePosition = locale.rfind('_');
		if (underlinePosition != string::npos)
		{
			locale.erase(underlinePosition);
		}
		addTranslation(locale);
	}
Пример #7
0
String FileName::getFileFormat() const
{
    size_t first;
    FileName result;
    if (find(NUM) != npos)
        return "raw";
    else if ((first = rfind(COLON)) != npos)
        result = substr(first + 1);
    else if ((first = rfind(".")) != npos)
        result = substr(first + 1);
    return result.toLowercase();
}
Пример #8
0
void take_over()
{
	auto old_path = winapi::get_module_path();
	if( !winapi::path_file_exists( old_path ) ) {
		old_path = winapi::get_module_path().substr( 0, old_path.rfind( "\\" ) );
	}

	mmaccel::mmaccel_txt_to_key_map_txt(
		old_path.substr( 0, old_path.rfind( u8"\\" ) ) + u8"\\mmaccel.txt",
		winapi::get_module_path() + u8"\\key_map.txt",
		mmaccel::mmd_map::load( winapi::get_module_path() + u8"\\mmd_map.json" )
	);
}
Пример #9
0
AString cFile::ChangeFileExt(const AString & a_FileName, const AString & a_NewExt)
{
	auto res = a_FileName;

	// If the path separator is the last character of the string, return the string unmodified (refers to a folder):
	#if defined(_MSC_VER)
		// Find either path separator - MSVC CRT accepts slashes as separators, too
		auto LastPathSep = res.find_last_of("/\\");
	#elif defined(_WIN32)
		// Windows with different CRTs support only the backslash separator
		auto LastPathSep = res.rfind('\\');
	#else
		// Linux supports only the slash separator
		auto LastPathSep = res.rfind('/');
	#endif
	if ((LastPathSep != AString::npos) && (LastPathSep + 1 == res.size()))
	{
		return res;
	}

	// Append or replace the extension:
	auto DotPos = res.rfind('.');
	if (
		(DotPos == AString::npos) ||  // No dot found
		((LastPathSep != AString::npos) && (LastPathSep > DotPos))  // Last dot is before the last path separator (-> in folder name)
	)
	{
		// No extension, just append the new one:
		if (!a_NewExt.empty() && (a_NewExt[0] != '.'))
		{
			// a_NewExt doesn't start with a dot, insert one:
			res.push_back('.');
		}
		res.append(a_NewExt);
	}
	else
	{
		// Replace existing extension:
		if (!a_NewExt.empty() && (a_NewExt[0] != '.'))
		{
			// a_NewExt doesn't start with a dot, keep the current one:
			res.erase(DotPos + 1, AString::npos);
		}
		else
		{
			res.erase(DotPos, AString::npos);
		}
		res.append(a_NewExt);
	}
	return res;
}
Пример #10
0
// Remove directories ......................................................
FileName FileName::removeDirectories(int keep) const
{
    size_t last_slash = rfind("/");
    int tokeep = keep;
    while (tokeep > 0)
    {
        last_slash = rfind("/", last_slash - 1);
        tokeep--;
    }
    if (last_slash == npos)
        return *this;
    else
        return substr(last_slash + 1, length() - last_slash);
}
Пример #11
0
void FixKernelParameterCallback::run(
    const ast_matchers::MatchFinder::MatchResult& result)
{
  auto funcDecl = result.Nodes.getDeclAs<FunctionDecl>("decl");
  if (funcDecl) {
    // Check if function is an OpenCL kernel
    if (!funcDecl->hasAttr<OpenCLKernelAttr>()) { return; }
    // search all parameters ...
    for ( auto param  = funcDecl->param_begin(),
               last   = funcDecl->param_end();
               param != last;
             ++param ) {
      // ... and look for a type ending in _matrix_t
      auto fullType = (*param)->getOriginalType().getAsString();
      auto pos = fullType.rfind("_matrix_t");
      if ( pos != std::string::npos) {
        // if found transform this parameter into two and adopt the body
        // accordingly
        auto dataType = fullType.substr(0, pos);
        auto paramName = (*param)->getName().str();
        rewriteParameter(*param, dataType, paramName, *result.SourceManager);
        adoptBody(funcDecl, fullType, paramName, *result.SourceManager);
      }
    }
  }
}
Пример #12
0
	String String::strip(Strings tokens) const
	{
		if(tokens.empty())
			tokens.push_back(L" ");

		IndexVar left = 0, right = mContent.size();
		while(left<mContent.size())
		{
			bool flag = false;
			for(Strings::iterator ptr = tokens.begin(); ptr != tokens.end(); ptr++)
				if(find(*ptr,left)==left)
				{
					flag = true;
					break;
				}
			if(!flag)
				break;
			left++;
		}
		while(right>=0)
		{
			bool flag = false;
			for(Strings::iterator ptr = tokens.begin(); ptr != tokens.end(); ptr++)
				if(rfind(*ptr,right-1)==right-1)
				{
					flag = true;
					break;
				}
			if(!flag)
				break;
			right--;
		}
		return substr(left,right-left);
	}
Пример #13
0
FileName FileName::removeAllPrefixes() const
{
    size_t first = rfind(AT);
    if (first != npos)
        return substr(first + 1);
    return *this;
}
Пример #14
0
FileName FileName::removeBlockName() const
{
    size_t first = rfind(AT);

    if (first != npos)
    {
        String block = substr(0, first);
        size_t second = block.find(COMMA);

        if (second == npos)
        {
          if (!isdigit(block[0])){
            return substr(first + 1);
          }
        }
        else
        {
          String prefix = block.substr(0, second);
          block = block.substr(second + 1);
          if (!isdigit(block[0]))
            return prefix + substr(first);
        }
    }
    return *this;
}
Пример #15
0
CL_StringData8::size_type CL_StringData8::rfind(const char *s, size_type pos) const
{
	size_type len = 0;
	while (s[len] != 0)
		len++;
	return rfind(s, pos, len);
}
Пример #16
0
String String::lastToken(char delimiter) {
  int pos = rfind(delimiter);
  if (pos >= 0) {
    return substr(pos + 1);
  }
  return *this;
}
Пример #17
0
static void py_bind_tensor_types(const std::vector<PyTensorType>& tensor_types) {
  auto torch_module = THPObjectPtr(PyImport_ImportModule("torch"));
  if (!torch_module) throw python_error();

  auto tensor_classes = THPObjectPtr(PyObject_GetAttrString(torch_module.get(), "_tensor_classes"));
  if (!tensor_classes) throw python_error();

  for (auto& tensor_type : tensor_types) {
    auto name = std::string(tensor_type.name);
    auto idx = name.rfind(".");
    auto type_name = name.substr(idx + 1);
    auto module_name = name.substr(0, idx);

    auto module_obj = THPObjectPtr(PyImport_ImportModule(module_name.c_str()));
    if (!module_obj) throw python_error();

    PyObject* type_obj = (PyObject*)&tensor_type;
    Py_INCREF(type_obj);
    if (PyModule_AddObject(module_obj.get(), type_name.c_str(), type_obj) < 0) {
      throw python_error();
    }
    if (PySet_Add(tensor_classes.get(), type_obj) < 0) {
      throw python_error();
    }
  }
}
ParticleSystem* ParticleManager::getEmitter(const std::string& filename) {
  auto filepath = FileUtils::getInstance()->fullPathForFilename(filename);
  ValueMap dict;
  ParticleSystem* emitter;

  auto iter = _emitters.find(filepath);
  if (iter != _emitters.end()) {
    dict = iter->second;
  }
  else {
    dict = FileUtils::getInstance()->getValueMapFromFile(filepath);
    _emitters[filepath] = dict;
  }

  CCASSERT(!dict.empty(), "Particles: file not found");

  if (filepath.find('/') != std::string::npos) {
    filepath = filepath.substr(0, filepath.rfind('/') + 1);
    emitter = ParticleSystemCustom::createWithDictionary(dict, filepath);
  }
  else {
    emitter = ParticleSystemCustom::createWithDictionary(dict, "");
  }

  return emitter;
}
Пример #19
0
inline bool Eliza::bot_repeat() const {
	int pos = rfind(vResponseLog, m_sResponse);
	if(pos != -1) {
		return (pos + 1 < response_list.size());
	}
	return 0;
}
Пример #20
0
// Retrieve the substring preceding the last occurrence of Str
// (or the whole string if it doesn't contain Str)
CStr CStr::BeforeLast(const CStr& Str, size_t startPos) const
{
	size_t pos = rfind(Str, startPos);
	if (pos == npos)
		return *this;
	else
		return substr(0, pos);
}
Пример #21
0
// Retrieve the substring following the last occurrence of Str
// (or the whole string if it doesn't contain Str)
CStr CStr::AfterLast(const CStr& Str, size_t startPos) const
{
	size_t pos = rfind(Str, startPos);
	if (pos == npos)
		return *this;
	else
		return substr(pos + Str.length());
}
Пример #22
0
 path path::extension() const
 {
     auto const filename = this->filename().string();
     if ( filename.empty() ) return path{};
     auto pos = filename.rfind( "." );
     if ( filename.size() == 1 || filename.size() == 2 || pos == std::string::npos ) return path{};
     return path{ filename.substr( pos ) };
 }
Пример #23
0
static bool TestShipperEmail(ref<CWarehouseReceipt> const& whr)
{
	auto email = whr->GetShipperEmail();
	const std::string domain = "@magaya.com";

//	return std::equal(rbegin(email), rbegin(email) + domain.size(), rbegin(domain));
	return email.rfind(domain) != std::string::npos;
}
Пример #24
0
int String::rfind(CStrRef s, int pos /* = 0 */,
                  bool caseSensitive /* = true */) const {
  if (empty()) return -1;
  if (s.size() == 1) {
    return rfind(*s.data(), pos, caseSensitive);
  }
  return string_rfind(m_px->data(), m_px->size(),
                      s.data(), s.size(), pos, caseSensitive);
}
Пример #25
0
//++
// Details: Remove '\n' from the end of string if found. It does not alter
//          *this string.
// Type:    Method.
// Args:    None.
// Return:  CMIUtilString - New version of the string.
// Throws:  None.
//--
CMIUtilString CMIUtilString::StripCREndOfLine() const {
  const size_t nPos = rfind('\n');
  if (nPos == std::string::npos)
    return *this;

  const CMIUtilString strNew(substr(0, nPos));

  return strNew;
}
Пример #26
0
//---------------------------------------------------------------------------
Ztring FileName::Name_Get() const
{
    #ifdef ZENLIB_USEWX
        wxFileName FN(c_str());
        if (FN==FN.GetName()) //Bug of WxWidgets? if C:\\dir\\(no name), name is C:\\dir\\(no name)
            return Ztring();
        return FN.GetName().c_str();
    #else //ZENLIB_USEWX
        size_t Pos_Path=rfind(FileName_PathSeparator); //Path limit
        if (Pos_Path==Ztring::npos)
            Pos_Path=(size_type)-1; //Not found
        //Extension limit
        size_t Pos_Ext=rfind(_T('.'));
        if (Pos_Ext==Ztring::npos || Pos_Ext<Pos_Path)
            Pos_Ext=size(); //Not found
        return Ztring(*this, Pos_Path+1, Pos_Ext-Pos_Path-1);
    #endif //ZENLIB_USEWX
}
Пример #27
0
//---------------------------------------------------------------------------
Ztring FileName::Extension_Get() const
{
    #ifdef ZENLIB_USEWX
        wxFileName FN(c_str());
        return FN.GetExt().c_str();
    #else //ZENLIB_USEWX
        //Path limit
        size_t Pos_Path=rfind(FileName_PathSeparator);
        if (Pos_Path==Ztring::npos)
            Pos_Path=0; //Not found
        //Extension limit
        size_t Pos_Ext=rfind(_T('.'));
        if (Pos_Ext==Ztring::npos || Pos_Ext<Pos_Path)
            return Ztring(); //Not found
        else
            return Ztring(*this, Pos_Ext+1, size()-Pos_Ext-1);
    #endif //ZENLIB_USEWX
}
Пример #28
0
long CStr::ReverseFind(const CStr& Str) const
{
	size_t Pos = rfind(Str, length() );

	if (Pos != npos)
		return (long)Pos;

	return -1;

}
Пример #29
0
int String::rfind(const char *s, int pos /* = 0 */,
                  bool caseSensitive /* = true */) const {
  assert(s);
  if (empty()) return -1;
  if (*s && *(s+1) == 0) {
    return rfind(*s, pos, caseSensitive);
  }
  return string_rfind(m_px->data(), m_px->size(), s, strlen(s),
                      pos, caseSensitive);
}
Пример #30
0
int String::rfind(CStrRef s, int pos /* = 0 */,
                  bool caseSensitive /* = true */) const {
  if (empty()) return -1;
  if (s.size() == 1) {
    return rfind(*s.dataIgnoreTaint(), pos, caseSensitive);
  }
  // Ignore taint in comparison functions.
  return string_rfind(m_px->dataIgnoreTaint(), m_px->size(),
                      s.dataIgnoreTaint(), s.size(), pos, caseSensitive);
}