EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Seperator Class Reference

Separates string to arguments. More...

#include "Seperator.h"

Collaboration diagram for Seperator:

Public Member Functions

 Seperator (const char *str, const char *divs=" \t", const char *quotes="\"\'")
 
const std::string & arg (size_t index) const
 
size_t argCount () const
 
bool isNumber (size_t index) const
 
bool isHexNumber (size_t index) const
 

Protected Attributes

std::vector< std::string > mArgs
 

Detailed Description

Separates string to arguments.

Author
Zhur, Bloody.Rabbit

Definition at line 36 of file Seperator.h.

Constructor & Destructor Documentation

Seperator::Seperator ( const char *  str,
const char *  divs = " \t",
const char *  quotes = "\"\'" 
)

Definition at line 34 of file Seperator.cpp.

References mArgs, and sLog.

35 {
36  bool inQuote = false, isDiv = false, isQuote = false;
37  std::string* cur(nullptr);
38 
39  for (size_t len = strlen( str ); len > 0; ++str, --len ) {
40  const char c = *str;
41  isDiv = (strchr(divs, c) != NULL);
42  isQuote = (strchr( quotes, c) != NULL);
43 
44  if (!inQuote) {
45  if (NULL == cur) {
46  if (!isDiv) {
47  mArgs.push_back( "" );
48  cur = &mArgs.back();
49 
50  if (isQuote)
51  inQuote = true;
52  else
53  cur->push_back( c );
54  }
55  } else {
56  if (isDiv)
57  cur = NULL;
58  else
59  cur->push_back( c );
60  }
61  } else {
62  if (NULL != cur) {
63  if (isQuote)
64  cur = NULL;
65  else
66  cur->push_back( c );
67  } else {
68  if (isDiv)
69  inQuote = false;
70  else
71  sLog.Error( "Seperator", "Invalid input." );
72  }
73  }
74  }
75 }
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
std::vector< std::string > mArgs
Definition: Seperator.h:50

Member Function Documentation

bool Seperator::isHexNumber ( size_t  index) const
inline

Definition at line 47 of file Seperator.h.

References arg(), and IsHexNumber().

Referenced by Command_ban(), Command_kick(), and Command_unban().

47 { return ::IsHexNumber( arg( index ) ); }
const std::string & arg(size_t index) const
Definition: Seperator.h:43
bool IsHexNumber(char c)
Checks whether character is a hexadecimal number.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Seperator::isNumber ( size_t  index) const
inline

Member Data Documentation

std::vector<std::string> Seperator::mArgs
protected

Definition at line 50 of file Seperator.h.

Referenced by arg(), argCount(), and Seperator().


The documentation for this class was generated from the following files: