예제 #1
0
파일: utility.cpp 프로젝트: emlai/zenith
std::string operator+(std::string_view a, std::string_view b)
{
    std::string result;
    result.reserve(a.size() + b.size());
    result.append(a.data(), a.size());
    result.append(b.data(), b.size());
    return result;
}
예제 #2
0
  bool operator()(std::string_view lhs, std::string_view rhs) const {
#if _WIN32
    if (_stricmp(lhs.data(), rhs.data()) < 0)
#else
    if (strcasecmp(lhs.data(), rhs.data()) < 0)
#endif
      return true;
    return false;
  }
예제 #3
0
/*!
  */
void SettingNodeBase::writeString(const std::string_view& text,
                                  std::ostream* data_stream) const noexcept
{
  const uint32 text_length = zisc::cast<uint32>(text.size());
  zisc::write(&text_length, data_stream);
  zisc::write(text.data(), data_stream, text_length);
}
예제 #4
0
파일: main.cpp 프로젝트: keitee/kb
   std::vector<unsigned int> fetch_unread_uids(std::string_view folder)
   {
      std::stringstream str;

      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>((url.data() + std::string("/") + folder.data() + std::string("/")).c_str());
         easy.add<CURLOPT_CUSTOMREQUEST>("SEARCH UNSEEN");
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception const & error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      std::vector<unsigned int> uids;
      str.seekg(8, std::ios::beg);
      unsigned int uid;
      while (str >> uid)
         uids.push_back(uid);

      return uids;
   }
예제 #5
0
파일: DCLN.cpp 프로젝트: AxioDL/urde
void DCLN::sendToBlender(hecl::blender::Connection& conn, std::string_view entryName) {
  /* Open Py Stream and read sections */
  hecl::blender::PyOutStream os = conn.beginPythonOut(true);
  os.format(
      "import bpy\n"
      "import bmesh\n"
      "from mathutils import Vector, Matrix\n"
      "\n"
      "bpy.context.scene.name = '%s'\n"
      "# Clear Scene\n"
      "for ob in bpy.data.objects:\n"
      "    if ob.type != 'CAMERA':\n"
      "        bpy.context.scene.objects.unlink(ob)\n"
      "        bpy.data.objects.remove(ob)\n",
      entryName.data());

  DeafBabe::BlenderInit(os);
  atInt32 idx = 0;
  for (const Collision& col : collision) {
    DeafBabeSendToBlender(os, col, true, idx++);
#if DCLN_DUMP_OBB
    col.root.sendToBlender(os);
#endif
  }
  os.centerView();
  os.close();
}
예제 #6
0
// -----------------------------------------------------------------------------
// Opens the texture browser for [tex_type] textures, with [init_texture]
// initially selected. Returns the selected texture
// -----------------------------------------------------------------------------
std::string MapEditor::browseTexture(
	std::string_view init_texture,
	TextureType      tex_type,
	SLADEMap&        map,
	std::string_view title)
{
	// Unlock cursor if locked
	bool cursor_locked = edit_context->mouseLocked();
	if (cursor_locked)
		edit_context->lockMouse(false);

	// Setup texture browser
	MapTextureBrowser browser(map_window, tex_type, wxString{ init_texture.data(), init_texture.size() }, &map);
	browser.SetTitle(WxUtils::strFromView(title));

	// Get selected texture
	std::string tex;
	if (browser.ShowModal() == wxID_OK)
		tex = browser.selectedItem()->name();

	// Re-lock cursor if needed
	if (cursor_locked)
		edit_context->lockMouse(true);

	return tex;
}
예제 #7
0
파일: Common.cpp 프로젝트: AxioDL/amuse
ObjectId NameDB::resolveIdFromName(std::string_view str) const {
  auto search = m_stringToId.find(std::string(str));
  if (search == m_stringToId.cend()) {
    Log.report(logvisor::Error, "Unable to resolve name %s", str.data());
    return {};
  }
  return search->second;
}
예제 #8
0
CPlayerState::EItemType CPlayerState::ItemNameToType(std::string_view name) {
  std::string lowName = name.data();
  athena::utility::tolower(lowName);
  if (g_TypeNameMap.find(lowName) == g_TypeNameMap.end())
    return EItemType::Invalid;

  return g_TypeNameMap.find(lowName)->second;
}
예제 #9
0
void outputString( std::string_view string ) {
#ifdef _WIN32
    OutputDebugStringA( string.data() );
    OutputDebugStringA( "\n" );
#endif
    std::setlocale( LC_ALL, "en_US.utf-8" );
    std::cout << string << std::endl;
}
예제 #10
0
	bool loadFile(const std::string_view file, Document& doc)
	{
		if (file.empty() == true)
		{
			return false;
		}
		return loadJson(FileUtils::readText(file.data()), doc);
	}
