Lines Matching full:-
8 Copyright (C) 2007-2013 Gerald Franz, eludi.net
55 //--- auxliary functions -------------------------------------------
71 return found ? found-s : strlen(s); in find()
74 //--- internal tokenizer -------------------------------------------
100 tok->s_size = str_size; in Tokenizer_new()
101 tok->s = str; in Tokenizer_new()
106 free(tok->m_token); in Tokenizer_delete()
110 …\n", tok->i, !tok->m_token ? "(null)" : (tok->m_token[0]==ESC)?"(esc)" : (tok->m_token[0]==OPN)?"(…
114 free(tok->m_token); in Tokenizer_set()
115 tok->m_token = (char*)malloc(size+1); in Tokenizer_set()
116 strncpy(tok->m_token,s, size); in Tokenizer_set()
117 tok->m_token[size] = 0; in Tokenizer_set()
118 tok->m_token_size = tok->m_token_capacity = size; in Tokenizer_set()
120 return tok->m_token; in Tokenizer_set()
124 if(tok->m_token_size+1>=tok->m_token_capacity) { in Tokenizer_append()
125 tok->m_token_capacity = (tok->m_token_capacity==0) ? 16 : tok->m_token_capacity*2; in Tokenizer_append()
126 tok->m_token = (char*)realloc(tok->m_token, tok->m_token_capacity); in Tokenizer_append()
128 tok->m_token[tok->m_token_size]=ch; in Tokenizer_append()
129 tok->m_token[++tok->m_token_size]=0; in Tokenizer_append()
139 if(tok->m_token) { in Tokenizer_next()
140 free(tok->m_token); in Tokenizer_next()
141 tok->m_token = 0; in Tokenizer_next()
142 tok->m_token_size=tok->m_token_capacity = 0; in Tokenizer_next()
145 while(tok->m_next_size || (tok->i < tok->s_size)) { in Tokenizer_next()
147 if(tok->m_next_size) { in Tokenizer_next()
148 Tokenizer_set(tok, tok->m_next, tok->m_next_size); in Tokenizer_next()
149 tok->m_next=0; in Tokenizer_next()
150 tok->m_next_size=0; in Tokenizer_next()
151 return tok->m_token; in Tokenizer_next()
154 switch(tok->s[tok->i]) { in Tokenizer_next()
157 if(tok->tagMode) { in Tokenizer_next()
158 if(!quotMode) quotMode=tok->s[tok->i]; in Tokenizer_next()
159 else if(quotMode==tok->s[tok->i]) quotMode=0; in Tokenizer_next()
161 Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
164 … if(!quotMode&&(tok->i+4<tok->s_size)&&(strncmp(tok->s+tok->i,"<!--",4)==0)) // strip comments in Tokenizer_next()
165 tok->i=find(tok->s, "-->", tok->i+4)+2; in Tokenizer_next()
166 …else if(!quotMode&&(tok->i+9<tok->s_size)&&(strncmp(tok->s+tok->i,"<![CDATA[",9)==0)) { // interpe… in Tokenizer_next()
167 size_t b=tok->i+9; in Tokenizer_next()
168 tok->i=find(tok->s, "]]>",b)+3; in Tokenizer_next()
169 if(!tok->m_token_size) return Tokenizer_set(tok, tok->s+b, tok->i-b-3); in Tokenizer_next()
171 tok->m_next = tok->s+b; in Tokenizer_next()
172 tok->m_next_size = tok->i-b-3; in Tokenizer_next()
173 --tok->i; in Tokenizer_next()
175 …else if(!quotMode&&(tok->i+1<tok->s_size)&&((tok->s[tok->i+1]=='?')||(tok->s[tok->i+1]=='!'))) // … in Tokenizer_next()
176 tok->i=find(tok->s, ">", tok->i+2); in Tokenizer_next()
177 else if(!quotMode&&!tok->tagMode) { in Tokenizer_next()
178 if((tok->i+1<tok->s_size)&&(tok->s[tok->i+1]=='/')) { in Tokenizer_next()
179 tok->m_next=ESC_str; in Tokenizer_next()
180 tok->m_next_size = 1; in Tokenizer_next()
181 tok->i=find(tok->s, ">", tok->i+2); in Tokenizer_next()
184 tok->m_next = OPEN_str; in Tokenizer_next()
185 tok->m_next_size = 1; in Tokenizer_next()
186 tok->tagMode=1; in Tokenizer_next()
190 else Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
193 if(tok->tagMode&&!quotMode) { in Tokenizer_next()
195 if((tok->i+1 < tok->s_size) && (tok->s[tok->i+1]=='>')) { in Tokenizer_next()
196 tok->tagMode=0; in Tokenizer_next()
197 tok->m_next=ESC_str; in Tokenizer_next()
198 tok->m_next_size = 1; in Tokenizer_next()
199 ++tok->i; in Tokenizer_next()
201 else Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
203 else Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
206 if(!quotMode&&tok->tagMode) { in Tokenizer_next()
207 tok->tagMode=0; in Tokenizer_next()
209 tok->m_next = CLOSE_str; in Tokenizer_next()
210 tok->m_next_size = 1; in Tokenizer_next()
212 else Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
218 if(tok->tagMode&&!quotMode) { in Tokenizer_next()
219 if(tok->m_token_size) tokenComplete=1; in Tokenizer_next()
221 else if(tok->m_token_size) Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
223 default: Tokenizer_append(tok, tok->s[tok->i]); in Tokenizer_next()
225 ++tok->i; in Tokenizer_next()
226 if((tok->i>=tok->s_size)||(tokenComplete&&tok->m_token_size)) { in Tokenizer_next()
228 while(tok->m_token_size&&isspace(tok->m_token[tok->m_token_size-1])) // trim whitespace in Tokenizer_next()
229 tok->m_token[--tok->m_token_size]=0; in Tokenizer_next()
230 if(tok->m_token_size) break; in Tokenizer_next()
234 return tok->m_token; in Tokenizer_next()
237 //--- local variables ----------------------------------------------
246 //--- public methods -----------------------------------------------
259 pos = found ? found-s : s_size; in Xml_pushDecode()
266 ch = ch * 10 + (*found - 48); in Xml_pushDecode()
270 luaL_addlstring(&b, s+start, pos-start); in Xml_pushDecode()
275 pos = found ? found-s : s_size; in Xml_pushDecode()
278 luaL_addlstring(&b,s+start, pos-start); in Xml_pushDecode()
281 for(i=sv_code_size-1; i<sv_code_size; i-=2) { in Xml_pushDecode()
282 luaL_gsub(L, lua_tostring(L,-1), sv_code[i], sv_code[i-1]); in Xml_pushDecode()
283 lua_remove(L,-2); in Xml_pushDecode()
307 size_t newIndex=lua_rawlen(L,-1)+1; in Xml_eval()
310 lua_settable(L, -3); in Xml_eval()
312 lua_gettable(L,-2); in Xml_eval()
325 lua_settable(L, -3); in Xml_eval()
330 lua_gettable(L, -2); in Xml_eval()
331 lua_remove(L, -2); in Xml_eval()
332 lua_settable(L, -3); in Xml_eval()
333 lua_setmetatable(L, -2); in Xml_eval()
338 lua_settable(L, -3); in Xml_eval()
347 lenVal = strlen(aVal)-1; in Xml_eval()
350 lua_settable(L, -3); in Xml_eval()
354 if(lua_gettop(L)>1) lua_settop(L,-2); // this tag has no content, only attributes in Xml_eval()
359 if(lua_gettop(L)>1) lua_settop(L,-2); // pop current table in Xml_eval()
363 lua_pushnumber(L,(lua_Number)lua_rawlen(L,-1)+1); in Xml_eval()
365 lua_settable(L, -3); in Xml_eval()
422 luaL_checkstring(L,-1); in Xml_encode()
425 luaL_gsub(L, lua_tostring(L,-1), sv_code[i], sv_code[i+1]); in Xml_encode()
426 lua_remove(L,-2); in Xml_encode()
431 if(pos>start) luaL_addlstring(&b,s+start, pos-start); in Xml_encode()
436 luaL_addlstring(&b,s+start, pos-start); in Xml_encode()
438 lua_remove(L,-2); in Xml_encode()