| 362 | } |
| 363 | |
| 364 | std::string CommentValue::comment(const char* encoding) const { |
| 365 | std::string c; |
| 366 | if (value_.length() < 8) { |
| 367 | return c; |
| 368 | } |
| 369 | c = value_.substr(8); |
| 370 | if (charsetId() == unicode) { |
| 371 | const char* from = !encoding || *encoding == '\0' ? detectCharset(c) : encoding; |
| 372 | if (!convertStringCharset(c, from, "UTF-8")) |
| 373 | throw Error(ErrorCode::kerInvalidIconvEncoding, from, "UTF-8"); |
| 374 | } |
| 375 | |
| 376 | // # 1266 Remove trailing nulls |
| 377 | if (charsetId() == undefined || charsetId() == ascii) { |
| 378 | auto n = c.find('\0'); |
| 379 | if (n != std::string::npos) |
| 380 | c.resize(n); |
| 381 | } |
| 382 | return c; |
| 383 | } |
| 384 | |
| 385 | CommentValue::CharsetId CommentValue::charsetId() const { |
| 386 | CharsetId charsetId = undefined; |
no test coverage detected