| 237 | } |
| 238 | |
| 239 | void ColorSpace::setInteropID(const char * interopID) |
| 240 | { |
| 241 | std::string id = interopID ? interopID : ""; |
| 242 | |
| 243 | if (!id.empty()) |
| 244 | { |
| 245 | // check if it only uses ASCII characters: 0-9, a-z, and the following characters (no spaces): |
| 246 | // . - _ ~ / * # % ^ + ( ) [ ] | |
| 247 | auto allowed = [](char c) |
| 248 | { |
| 249 | return (c >= '0' && c <= '9')|| |
| 250 | (c >= 'a' && c <= 'z')|| |
| 251 | c=='.'||c=='-'||c=='_'||c=='~'||c=='/'||c=='*'||c=='#'||c=='%'|| |
| 252 | c=='^'||c=='+'||c=='('||c==')'||c=='['||c==']'||c=='|'||c==':'; |
| 253 | }; |
| 254 | |
| 255 | if (!std::all_of(id.begin(), id.end(), allowed)) |
| 256 | { |
| 257 | std::ostringstream oss; |
| 258 | oss << "InteropID '" << id << "' contains invalid characters. " |
| 259 | "Only lowercase a-z, 0-9 and . - _ ~ / * # % ^ + ( ) [ ] | are allowed." << |
| 260 | std::endl; |
| 261 | throw Exception(oss.str().c_str()); |
| 262 | } |
| 263 | |
| 264 | // Check if has a namespace. |
| 265 | size_t pos = id.find(':'); |
| 266 | if (pos != std::string::npos) |
| 267 | { |
| 268 | // Namespace found, split into namespace and color space. |
| 269 | std::string ns = id.substr(0, pos); |
| 270 | std::string cs = id.substr(pos+1); |
| 271 | |
| 272 | // both should be non-empty |
| 273 | if (ns.empty() || cs.empty()) |
| 274 | { |
| 275 | std::ostringstream oss; |
| 276 | oss << "InteropID '" << id << "' is not valid. " |
| 277 | "If ':' is used, both the namespace and the color space parts must be non-empty." << |
| 278 | std::endl; |
| 279 | throw Exception(oss.str().c_str()); |
| 280 | } |
| 281 | |
| 282 | // More than one ':' is an error. |
| 283 | if (cs.find(':') != std::string::npos) |
| 284 | { |
| 285 | std::ostringstream oss; |
| 286 | oss << "ERROR: InteropID '" << id << "' is not valid. " |
| 287 | "Only one ':' is allowed to separate the namespace and the color space." << |
| 288 | std::endl; |
| 289 | throw Exception(oss.str().c_str()); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | getImpl()->m_interopID = id; |
| 295 | } |
| 296 | |