Skip to content
Snippets Groups Projects
Commit d8525301 authored by rswindell's avatar rswindell
Browse files

Created methods: ascii_str (convert ex-ascii string to pure ascii) and

strip_exascii (remove all ex-ascii chars from string).
parent e45e1caf
No related branches found
No related tags found
No related merge requests found
......@@ -269,6 +269,26 @@ js_ascii(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return(JS_TRUE);
}
static JSBool
js_ascii_str(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* p;
JSString* js_str;
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
if((p=JS_GetStringBytes(js_str))==NULL)
return(JS_FALSE);
ascii_str(p);
js_str = JS_NewStringCopyZ(cx, p);
*rval = STRING_TO_JSVAL(js_str);
return(JS_TRUE);
}
static JSBool
js_strip_ctrl(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
......@@ -288,6 +308,25 @@ js_strip_ctrl(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
return(JS_TRUE);
}
static JSBool
js_strip_exascii(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* p;
JSString* js_str;
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
if((p=JS_GetStringBytes(js_str))==NULL)
return(JS_FALSE);
strip_exascii(p);
js_str = JS_NewStringCopyZ(cx, p);
*rval = STRING_TO_JSVAL(js_str);
return(JS_TRUE);
}
static JSBool
js_fexist(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
......@@ -570,7 +609,9 @@ static JSFunctionSpec js_global_functions[] = {
{"crc32", js_crc32, 1}, /* calculate 32-bit CRC of string */
{"chksum", js_chksum, 1}, /* calculate 32-bit chksum of string */
{"ascii", js_ascii, 1}, /* convert str to ascii-val or vice-versa */
{"ascii_str", js_ascii_str, 1}, /* convert ex-ascii in str to plain ascii */
{"strip_ctrl", js_strip_ctrl, 1}, /* strip ctrl chars from string */
{"strip_exascii", js_strip_exascii, 1}, /* strip ex-ascii chars from string */
{"file_exists", js_fexist, 1}, /* verify file existence */
{"file_remove", js_remove, 1}, /* delete a file */
{"file_isdir", js_isdir, 1}, /* check if directory */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment