EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommandHelper.cpp
Go to the documentation of this file.
1 #include "admin/CommandHelper.h"
2 
3 
4 // finds the nth noneq argument
5 // this function is 1 indexed meaning n = 1 would return the FIRST occurence
6 // if not found returns 0
7 // this function returns the index of the args
8 int cmd_find_nth_noneq(const Seperator &args, int n) {
9  int c = 0;
10  for (int i = 0; i < args.argCount(); i++) {
11  std::string arg = args.arg(i);
12  size_t pos = arg.find("=");
13 
14  // Didn't find = in string
15  if (pos == std::string::npos) {
16  c++;
17  if (c == n) {
18  return i;
19  }
20  }
21  }
22  return -1;
23 }
24 
25 // name should be like "name="
26 std::string cmd_parse_eq_arg(const Seperator &args, const char *name) {
27  for (int i = 1; i < args.argCount(); i++) {
28  std::string arg = args.arg(i);
29  size_t pos = arg.find(name);
30  codelog(COMMAND__ERROR, "cmd_parse_eq_arg: %d name '%s' arg '%s' pos: '%d'",
31  i, name, arg.c_str(), pos);
32  if (pos == std::string::npos) {
33  continue;
34  }
35  if (strlen(name) >= arg.size()) {
36  continue;
37  }
38  codelog(COMMAND__ERROR, " returning: '%s'", arg.c_str() + strlen(name));
39  return std::string(arg.c_str() + strlen(name));
40  }
41 
42  return std::string();
43 }
const std::string & arg(size_t index) const
Definition: Seperator.h:43
std::string cmd_parse_eq_arg(const Seperator &args, const char *name)
Separates string to arguments.
Definition: Seperator.h:36
* args
size_t argCount() const
Definition: Seperator.h:44
#define codelog(type, fmt,...)
Definition: logsys.h:128
int cmd_find_nth_noneq(const Seperator &args, int n)