diff options
author | Ignacio Etcheverry <neikeq@users.noreply.github.com> | 2018-10-25 18:18:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 18:18:40 +0200 |
commit | d47cec43f2f4ef2cd6d1a0acf6e99a9dd8d31eef (patch) | |
tree | 5dd8beb564a74a8fd52d98f4ca727077532bfad2 /modules/mono/utils/string_utils.cpp | |
parent | dbaa22329761ce7a4d8bab291871b5b5ba359cbe (diff) | |
parent | 1aac95a7375e58bacade69ed12f9dade484a03a8 (diff) | |
download | redot-engine-d47cec43f2f4ef2cd6d1a0acf6e99a9dd8d31eef.tar.gz |
Merge pull request #23162 from neikeq/cc
Proper support for namespaces and other enhancement/fixes
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; +} |