Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
inline std::string StringFromHex(const std::string_view& input)
{
    assert((input.size() & 1) == 0);

    std::string result;
    result.reserve(input.size() / 2);
    for (size_t i = 0; i < input.size(); i += 2)
    {
        auto val = std::stoi(std::string(input.substr(i, 2)), 0, 16);
        result.push_back(val);
    }
    return result;
}
Exemplo n.º 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);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
 std::string quote_this(std::string_view arg)
 {
    if (arg.size() && arg[0] != '"' && arg.find(' ') != std::string::npos)
    {
       return '"' + std::string(arg) + '"';
    }
    return std::string(arg);
 }
Exemplo n.º 6
0
void Calculator::skipSpaces(std::string_view &ref)
{
	size_t i = 0;
	while (i < ref.size() && std::isspace(ref[i]))
	{
		++i;
	}
	ref.remove_prefix(i);
}
Exemplo n.º 7
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);
	}
Exemplo n.º 8
0
static std::string_view hash_from_url( std::string_view url ){
	size_t start = url.find_last_of( '/' ) + 1;
	size_t end = url.find_last_of( '.' );
	
	//Validate results
	if( start == string::npos || end == string::npos || start >= url.size() )
		return "";
	else
		return url.substr( start, end-start );
}
Exemplo n.º 9
0
	std::pair<std::string_view, std::string_view> splitStringIn2(
		const std::string_view str, char delimiter)
	{
		auto pos = str.find(delimiter, 0);
		if (pos != std::string::npos)
		{
			return std::make_pair(str.substr(0, pos), str.substr(pos + 1, str.size() - pos));
		}
		return std::make_pair(str, "");
	}
Exemplo n.º 10
0
    bool is_palindrome( const std::string_view str ){
        const auto len = str.size();
        const auto limit = (len / 2) + 1;
        for( int i = 0 ; i < limit ; ++i ){
            if( str[i] != str[len - 1 - i] ){
                return false;
            }
        }

        return true;
    }
Exemplo n.º 11
0
void job_implObj::set_option(const std::string_view &name,
			     const std::string_view &value)
{
	size_t s=name.size();

	char name_str[s+1];

	std::copy(name.begin(), name.end(), name_str);
	name_str[s]=0;

	s=value.size();
	char value_str[s+1];

	std::copy(value.begin(), value.end(), value_str);
	value_str[s]=0;

	job_info_t::lock lock{job_info};

	lock->num_options=cupsAddOption(name_str, value_str,
					lock->num_options,
					&lock->options);
}
Exemplo n.º 12
0
Arquivo: main.cpp Projeto: 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())
      )
   );
}
Exemplo n.º 13
0
bool destination_implObj::supported(const std::string_view &option,
				    const std::string_view &value) const
{
	auto s=option.size();

	char option_s[s+1];

	std::copy(option.begin(), option.end(), option_s);
	option_s[s]=0;

	s=value.size();

	char value_s[s+1];
	std::copy(value.begin(), value.end(), value_s);
	value_s[s]=0;

	info_t::lock lock{*this};

	return !!cupsCheckDestSupported(lock->http,
					lock->dest,
					lock->info,
					option_s,
					value_s);
}
Exemplo n.º 14
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;
	}
Exemplo n.º 15
0
	//初始化各项参数
	bool InitBackend(std::string_view path,
					 int64_t maxSize		   = 0,
					 std::string_view prefix   = "",
					 std::string_view fileLink = "")
	{
		if (path.size() <= 0) {
			return false;
		} else {
			mPath = path;
		}

		if (prefix.size() > 0) {
			mPrefix = prefix;
		}
		if (fileLink.size() > 0) {
			mLink = fileLink;
		}

		if (maxSize > 0) {
			mMaxSize = maxSize * 1024 * 1024;
		}

		if (!std::filesystem::exists(mPath)) {
			if (!std::filesystem::create_directory(mPath)) {
				return false;
			}
		}

		mCurrentDay = TimeUtil::GetCurrentDay();

		if (mChang) {
			createFile();
		}

		return true;
	}
Exemplo n.º 16
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);
}
Exemplo n.º 17
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;
	}
