AMFP Enhanced
C++ reference: the code this unofficial fork added
Toggle main menu visibility
Loading...
Searching...
No Matches
LuxDevBridgeParse.h
Go to the documentation of this file.
1
/*
2
* AMFP-2026: parsing for the dev bridge (LuxDevBridge.cpp). A command line is
3
* "<id> <name> [args...]"; args are the rest of the line, spaces kept.
4
* Unit tested in tests/cpp/test_dev_bridge.cpp.
5
*/
6
#ifndef LUX_DEV_BRIDGE_PARSE_H
7
#define LUX_DEV_BRIDGE_PARSE_H
8
9
#include <cstdlib>
10
#include <string>
11
12
struct
cLuxDevCommand
13
{
14
int
mlId
;
15
std::string
msName
;
16
std::string
msArgs
;
17
};
18
19
inline
bool
LuxParseDevCommand
(
const
std::string& asLine,
cLuxDevCommand
& aCmd)
20
{
21
std::string s = asLine;
22
while
(!s.empty() && (s[s.size()-1] ==
'\r'
|| s[s.size()-1] ==
'\n'
|| s[s.size()-1] ==
' '
)) s.erase(s.size()-1);
23
size_t
p = s.find_first_not_of(
' '
);
24
if
(p == std::string::npos || s[p] ==
'#'
)
return
false
;
25
26
// id: non-negative decimal
27
size_t
lIdEnd = p;
28
while
(lIdEnd < s.size() && s[lIdEnd] >=
'0'
&& s[lIdEnd] <=
'9'
) ++lIdEnd;
29
if
(lIdEnd == p || (lIdEnd < s.size() && s[lIdEnd] !=
' '
))
return
false
;
30
aCmd.
mlId
= std::atoi(s.substr(p, lIdEnd - p).c_str());
31
32
size_t
lNameStart = s.find_first_not_of(
' '
, lIdEnd);
33
if
(lNameStart == std::string::npos)
return
false
;
34
size_t
lNameEnd = s.find(
' '
, lNameStart);
35
aCmd.
msName
= s.substr(lNameStart, lNameEnd == std::string::npos ? std::string::npos : lNameEnd - lNameStart);
36
aCmd.
msArgs
=
""
;
37
if
(lNameEnd != std::string::npos)
38
{
39
size_t
lArgs = s.find_first_not_of(
' '
, lNameEnd);
40
if
(lArgs != std::string::npos) aCmd.
msArgs
= s.substr(lArgs);
41
}
42
return
true
;
43
}
44
45
#endif
LuxParseDevCommand
bool LuxParseDevCommand(const std::string &asLine, cLuxDevCommand &aCmd)
Definition
LuxDevBridgeParse.h:19
cLuxDevCommand
Definition
LuxDevBridgeParse.h:13
cLuxDevCommand::msName
std::string msName
Definition
LuxDevBridgeParse.h:15
cLuxDevCommand::mlId
int mlId
Definition
LuxDevBridgeParse.h:14
cLuxDevCommand::msArgs
std::string msArgs
Definition
LuxDevBridgeParse.h:16
Game
src
game
LuxDevBridgeParse.h
Generated by
1.18.0