| 80 | } |
| 81 | |
| 82 | bool EnergyManagementSystemSubroutine_Impl::setBody(const std::string& body) { |
| 83 | //set body of program to input string |
| 84 | bool result = false; |
| 85 | // TODO: JM 2019-01-03: This is unused |
| 86 | [[maybe_unused]] bool comment_result = false; |
| 87 | //if body string empty then return false |
| 88 | if (body.empty()) { |
| 89 | return false; |
| 90 | }; |
| 91 | |
| 92 | //clobber existing body |
| 93 | this->resetBody(); |
| 94 | |
| 95 | // remove '\r' from the body string |
| 96 | std::string body_minus_r = body; |
| 97 | std::string::size_type pos = 0; // Must initialize |
| 98 | while ((pos = body_minus_r.find("\r", pos)) != std::string::npos) { |
| 99 | body_minus_r.erase(pos, 1); |
| 100 | } |
| 101 | |
| 102 | //split the body string on newline characters and insert program line for each string line |
| 103 | std::vector<std::string> body_minus_nl = splitString(body_minus_r, '\n'); |
| 104 | std::string body_minus_comment; |
| 105 | std::vector<std::string> comments; |
| 106 | std::string comment; |
| 107 | |
| 108 | //add program lines to body |
| 109 | for (size_t i = 0; i < body_minus_nl.size(); i++) { |
| 110 | //split string on comment character ! |
| 111 | comments = splitString(body_minus_nl.at(i), '!'); |
| 112 | //get extensibleGroup object |
| 113 | auto group = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>(); |
| 114 | //make sure program line exists and insert |
| 115 | if (!comments.empty()) { |
| 116 | //remove whitespace at end of comments[0] |
| 117 | boost::trim_right(comments[0]); |
| 118 | //remove whitespace at beginning of comments[0] |
| 119 | boost::trim_left(comments[0]); |
| 120 | //remove , |
| 121 | pos = 0; |
| 122 | while ((pos = comments[0].find(",", pos)) != std::string::npos) { |
| 123 | comments[0].erase(pos, 1); |
| 124 | } |
| 125 | //insert program line |
| 126 | result = group.setString(OS_EnergyManagementSystem_SubroutineExtensibleFields::ProgramLine, comments[0]); |
| 127 | if (!result) { |
| 128 | return result; |
| 129 | } |
| 130 | //check if comments exist |
| 131 | if (comments.size() > 1) { |
| 132 | //clear out the old comment |
| 133 | comment.clear(); |
| 134 | //add comment to comment vector |
| 135 | comment.append(comments.at(1)); |
| 136 | //combine any remaining comments for this line into one comment |
| 137 | if (comments.size() > 2) { |
| 138 | for (size_t j = 2; j < comments.size(); j++) { |
| 139 | comment.append("!" + comments.at(j)); |
nothing calls this directly
no test coverage detected