File indexing completed on 2026-04-09 07:49:39
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include "sstr.h"
0024
0025 struct SGLM_Parse
0026 {
0027 std::vector<std::string> key ;
0028 std::vector<std::string> val ;
0029 std::vector<std::string> opt ;
0030
0031 static bool IsKey(const char* str);
0032 SGLM_Parse(const char* cmd);
0033 std::string desc() const ;
0034 };
0035
0036 inline bool SGLM_Parse::IsKey(const char* str)
0037 {
0038 return str && strlen(str) > 2 && str[0] == '-' && str[1] == '-' ;
0039 }
0040
0041 inline SGLM_Parse::SGLM_Parse(const char* cmd)
0042 {
0043
0044 std::vector<std::string> elem ;
0045 sstr::Split(cmd,' ',elem);
0046 int num_elem = elem.size();
0047
0048 for(int i=0 ; i < std::max(1, num_elem - 1) ; i++)
0049 {
0050 const char* e0 = i < num_elem ? elem[i].c_str() : nullptr ;
0051 const char* e1 = i+1 < num_elem ? elem[i+1].c_str() : nullptr ;
0052 bool k0 = IsKey(e0);
0053 bool k1 = IsKey(e1);
0054
0055 if( ( k0 && k1 ) || (k0 && e1 == nullptr) )
0056 {
0057 opt.push_back(e0+2);
0058 }
0059 else if(k0 && !k1)
0060 {
0061 key.push_back(e0+2);
0062 val.push_back(e1);
0063 }
0064 }
0065 }
0066
0067 inline std::string SGLM_Parse::desc() const
0068 {
0069 std::stringstream ss ;
0070 ss << "SGLM_Parse::desc"
0071 << " key.size " << key.size()
0072 << " val.size " << val.size()
0073 << " opt.size " << opt.size()
0074 << std::endl
0075 ;
0076 std::string str = ss.str();
0077 return str ;
0078 }
0079
0080