예제 #11
0
SQLiteDb::SQLiteStmt SQLiteDb::create_stmt(std::string_view const Stmt) const
{
	sqlite::sqlite3_stmt* pStmt;

	// https://www.sqlite.org/c3ref/prepare.html
	// If the caller knows that the supplied string is nul-terminated,
	// then there is a small performance advantage to passing an nByte parameter
	// that is the number of bytes in the input string *including* the nul-terminator.

	// We use data() instead of operator[] here to bypass any bounds checks in debug mode
	const auto IsNullTerminated = !Stmt.data()[Stmt.size()];

	const auto Result = sqlite::sqlite3_prepare_v3(m_Db.get(), Stmt.data(), static_cast<int>(Stmt.size() + (IsNullTerminated? 1 : 0)), SQLITE_PREPARE_PERSISTENT, &pStmt, nullptr);
	if (Result != SQLITE_OK)
		throw MAKE_FAR_EXCEPTION(format(L"SQLiteDb::create_stmt error {0} - {1}", Result, GetErrorString(Result)));

	return SQLiteStmt(pStmt);
}
예제 #12
0
	bool loadJson(const std::string_view json, Document& doc)
	{
		if (json.empty() == true)
		{
			return false;
		}
		// Default template parameter uses UTF8 and MemoryPoolAllocator.
		return (doc.Parse(json.data(), json.size()).HasParseError() == false);
	}
예제 #13
0
파일: main.cpp 프로젝트: keitee/kb
   std::wstring translate_text(
      std::wstring_view wtext, 
      std::string_view to,
      std::string_view from = "en")
   {
      try
      {
         using namespace std::string_literals;

         std::stringstream str;
         std::string text = utf16_to_utf8(wtext);

         curl::curl_ios<std::stringstream> writer(str);
         curl::curl_easy easy(writer);

         curl::curl_header header;
         header.add("Ocp-Apim-Subscription-Key:" + app_key);

         easy.escape(text);
         auto url = endpoint + "/Translate";
         url += "?from="s + from.data();
         url += "&to="s + to.data();
         url += "&text="s + text;

         easy.add<CURLOPT_URL>(url.c_str());
         easy.add<CURLOPT_HTTPHEADER>(header.get());

         easy.perform();

         auto result = deserialize_result(str.str());
         return utf8_to_utf16(result);
      }
      catch (curl::curl_easy_exception const & error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }
      catch (std::exception const & ex)
      {
         std::cout << ex.what() << std::endl;
      }

      return {};
   }
예제 #14
0
	bool saveText(const std::string_view filePath, const std::string_view str) noexcept
	{
		try
		{
			std::filesystem::path path(filePath);
			if (path.has_parent_path() == true)
			{
				createDir(path.parent_path().u8string().c_str());
			}
			auto file = PHYSFS_openWrite(filePath.data());
			if (file != nullptr)
			{
				PHYSFS_writeBytes(file, str.data(), str.size());
				return PHYSFS_close(file) != 0;
			}
		}
		catch (std::exception&) {}
		return false;
	}
예제 #15
0
파일: main.cpp 프로젝트: keitee/kb
void serialize(movie_list const & movies, std::string_view filepath)
{
   json jdata{ { "movies", movies } };

   std::ofstream ofile(filepath.data());
   if (ofile.is_open())
   {
      ofile << std::setw(2) << jdata << std::endl;
   }
}
예제 #16
0
bool easy_lua::execute(
    const std::string_view& script,
    const bool              from_memory ) const
{
    if( script.empty() ) {
        return false;
    }
    if( !from_memory ) {
        return !luaL_dofile( EASY_LUA_CAST_LUA( this ), script.data() );
    }
    if( luaL_loadstring( EASY_LUA_CAST_LUA( this ), script.data() ) > 0 ) {
        return false;
    }
    if( lua_pcall( EASY_LUA_CAST_LUA( this ), 0, 0, 0 ) > 0 ) {
        if( pop( 1 ) == this ) {
            return false;
        }
        return false;
    }
    return true;
}
예제 #17
0
easy_lua::EState easy_lua::load_file(
    const std::string_view& file ) const
{
    switch( luaL_loadfile( EASY_LUA_CAST_LUA( this ), file.data() ) ) {
    case LUA_ERRSYNTAX:
        return State_Syntax;
    case LUA_ERRMEM:
        return State_MemAlloc;
    default:
        break;
    }
    return State_Success;
}
예제 #18
0
	bool mount(const std::string_view file, const std::string_view mountPoint,
		bool appendToSearchPath)
	{
		int append = appendToSearchPath == true ? 1 : 0;
		try
		{
			std::filesystem::path path(file);

			if (PHYSFS_mount(path.u8string().c_str(), mountPoint.data(), append) != 0)
			{
				return true;
			}
			if (path.has_extension() == true)
			{
				path = path.replace_extension();
				if (PHYSFS_mount(path.u8string().c_str(), mountPoint.data(), append) != 0)
				{
					return true;
				}
			}
			path = path.replace_extension(".mpq");
			if (PHYSFS_mount(path.u8string().c_str(), mountPoint.data(), append) != 0)
			{
				return true;
			}
			path = path.replace_extension(".zip");
			if (PHYSFS_mount(path.u8string().c_str(), mountPoint.data(), append) != 0)
			{
				return true;
			}
			path = path.replace_extension(".7z");
			if (PHYSFS_mount(path.u8string().c_str(), mountPoint.data(), append) != 0)
			{
				return true;
			}
		}
		catch (std::exception&) {}
		return false;
	}
