| 153 | } |
| 154 | |
| 155 | void validateInstanceName(const std::string& name, int line_number) |
| 156 | { |
| 157 | // Instance name CAN be empty (defaults to model name) |
| 158 | // Instance names are XML attribute VALUES, so they can contain spaces, |
| 159 | // periods, and most characters. We only reject control characters that |
| 160 | // are invalid in XML. |
| 161 | if(name.empty()) |
| 162 | { |
| 163 | return; |
| 164 | } |
| 165 | for(const char c : name) |
| 166 | { |
| 167 | const auto uc = static_cast<unsigned char>(c); |
| 168 | // Only reject control characters that are invalid in XML |
| 169 | // (XML allows tab=0x09, newline=0x0A, carriage return=0x0D) |
| 170 | if(uc < 32 && uc != 0x09 && uc != 0x0A && uc != 0x0D) |
| 171 | { |
| 172 | const auto line_str = std::to_string(line_number); |
| 173 | throw RuntimeError("Error at line ", line_str, ": Instance name '", name, |
| 174 | "' contains invalid control character (ASCII ", |
| 175 | std::to_string(static_cast<int>(uc)), ")"); |
| 176 | } |
| 177 | if(uc == 127) |
| 178 | { |
| 179 | const auto line_str = std::to_string(line_number); |
| 180 | throw RuntimeError("Error at line ", line_str, ": Instance name '", name, |
| 181 | "' contains invalid control character (ASCII 127)"); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | struct SubtreeModel |
| 187 | { |
no test coverage detected