Parse C# script namespace and class

- Added a very simple parser that can extract the namespace and class name of a C# script.
This commit is contained in:
Ignacio Etcheverry 2018-10-22 19:43:19 +02:00
parent c6e2873605
commit 1aac95a737
14 changed files with 891 additions and 53 deletions

View file

@ -30,6 +30,8 @@
#include "string_utils.h"
#include "core/os/file_access.h"
namespace {
int sfind(const String &p_text, int p_from) {
@ -128,6 +130,7 @@ String sformat(const String &p_text, const Variant &p1, const Variant &p2, const
return new_string;
}
#ifdef TOOLS_ENABLED
bool is_csharp_keyword(const String &p_name) {
// Reserved keywords
@ -156,3 +159,28 @@ bool is_csharp_keyword(const String &p_name) {
String escape_csharp_keyword(const String &p_name) {
return is_csharp_keyword(p_name) ? "@" + p_name : p_name;
}
#endif
Error read_all_file_utf8(const String &p_path, String &r_content) {
PoolVector<uint8_t> sourcef;
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
ERR_FAIL_COND_V(err != OK, err);
int len = f->get_len();
sourcef.resize(len + 1);
PoolVector<uint8_t>::Write w = sourcef.write();
int r = f->get_buffer(w.ptr(), len);
f->close();
memdelete(f);
ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);
w[len] = 0;
String source;
if (source.parse_utf8((const char *)w.ptr())) {
ERR_FAIL_V(ERR_INVALID_DATA);
}
r_content = source;
return OK;
}