示例#1
0
double Calculator::parseExprSum(std::string_view &ref)
{
	double value = parseExprMul(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '+')
		{
			ref.remove_prefix(1);
			value += parseExprMul(ref);
			m_printStrategy->printAddition();
		}
		else if (!ref.empty() && ref[0] == '-')
		{
			ref.remove_prefix(1);
			value -= parseExprMul(ref);
			m_printStrategy->printSubstraction();
		}
		else
		{
			break;
		}
	}

	return value;
}
示例#2
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;
}
示例#3
0
double Calculator::parseExprMul(std::string_view &ref)
{
	double value = parseSymbol(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '*')
		{
			ref.remove_prefix(1);
			value *= parseSymbol(ref);
			m_printStrategy->printMultiplication();
		}
		else if (!ref.empty() && ref[0] == '/')
		{
			ref.remove_prefix(1);
			value /= parseSymbol(ref);
			m_printStrategy->printDivision();
		}
		else
		{
			break;
		}
	}

	return value;
}
示例#4
0
    bool are_headers_split(std::string_view headers) noexcept
    {
      char prev('0');
      char pprev('0');

      if (!headers.empty())
      {
        auto iter(headers.cbegin());
        for(; iter != headers.cend(); ++iter)
        {
          if (*iter == '\n')
          {
            if (prev == '\n')
              return true;
            else if ((prev == '\r') && (pprev == '\n'))
              return true;
          }

          pprev = prev;
          prev = *iter;
        }
      }

      return false;
    }
inline std::pair<std::string_view, std::string_view> splitAt( std::string_view str, char splitter ){
	auto pos = str.find( splitter );
	if( pos == std::string_view::npos )
		return { str, {} };
	else
		return { str.substr( 0, pos ), str.substr( pos+1 ) };
}
示例#6
0
double Calculator::parseSymbol(std::string_view &ref)
{
	double value = 0;
	skipSpaces(ref);
	if (!ref.empty() && ref[0] == '(')
	{
		ref.remove_prefix(1);
		value = parseExprSum(ref);
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == ')')
		{
			ref.remove_prefix(1);
			return value;
		}
		else
		{
			return std::numeric_limits<double>::quiet_NaN();
		}
	}
	else if (!ref.empty() && !std::isdigit(ref[0]) && ref[0] != '-')
	{
		return parseFunction(ref);
	}
	else
	{
		return parseDouble(ref);
	}
}
示例#7
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);
}
示例#8
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);
 }
示例#9
0
	bool loadFile(const std::string_view file, Document& doc)
	{
		if (file.empty() == true)
		{
			return false;
		}
		return loadJson(FileUtils::readText(file.data()), doc);
	}
示例#10
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);
}
示例#11
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);
	}
示例#12
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;
  }
示例#13
0
	void replaceStringInPlace(std::string& subject, const std::string_view search, const std::string_view replace)
	{
		size_t pos = 0;
		while ((pos = subject.find(search, pos)) != std::string::npos)
		{
			subject.replace(pos, search.length(), replace);
			pos += replace.length();
		}
	}
示例#14
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 );
}
示例#15
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, "");
	}
