/**
 * Creates a command line from a list of arguments. The returned
 * string is allocated with "malloc" and should be "free"d.
 *
 * argv is UTF8
 */
wchar_t*
MakeCommandLine(int argc, wchar_t **argv)
{
  int i;
  int len = 0;

  // The + 1 of the last argument handles the allocation for null termination
  for (i = 0; i < argc; ++i)
    len += ArgStrLen(argv[i]) + 1;

  // Protect against callers that pass 0 arguments
  if (len == 0)
    len = 1;

  wchar_t *s = (wchar_t*) malloc(len * sizeof(wchar_t));
  if (!s)
    return nullptr;

  wchar_t *c = s;
  for (i = 0; i < argc; ++i) {
    c = ArgToString(c, argv[i]);
    if (i + 1 != argc) {
      *c = ' ';
      ++c;
    }
  }

  *c = '\0';

  return s;
}
Beispiel #2
0
std::string StringMgr::FormatString(const char* key, const Var* arg)
{
	string text = GetString(key);
	vector<int> indexs;
	vector<ETypeId> typeIds;
	vector<string> strings;
	if (!Parse(key, text, indexs, typeIds, strings))
	{
		//Assert(false);
		return key ? key : "";
	}
	if (strings.size() != 2)
	{
		//Assert(false);
		return key ? key : "";
	}
	return (strings[0] + ArgToString(&arg, typeIds[0]) + strings[1]);
}
Beispiel #3
0
std::string StringMgr::FormatString(const char* key, const vector<Var *>& args)
{
	string text = GetString(key);
	vector<int> indexs;
	vector<ETypeId> typeIds;
	vector<string> strings;
	if (!Parse(key, text, indexs, typeIds, strings))
	{
		//Assert(false);
		return key ? key : "";
	}
	if (strings.size() != args.size() + 1)
	{
		//Assert(false);
		return key ? key : "";
	}
	string ret = strings[0];
	for (size_t i = 0; i < args.size(); ++i)
	{
		ret += ArgToString(*args.at(i), typeIds[i]) + strings[i + 1];
	}
	return ret;
}