| 757 | } |
| 758 | |
| 759 | ScriptLanguage::ScriptTemplate ScriptCreateDialog::_parse_template(const ScriptLanguage *p_language, const String &p_path, const String &p_filename, const ScriptLanguage::TemplateLocation &p_origin, const String &p_inherits) const { |
| 760 | ScriptLanguage::ScriptTemplate script_template = ScriptLanguage::ScriptTemplate(); |
| 761 | script_template.origin = p_origin; |
| 762 | script_template.inherit = p_inherits; |
| 763 | int space_indent_size = 4; |
| 764 | // Get meta delimiter |
| 765 | String meta_delimiter; |
| 766 | for (const String &script_delimiter : p_language->get_comment_delimiters()) { |
| 767 | if (!script_delimiter.contains_char(' ')) { |
| 768 | meta_delimiter = script_delimiter; |
| 769 | break; |
| 770 | } |
| 771 | } |
| 772 | String meta_prefix = meta_delimiter + " meta-"; |
| 773 | |
| 774 | // Parse file for meta-information and script content |
| 775 | Error err; |
| 776 | Ref<FileAccess> file = FileAccess::open(p_path.path_join(p_filename), FileAccess::READ, &err); |
| 777 | if (!err) { |
| 778 | while (!file->eof_reached()) { |
| 779 | String line = file->get_line(); |
| 780 | if (line.begins_with(meta_prefix)) { |
| 781 | // Store meta information |
| 782 | line = line.substr(meta_prefix.length()); |
| 783 | if (line.begins_with("name:")) { |
| 784 | script_template.name = line.substr(5).strip_edges(); |
| 785 | } else if (line.begins_with("description:")) { |
| 786 | script_template.description = line.substr(12).strip_edges(); |
| 787 | } else if (line.begins_with("space-indent:")) { |
| 788 | String indent_value = line.substr(13).strip_edges(); |
| 789 | if (indent_value.is_valid_int()) { |
| 790 | int indent_size = indent_value.to_int(); |
| 791 | if (indent_size >= 0) { |
| 792 | space_indent_size = indent_size; |
| 793 | } else { |
| 794 | WARN_PRINT(vformat("Template meta-space-indent need to be a non-negative integer value. Found %s.", indent_value)); |
| 795 | } |
| 796 | } else { |
| 797 | WARN_PRINT(vformat("Template meta-space-indent need to be a valid integer value. Found %s.", indent_value)); |
| 798 | } |
| 799 | } |
| 800 | } else { |
| 801 | // Replace indentation. |
| 802 | int i = 0; |
| 803 | int space_count = 0; |
| 804 | for (; i < line.length(); i++) { |
| 805 | if (line[i] == '\t') { |
| 806 | if (space_count) { |
| 807 | script_template.content += String(" ").repeat(space_count); |
| 808 | space_count = 0; |
| 809 | } |
| 810 | script_template.content += "_TS_"; |
| 811 | } else if (line[i] == ' ') { |
| 812 | space_count++; |
| 813 | if (space_count == space_indent_size) { |
| 814 | script_template.content += "_TS_"; |
| 815 | space_count = 0; |
| 816 | } |
nothing calls this directly
no test coverage detected