util-src/encodings.c

changeset 1826
3d0db768be2f
parent 894
2c0b9e3c11c3
child 1844
a4a8fe2a560c
child 1854
7e055cc6bc90
equal deleted inserted replaced
1812:2683cdaf6dc8 1826:3d0db768be2f
170 const char *s = luaL_checklstring(L, 1, &len); 170 const char *s = luaL_checklstring(L, 1, &len);
171 char* output = NULL; 171 char* output = NULL;
172 int ret = idna_to_ascii_8z(s, &output, 0); 172 int ret = idna_to_ascii_8z(s, &output, 0);
173 if (ret == IDNA_SUCCESS) { 173 if (ret == IDNA_SUCCESS) {
174 lua_pushstring(L, output); 174 lua_pushstring(L, output);
175 if (output) free(output); 175 idn_free(output);
176 return 1; 176 return 1;
177 } else { 177 } else {
178 lua_pushnil(L); 178 lua_pushnil(L);
179 if (output) free(output); 179 idn_free(output);
180 return 1; // TODO return error message 180 return 1; // TODO return error message
181 } 181 }
182 } 182 }
183 183
184 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */ 184 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */
187 const char *s = luaL_checklstring(L, 1, &len); 187 const char *s = luaL_checklstring(L, 1, &len);
188 char* output = NULL; 188 char* output = NULL;
189 int ret = idna_to_unicode_8z8z(s, &output, 0); 189 int ret = idna_to_unicode_8z8z(s, &output, 0);
190 if (ret == IDNA_SUCCESS) { 190 if (ret == IDNA_SUCCESS) {
191 lua_pushstring(L, output); 191 lua_pushstring(L, output);
192 if (output) free(output); 192 idn_free(output);
193 return 1; 193 return 1;
194 } else { 194 } else {
195 lua_pushnil(L); 195 lua_pushnil(L);
196 if (output) free(output); 196 idn_free(output);
197 return 1; // TODO return error message 197 return 1; // TODO return error message
198 } 198 }
199 } 199 }
200 200
201 static const luaL_Reg Reg_idna[] = 201 static const luaL_Reg Reg_idna[] =

mercurial