예제 #19
0
 void message_headers::add(std::string_view name, std::string_view value)
 {
   std::unordered_map<std::string, std::string>::iterator iter
     (fields_.find(name.data()));
   // if the field name was found previously
   if (iter != fields_.end())
   {
     char separator((name.find(COOKIE) != std::string::npos) ? ';' : ',');
     iter->second.append({separator});
     iter->second.append(value);
   }
   else
     fields_.insert(std::unordered_map<std::string, std::string>::value_type
                          (name, value));
 }
예제 #20
0
	std::string_view WesConverter::Convert(const std::string_view& str)
	{
		_Mybase::initialize("UI\\WorldEditStrings.txt");

		if (0 == str.compare(0, _countof("WESTRING_") - 1, "WESTRING_"))
		{
			auto It = _Mybase::table_.find(std::string(str.data(), str.size()));
			if (It != _Mybase::table_.end())
			{
				return It->second;
			}
		}

		return str;
	}
예제 #21
0
    ZipArchive(const std::string_view& path, ZIP_ACCESS access)
    {
        // retrieve the JNI environment.
        JNIEnv *env = (JNIEnv *) SDL_AndroidGetJNIEnv();

        jclass jniClass = env->FindClass("website/openrct2/ZipArchive");
        jmethodID constructor = env->GetMethodID(jniClass, "<init>", "(Ljava/lang/String;)V");

        jstring jniPath = env->NewStringUTF(path.data());

        // TODO: Catch exceptions. Should probably be done on Java side, and just return null from a static method
        jobject zip = env->NewObject(jniClass, constructor, jniPath);

        _zip = env->NewGlobalRef(zip);
    }
예제 #22
0
파일: main.cpp 프로젝트: keitee/kb
void decrypt_file(
   fs::path const & sourcefile,
   fs::path const & destfile,
   std::string_view password)
{
   CryptoPP::FileSource source(
      sourcefile.c_str(),
      true,
      new CryptoPP::DefaultDecryptorWithMAC(
      (CryptoPP::byte*)password.data(), password.size(),
         new CryptoPP::FileSink(
            destfile.c_str())
      )
   );
}
예제 #23
0
파일: main.cpp 프로젝트: keitee/kb
std::vector<fs::directory_entry> find_files(
   fs::path const & path,
   std::string_view regex)
{
   std::vector<fs::directory_entry> result;
   std::regex rx(regex.data());

   std::copy_if(
      fs::recursive_directory_iterator(path),
      fs::recursive_directory_iterator(),
      std::back_inserter(result),
      [&rx](fs::directory_entry const & entry) {
         return fs::is_regular_file(entry.path()) &&
                std::regex_match(entry.path().filename().string(), rx);
      });

   return result;
}
예제 #24
0
    std::vector<uint8> GetFileData(const std::string_view& path) const override
    {
        // retrieve the JNI environment.
        JNIEnv *env = (JNIEnv *) SDL_AndroidGetJNIEnv();

        jclass zipClass = env->GetObjectClass(_zip);
        jstring javaPath = env->NewStringUTF(path.data());
        jmethodID indexMethod = env->GetMethodID(zipClass, "getFileIndex", "(Ljava/lang/String;)I");
        jint index = env->CallIntMethod(_zip, indexMethod, javaPath);

        jmethodID fileMethod = env->GetMethodID(zipClass, "getFile", "(I)J");
        jlong ptr = env->CallLongMethod(_zip, fileMethod, index);

        auto dataPtr = reinterpret_cast<uint8 *>(ptr);
        auto dataSize = this->GetFileSize(index);

        return std::vector<uint8>(dataPtr, dataPtr + dataSize);
    }
예제 #25
0
파일: main.cpp 프로젝트: keitee/kb
   std::string fetch_email(std::string_view folder, unsigned int uid)
   {
      std::stringstream str;

      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>((url.data() + std::string("/") + folder.data() + std::string("/;UID=") + std::to_string(uid)).c_str());
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      return str.str();
   }
예제 #26
0
파일: main.cpp 프로젝트: keitee/kb
   std::string examine_folder(std::string_view folder)
   {
      std::stringstream str;
      try
      {
         curl::curl_ios<std::stringstream> writer(str);

         curl::curl_easy easy(writer);
         easy.add<CURLOPT_URL>(url.data());
         easy.add<CURLOPT_CUSTOMREQUEST>((std::string("EXAMINE ") + folder.data()).c_str());
         setup_easy(easy);

         easy.perform();
      }
      catch (curl::curl_easy_exception const & error)
      {
         auto errors = error.get_traceback();
         error.print_traceback();
      }

      return str.str();
   }
예제 #27
0
	std::vector<std::string> geDirList(const std::string_view path,
		const std::string_view rootPath)
	{
		std::vector<std::string> vecDirs;
		auto dirs = PHYSFS_enumerateFiles(path.data());
		if (dirs != nullptr)
		{
			PHYSFS_Stat fileStat;
			for (char** dir = dirs; *dir != nullptr; dir++)
			{
				if (PHYSFS_stat(*dir, &fileStat) == 0)
				{
					continue;
				}
				if (fileStat.filetype != PHYSFS_FILETYPE_DIRECTORY)
				{
					continue;
				}
				if (**dir == '.')
				{
					continue;
				}
				if (rootPath.empty() == false)
				{
					auto realDir = PHYSFS_getRealDir(*dir);
					if (realDir != nullptr)
					{
						if (rootPath != realDir)
						{
							continue;
						}
					}
				}
				vecDirs.push_back(*dir);
			}
			PHYSFS_freeList(dirs);
		}
		return vecDirs;
	}
예제 #28
0
	bool unmount(const std::string_view file)
	{
		if (PHYSFS_unmount(file.data()) != 0)
		{
			return true;
		}
		try
		{
			std::filesystem::path path(file);

			if (path.has_extension() == true)
			{
				path = path.replace_extension();
				if (PHYSFS_unmount(path.u8string().c_str()) != 0)
				{
					return true;
				}
			}
			path = path.replace_extension(".mpq");
			if (PHYSFS_unmount(path.u8string().c_str()) != 0)
			{
				return true;
			}
			path = path.replace_extension(".zip");
			if (PHYSFS_unmount(path.u8string().c_str()) != 0)
			{
				return true;
			}
			path = path.replace_extension(".7z");
			if (PHYSFS_unmount(path.u8string().c_str()) != 0)
			{
				return true;
			}
		}
		catch (std::exception&) {}
		return false;
	}
예제 #29
0
파일: Min.cpp 프로젝트: dgengin/DGEngine
Min::Min(const std::string_view fileName, size_t minSize)
{
	sf::PhysFSStream file(fileName.data());
	if (file.hasError() == true)
	{
		return;
	}

	auto fileSize = (size_t)file.getSize();
	numPillars = fileSize / (minSize * 2);
	pillarHeight = minSize / 2;

	pillars.resize(numPillars * pillarHeight);
	file.read(pillars.data(), file.getSize());

	LittleEndianStreamReader fileStream((const uint8_t*)pillars.data(), fileSize);

	MinPillar minPillar(pillars.data(), pillarHeight);
	size_t count = 0;
	for (auto& pillar : pillars)
	{
		std::pair<uint16_t, uint16_t> temp;
		fileStream.read(temp.first);
		fileStream.read(temp.second);
		pillar = temp;
		count++;
		if (count == pillarHeight)
		{
			if (minPillar.isTopBlank() == true)
			{
				numBlankTopPillars++;
			}
			count = 0;
			minPillar = MinPillar(&pillar + 1, pillarHeight);
		}
	}
}
예제 #30
0
	std::vector<std::string> getFileList(const std::string_view filePath,
		const std::string_view fileExt, bool getFullPath)
	{
		std::vector<std::string> vec;
		auto files = PHYSFS_enumerateFiles(filePath.data());
		if (files != nullptr)
		{
			PHYSFS_Stat fileStat;
			for (char** file = files; *file != nullptr; file++)
			{
				auto file2 = std::string(filePath) + '/' + std::string(*file);

				if (Utils::endsWith(file2, fileExt) == false)
				{
					continue;
				}
				if (PHYSFS_stat(file2.c_str(), &fileStat) == 0)
				{
					continue;
				}
				if (fileStat.filetype == PHYSFS_FILETYPE_REGULAR)
				{
					if (getFullPath == true)
					{
						vec.push_back(file2);
					}
					else
					{
						vec.push_back(std::string(*file));
					}
				}
			}
			PHYSFS_freeList(files);
		}
		return vec;
	}