1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "nel/gui/proc.h"
24 #include "nel/misc/algo.h"
26 using namespace NLMISC
;
35 #define PROC_PARAM_IDENT '@'
37 // ***************************************************************************
38 void CProcAction::buildParamBlock( const std::string
¶ms
)
40 buildBlocks( params
, ParamBlocks
);
43 void CProcAction::buildParams( const std::vector
< std::string
> ¶mList
, std::string
¶ms
) const
45 eval( paramList
, ParamBlocks
, params
);
48 void CProcAction::buildCondBlock( const std::string
¶ms
)
50 buildBlocks( params
, CondBlocks
);
53 void CProcAction::buildCond( const std::vector
< std::string
> ¶mList
, std::string
¶ms
) const
55 eval( paramList
, CondBlocks
, params
);
58 // ***************************************************************************
59 void CProcAction::buildBlocks( const std::string
&in
, std::vector
< CParamBlock
> &out
)
66 std::string lastString
;
67 std::string::size_type curPos
= 0;
68 std::string::size_type lastPos
= 0;
70 //if it has some @ then solve proc value
71 while( (curPos
=in
.find(PROC_PARAM_IDENT
, curPos
)) != std::string::npos
)
73 // If it is end of line
74 if(curPos
==in
.size()-1)
82 uint countNbIdent
= 0;
83 while (curPos
<in
.size() && in
[curPos
]==PROC_PARAM_IDENT
)
90 uint countNbDigit
= 0;
91 uint startIdPos
= (uint
)curPos
;
92 while (curPos
<in
.size() && in
[curPos
]>='0' && in
[curPos
]<='9')
98 if (curPos
== startIdPos
)
100 // No digit so it is a normal db entry
101 lastString
+= in
.substr (lastPos
, curPos
-(countNbIdent
-1)-lastPos
);
106 // There is some digit it is an argument
108 // copy the last not param sub string.
109 sint nbToCopy
= (sint
)(curPos
-countNbIdent
-countNbDigit
-lastPos
);
111 lastString
+= in
.substr(lastPos
, nbToCopy
);
113 // if not empty, add to the param block
114 if (!lastString
.empty())
117 pb
.String
= lastString
;
125 fromString(in
.substr(startIdPos
, curPos
-startIdPos
), paramId
);
126 // Add it to the param block
128 pb
.NumParam
= paramId
;
132 // valid pos is current pos
137 lastString
+= in
.substr(lastPos
, in
.size()-lastPos
);
138 if(!lastString
.empty())
141 pb
.String
= lastString
;
146 // ***************************************************************************
147 void CProcAction::eval( const std::vector
<std::string
> &inArgs
, const std::vector
< CParamBlock
> &inBlocks
, std::string
&out
)
149 // clear the ret string
153 for (uint i
=0; i
< inBlocks
.size(); i
++)
155 const CParamBlock
&pb
= inBlocks
[i
];
156 // if the block is a raw string
159 // concat with the block
162 // else get from paramList
165 // add 1, because paramList[0] is the name of the procedure
166 sint idInList
= pb
.NumParam
+1;
168 if (idInList
< (sint
)inArgs
.size())
169 // concat with the params
170 out
+= inArgs
[idInList
];
171 // else skip (should fail)