Exemplo n.º 18
0
std::string pascalCaseToSentenceCase(std::string_view pascalCaseString)
{
    std::string name;
    name.reserve(pascalCaseString.size());

    for (char ch : pascalCaseString)
    {
        if (std::isupper(ch))
        {
            if (!name.empty())
                name += ' ';

            name += char(std::tolower(ch));
        }
        else
            name += ch;
    }

    return name;
}
Exemplo n.º 19
0
option_values_t
destination_implObj::ready_option_values(const std::string_view &option)
	const
{
	auto s=option.size();

	char option_s[s+1];

	std::copy(option.begin(), option.end(), option_s);
	option_s[s]=0;

	auto[name, unicode_flag]=parse_unicode_option(option_s);
	info_t::lock lock{*this};

	auto attrs=cupsFindDestReady(lock->http, lock->dest,
				     lock->info,
				     name);

	return parse_attribute_values(lock, attrs, name, unicode_flag);
}
Exemplo n.º 20
0
//string_views
static constexpr uint64_t fnv_hash(const std::string_view sv){
  return fnv_hash(static_cast<const void*>(sv.data()), sv.size());
}
Exemplo n.º 21
0
	unsigned long long strtoull(std::string_view str) noexcept
	{
		unsigned long long val = 0;
		std::from_chars(str.data(), str.data() + str.size(), val);
		return val;
	}
Exemplo n.º 22
0
	int strtoi(std::string_view str) noexcept
	{
		int val = 0;
		std::from_chars(str.data(), str.data() + str.size(), val);
		return val;
	}
Exemplo n.º 23
0
	long double strtold(std::string_view str) noexcept
	{
		long double val = 0;
		std::from_chars(str.data(), str.data() + str.size(), val);
		return val;
	}
Exemplo n.º 24
0
	inline bool SendUserEvent(enum UserEventType type, unsigned code, std::string_view string)
	{
		return SendUserEvent(type, code, string.data(), string.size());
	}
Exemplo n.º 25
0
 void operator()(clmdep_msgpack::object& o, const std::string_view& v) const {
     uint32_t size = checked_get_container_size(v.size());
     o.type = clmdep_msgpack::type::STR;
     o.via.str.ptr = v.data();
     o.via.str.size = size;
 }
Exemplo n.º 26
0
int job_implObj::submit(const std::string_view &title)
{
	size_t s=title.size();

	char title_str[s+1];

	std::copy(title.begin(), title.end(), title_str);
	title_str[s]=0;

	job_info_t::lock job_lock{job_info};

	if (job_lock->documents.empty())
		return 0;

	destination_implObj::info_t::lock lock{*destination};

	int job_id;

	auto status=cupsCreateDestJob(lock->http,
				      lock->dest,
				      lock->info,
				      &job_id,
				      title_str,
				      job_lock->num_options,
				      job_lock->options);

	if (status != IPP_STATUS_OK)
		throw EXCEPTION(ippErrorString(status));

	auto job_sentry=make_sentry([&]
				    {
					    cupsCancelDestJob(lock->http,
							      lock->dest,
							      job_id);
				    });

	job_sentry.guard();

	for (const auto &doc:job_lock->documents)
	{
		auto [mime_type, contents]=doc.document();

		auto status=cupsStartDestDocument(lock->http,
						  lock->dest, lock->info,
						  job_id,
						  doc.name.c_str(),
						  mime_type.c_str(),
						  0, NULL, 0);
		if (status != HTTP_STATUS_CONTINUE)
			throw EXCEPTION(httpStatus(status));

		auto doc_sentry=make_sentry
			([&]
			 {
				 cupsFinishDestDocument(lock->http,
							lock->dest,
							lock->info);
			 });
		doc_sentry.guard();

		while (auto res=contents())
		{
			status=cupsWriteRequestData(lock->http,
						    res->data(),
						    res->size());

			if (status != HTTP_STATUS_CONTINUE)
				throw EXCEPTION(httpStatus(status));
		}
		doc_sentry.unguard();

		auto ipp_status=cupsFinishDestDocument(lock->http,
						       lock->dest,
						       lock->info);

		if (ipp_status != IPP_STATUS_OK)
			throw EXCEPTION(cupsLastErrorString());
	}

	job_sentry.unguard();

	auto ipp_status=cupsCloseDestJob(lock->http,
					 lock->dest,
					 lock->info,
					 job_id);

	if (ipp_status != IPP_STATUS_OK)
		throw EXCEPTION(cupsLastErrorString());
	return job_id;
}
Exemplo n.º 27
0
 explicit StageSourceText(std::string_view text) : m_text(text), m_hash(XXH64(m_text.data(), m_text.size(), 0)) {}
Exemplo n.º 28
0
 error bind_by_name(std::string_view name, T value)
 {
     return bind_by_name_n(name.data(), name.size(), value);
 }
Exemplo n.º 29
0
	int convert_to_lua(lua_State* L, const std::string_view& v)
	{
		lua_pushlstring(L, v.data(), v.size());
		return 1;
	}
Exemplo n.º 30
0
	void Write(std::string_view buf) override
	{
		doIncise();
        mFile.write(buf.data(), buf.size());
	}