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

Created global truncsp method (truncates space off end of string).

parent 710cc84c
No related branches found
No related tags found
No related merge requests found
......@@ -332,6 +332,25 @@ js_strip_exascii(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
return(JS_TRUE);
}
static JSBool
js_truncsp(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);
truncsp(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)
{
......@@ -617,6 +636,7 @@ static JSFunctionSpec js_global_functions[] = {
{"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 */
{"truncsp", js_truncsp, 1}, /* truncate space off end of 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.
Please register or to comment