diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2018-10-22 19:43:19 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2018-10-25 18:00:24 +0200 |
commit | 1aac95a7375e58bacade69ed12f9dade484a03a8 (patch) | |
tree | 740e21d53c5a65e1e405f3f71b89ba05a7cf4fae /modules/mono/utils/string_utils.cpp | |
parent | c6e2873605c33230210af2738f59b869ffe2141c (diff) | |
download | redot-engine-1aac95a7375e58bacade69ed12f9dade484a03a8.tar.gz |
Parse C# script namespace and class
- Added a very simple parser that can extract the namespace and class name of a C# script.
Diffstat (limited to 'modules/mono/utils/string_utils.cpp')
-rw-r--r-- | modules/mono/utils/string_utils.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index 8691932f9a..6900866725 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -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; +} |