Fix getCssLength returning false for '0'
[ryzomcore.git] / nel / src / gui / proc.cpp
blob4ecb418782e98078ec0b75b380eeb4f99b893ca5
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
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/>.
21 #include "stdpch.h"
22 #include "nel/gui/proc.h"
24 #include "nel/misc/algo.h"
26 using namespace NLMISC;
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 namespace NLGUI
35 #define PROC_PARAM_IDENT '@'
37 // ***************************************************************************
38 void CProcAction::buildParamBlock( const std::string &params )
40 buildBlocks( params, ParamBlocks );
43 void CProcAction::buildParams( const std::vector< std::string > &paramList, std::string &params ) const
45 eval( paramList, ParamBlocks, params );
48 void CProcAction::buildCondBlock( const std::string &params )
50 buildBlocks( params, CondBlocks );
53 void CProcAction::buildCond( const std::vector< std::string > &paramList, std::string &params ) const
55 eval( paramList, CondBlocks, params );
58 // ***************************************************************************
59 void CProcAction::buildBlocks( const std::string &in, std::vector< CParamBlock > &out )
61 out.clear();
63 if(in.empty())
64 return;
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)
76 // then skip
77 curPos= in.size();
79 else
81 // Skip all @
82 uint countNbIdent = 0;
83 while (curPos<in.size() && in[curPos]==PROC_PARAM_IDENT)
85 curPos++;
86 countNbIdent++;
89 // get the id pos
90 uint countNbDigit = 0;
91 uint startIdPos= (uint)curPos;
92 while (curPos<in.size() && in[curPos]>='0' && in[curPos]<='9')
94 curPos++;
95 countNbDigit++;
98 if (curPos == startIdPos)
100 // No digit so it is a normal db entry
101 lastString+= in.substr (lastPos, curPos-(countNbIdent-1)-lastPos);
102 // all @ are skipped
104 else
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);
110 if (nbToCopy > 0)
111 lastString += in.substr(lastPos, nbToCopy);
113 // if not empty, add to the param block
114 if (!lastString.empty())
116 CParamBlock pb;
117 pb.String = lastString;
118 out.push_back(pb);
119 // clear it
120 lastString.clear();
123 // get the param id
124 sint paramId;
125 fromString(in.substr(startIdPos, curPos-startIdPos), paramId);
126 // Add it to the param block
127 CParamBlock pb;
128 pb.NumParam = paramId;
129 out.push_back(pb);
132 // valid pos is current pos
133 lastPos= curPos;
136 // concat last part
137 lastString+= in.substr(lastPos, in.size()-lastPos);
138 if(!lastString.empty())
140 CParamBlock pb;
141 pb.String = lastString;
142 out.push_back(pb);
146 // ***************************************************************************
147 void CProcAction::eval( const std::vector<std::string> &inArgs, const std::vector< CParamBlock > &inBlocks, std::string &out )
149 // clear the ret string
150 out.clear();
152 // for all block
153 for (uint i=0; i < inBlocks.size(); i++)
155 const CParamBlock &pb = inBlocks[i];
156 // if the block is a raw string
157 if (pb.NumParam < 0)
159 // concat with the block
160 out += pb.String;
162 // else get from paramList
163 else
165 // add 1, because paramList[0] is the name of the procedure
166 sint idInList = pb.NumParam+1;
167 // if param exist
168 if (idInList < (sint)inArgs.size())
169 // concat with the params
170 out += inArgs[idInList];
171 // else skip (should fail)