--- parser3/src/classes/string.C 2001/10/29 13:04:46 1.86 +++ parser3/src/classes/string.C 2001/11/09 11:59:13 1.89 @@ -2,9 +2,9 @@ Parser: @b string parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: string.C,v 1.86 2001/10/29 13:04:46 paf Exp $ + $Id: string.C,v 1.89 2001/11/09 11:59:13 paf Exp $ */ #include "classes.h" @@ -427,14 +427,26 @@ static void _replace(Request& r, const S static void _save(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - Value& vfile_name=params->as_no_junction(0, - "file name must not be code"); + const String& file_name=params->as_string(params->size()-1, + "file name must be string"); const String& src=*static_cast(r.self)->get_string(); + bool do_append=false; + if(params->size()>1) { + const String& mode=params->as_string(0, "mode must be string"); + if(mode=="append") + do_append=true; + else + throw Exception(0, 0, + &mode, + "unknown mode, must be 'append'"); + } + // write - file_write(pool, r.absolute(vfile_name.as_string()), - src.cstr(String::UL_AS_IS), src.size(), true); + const char *buf=src.cstr(String::UL_UNSPECIFIED); + file_write(pool, r.absolute(file_name), + buf, strlen(buf), true, do_append); } // constructor @@ -488,7 +500,7 @@ MString::MString(Pool& apool) : Methoded add_native_method("replace", Method::CT_DYNAMIC, _replace, 1, 1); // ^string.save[file] - add_native_method("save", Method::CT_DYNAMIC, _save, 1, 1); + add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); } // global variable