示例#16
0
static std::string print_color_mode(const std::string_view &v)
{
	if (v == CUPS_PRINT_COLOR_MODE_AUTO)
		return _("Automatic");
	if (v == CUPS_PRINT_COLOR_MODE_MONOCHROME)
		return _("Monochrome");
	if (v == CUPS_PRINT_COLOR_MODE_COLOR)
		return _("Color");
	return {v.begin(), v.end()};
}
示例#17
0
static std::string sides(const std::string_view &v)
{
	if (v == CUPS_SIDES_ONE_SIDED)
		return _("Off");
	if (v == CUPS_SIDES_TWO_SIDED_PORTRAIT)
		return _("Duplex (Long Edge)");
	if (v == CUPS_SIDES_TWO_SIDED_LANDSCAPE)
		return _("Duplex (Short Edge)");
	return {v.begin(), v.end()};
}
示例#18
0
文件: misc.cpp 项目: chys87/tiary
std::string environment_expand(std::string_view s) {
	std::string r;
	size_t start_pos = 0;
	size_t dollar_pos;
	while ((dollar_pos = s.find('$', start_pos)) != s.npos) {
		r += s.substr(start_pos, dollar_pos - start_pos);
		std::string varname;
		if (dollar_pos + 1 < s.length() && s[dollar_pos + 1] == '{') {
			size_t dollar_end = s.find('}', dollar_pos + 2);
			if (dollar_end == s.npos) {
				break;
			}
			varname = s.substr(dollar_pos + 2, dollar_end - (dollar_pos + 2));
			start_pos = dollar_end + 1;
		} else {
			size_t dollar_end = s.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"sv, dollar_pos + 1);
			varname = s.substr(dollar_pos + 1, dollar_end - (dollar_pos + 1));
			start_pos = dollar_end;
		}
		if (const char *varval = getenv (varname.c_str ())) {
			r += varval;
		}
	}
	if (start_pos < s.length()) {
		r += s.substr(start_pos);
	}
	return r;
}
示例#19
0
inline std::vector<std::string_view> splitAllOn( std::string_view str, char splitter ){
	std::vector<std::string_view> splits;
	
	size_t last=0, pos = 0;
	while( (pos = str.find(splitter, last)) != std::string_view::npos ){
		splits.push_back( str.substr( last, pos-last ) );
		last = pos+1;
	}
	splits.push_back( str.substr( last ) );
	
	return splits;
}
示例#20
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;
}
示例#21
0
	//连接到网络地址
	bool
	Dial(std::string_view network, std::string_view ip, unsigned short port)
	{
		if (network.empty() || ip.empty() || port <= 0) {
			return false;
		}
		mRemoteAddr = std::move(ip);
		mPort		= port;

		if (!mSocket.NewSocket(network))
			return false;

		return mSocket.Connect(port, ip) == 0 ? true : false;
	}
示例#22
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;
	}
示例#23
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));
 }
示例#24
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())
      )
   );
}
示例#25
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();
}
	void CArchiveExtractCallback::Init(std::string_view pw, std::shared_ptr<ISequentialOutStream> const & outFileStream)
	{
		_outFileStream = outFileStream;

		password_is_defined_ = !pw.empty();
		Convert(password_, pw);
	}
示例#27
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;
   }
示例#28
0
	std::vector<std::string> splitString(const std::string_view str, char delimiter)
	{
		std::vector<std::string> strings;

		std::string_view::size_type pos = 0;
		std::string_view::size_type prev = 0;
		while ((pos = str.find(delimiter, prev)) != std::string::npos)
		{
			strings.push_back(std::string(str.substr(prev, pos - prev)));
			prev = pos + 1;
		}

		strings.push_back(std::string(str.substr(prev)));

		return strings;
	}
示例#29
0
void Player::setProperty(const std::string_view prop, const Variable& val)
{
	if (prop.empty() == true)
	{
		return;
	}
	auto propHash16 = str2int16(prop);
	switch (propHash16)
	{
	case str2int16("name"):
	{
		if (std::holds_alternative<std::string>(val) == true)
		{
			Name(std::get<std::string>(val));
		}
	}
	break;
	default:
	{
		if (std::holds_alternative<int64_t>(val) == true)
		{
			if (setNumberByHash(propHash16, (LevelObjValue)std::get<int64_t>(val), nullptr))
			{
				updateProperties();
			}
		}
	}
	break;
	}
}
示例#30
0
void job_implObj::set_option(const std::string_view &name,
			     int value)
{
	size_t s=name.size();

	char name_str[s+1];

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

	job_info_t::lock lock{job_info};

	lock->num_options=cupsAddIntegerOption(name_str, value,
					       lock->num_options,
					       &lock->options);
}