summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp7
-rw-r--r--core/bind/core_bind.h3
-rw-r--r--core/io/config_file.cpp6
-rw-r--r--core/io/json.cpp2
-rw-r--r--core/os/file_access.h1
-rw-r--r--core/os/os.cpp2
-rw-r--r--core/os/os.h2
-rw-r--r--core/ustring.cpp15
-rw-r--r--core/ustring.h1
-rw-r--r--core/variant_call.cpp6
-rw-r--r--core/variant_parser.cpp12
11 files changed, 46 insertions, 11 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index f1edc3d7d7..f951237971 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -494,8 +494,8 @@ uint64_t _OS::get_unix_time() const {
return OS::get_singleton()->get_unix_time();
};
-uint64_t _OS::get_system_time_msec() const {
- return OS::get_singleton()->get_system_time_msec();
+uint64_t _OS::get_system_time_secs() const {
+ return OS::get_singleton()->get_system_time_secs();
}
void _OS::delay_usec(uint32_t p_usec) const {
@@ -810,7 +810,7 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
ObjectTypeDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
- ObjectTypeDB::bind_method(_MD("get_system_time_msec"), &_OS::get_system_time_msec);
+ ObjectTypeDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
ObjectTypeDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
@@ -1509,6 +1509,7 @@ void _File::_bind_methods() {
BIND_CONSTANT( READ );
BIND_CONSTANT( WRITE );
BIND_CONSTANT( READ_WRITE );
+ BIND_CONSTANT( WRITE_READ );
}
_File::_File(){
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 172f33dac5..62572d7761 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -208,7 +208,7 @@ public:
Dictionary get_time(bool utc) const;
Dictionary get_time_zone_info() const;
uint64_t get_unix_time() const;
- uint64_t get_system_time_msec() const;
+ uint64_t get_system_time_secs() const;
int get_static_memory_usage() const;
int get_static_memory_peak_usage() const;
@@ -329,6 +329,7 @@ public:
READ=1,
WRITE=2,
READ_WRITE=3,
+ WRITE_READ=7,
};
Error open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key);
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index d79a3d1288..fd20ec9404 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -127,6 +127,8 @@ Error ConfigFile::save(const String& p_path){
FileAccess *file = FileAccess::open(p_path,FileAccess::WRITE,&err);
if (err) {
+ if (file)
+ memdelete(file);
return err;
}
@@ -178,8 +180,10 @@ Error ConfigFile::load(const String& p_path) {
next_tag.name=String();
err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true);
- if (err==ERR_FILE_EOF)
+ if (err==ERR_FILE_EOF) {
+ memdelete(f);
return OK;
+ }
else if (err!=OK) {
ERR_PRINTS("ConfgFile::load - "+p_path+":"+itos(lines)+" error: "+error_text);
memdelete(f);
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 45a97ed720..f9a8638d06 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -86,7 +86,7 @@ String JSON::_print_var(const Variant& p_var) {
s+="}";
return s;
};
- default: return "\""+String(p_var).c_escape()+"\"";
+ default: return "\""+String(p_var).json_escape()+"\"";
}
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 35514a129f..51cf839117 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -78,6 +78,7 @@ public:
READ=1,
WRITE=2,
READ_WRITE=3,
+ WRITE_READ=7,
};
virtual void close()=0; ///< close a file
diff --git a/core/os/os.cpp b/core/os/os.cpp
index eb5f91167a..1a505fb236 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -50,7 +50,7 @@ uint64_t OS::get_unix_time() const {
return 0;
};
-uint64_t OS::get_system_time_msec() const {
+uint64_t OS::get_system_time_secs() const {
return 0;
}
void OS::debug_break() {
diff --git a/core/os/os.h b/core/os/os.h
index 94cb1d4ea4..711743f23a 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -256,7 +256,7 @@ public:
virtual Time get_time(bool local=false) const=0;
virtual TimeZoneInfo get_time_zone_info() const=0;
virtual uint64_t get_unix_time() const;
- virtual uint64_t get_system_time_msec() const;
+ virtual uint64_t get_system_time_secs() const;
virtual void delay_usec(uint32_t p_usec) const=0;
virtual uint64_t get_ticks_usec() const=0;
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 21c0d78fdb..ee750c39e5 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3158,6 +3158,21 @@ String String::c_escape() const {
return escaped;
}
+String String::json_escape() const {
+
+ String escaped=*this;
+ escaped=escaped.replace("\\","\\\\");
+ escaped=escaped.replace("\b","\\b");
+ escaped=escaped.replace("\f","\\f");
+ escaped=escaped.replace("\n","\\n");
+ escaped=escaped.replace("\r","\\r");
+ escaped=escaped.replace("\t","\\t");
+ escaped=escaped.replace("\v","\\v");
+ escaped=escaped.replace("\"","\\\"");
+
+ return escaped;
+}
+
String String::xml_escape(bool p_escape_quotes) const {
String str=*this;
diff --git a/core/ustring.h b/core/ustring.h
index 2b967d368a..9276afa0f7 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -211,6 +211,7 @@ public:
String http_unescape() const;
String c_escape() const;
String c_unescape() const;
+ String json_escape() const;
String world_wrap(int p_chars_per_line) const;
String percent_encode() const;
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 2122640be8..90f868c866 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -272,6 +272,9 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(String,get_file);
VCALL_LOCALMEM0R(String,xml_escape);
VCALL_LOCALMEM0R(String,xml_unescape);
+ VCALL_LOCALMEM0R(String,c_escape);
+ VCALL_LOCALMEM0R(String,c_unescape);
+ VCALL_LOCALMEM0R(String,json_escape);
VCALL_LOCALMEM0R(String,percent_encode);
VCALL_LOCALMEM0R(String,percent_decode);
VCALL_LOCALMEM0R(String,is_valid_identifier);
@@ -1286,6 +1289,9 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(STRING,STRING,String,get_file,varray());
ADDFUNC0(STRING,STRING,String,xml_escape,varray());
ADDFUNC0(STRING,STRING,String,xml_unescape,varray());
+ ADDFUNC0(STRING,STRING,String,c_escape,varray());
+ ADDFUNC0(STRING,STRING,String,c_unescape,varray());
+ ADDFUNC0(STRING,STRING,String,json_escape,varray());
ADDFUNC0(STRING,STRING,String,percent_encode,varray());
ADDFUNC0(STRING,STRING,String,percent_decode,varray());
ADDFUNC0(STRING,BOOL,String,is_valid_identifier,varray());
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 446f9ae6d1..3efa87de80 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -448,7 +448,7 @@ Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,in
if (!first) {
get_token(p_stream,token,line,r_err_str);
if (token.type==TK_COMMA) {
- //do none
+ //do none
} else if (token.type==TK_PARENTHESIS_CLOSE) {
break;
} else {
@@ -458,7 +458,10 @@ Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,in
}
}
get_token(p_stream,token,line,r_err_str);
- if (token.type!=TK_NUMBER) {
+
+ if (first && token.type==TK_PARENTHESIS_CLOSE) {
+ break;
+ } else if (token.type!=TK_NUMBER) {
r_err_str="Expected float in constructor";
return ERR_PARSE_ERROR;
}
@@ -1801,7 +1804,10 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
} break;
case Variant::REAL: {
- p_store_string_func(p_store_string_ud, rtoss(p_variant.operator real_t()) );
+ String s = rtoss(p_variant.operator real_t());
+ if (s.find(".")==-1 && s.find("e")==-1)
+ s+=".0";
+ p_store_string_func(p_store_string_ud, s );
} break;
case Variant::STRING: {