Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 949:766a57997121
enumeration for encodings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Jun 2014 15:02:37 +0200 |
parents | b3f6fb1130cd |
children | 8811abd6aec9 |
comparison
equal
deleted
inserted
replaced
942:b3f6fb1130cd | 949:766a57997121 |
---|---|
493 return p.parent_path().string(); | 493 return p.parent_path().string(); |
494 } | 494 } |
495 | 495 |
496 | 496 |
497 std::string Toolbox::ConvertToUtf8(const std::string& source, | 497 std::string Toolbox::ConvertToUtf8(const std::string& source, |
498 const char* fromEncoding) | 498 const Encoding sourceEncoding) |
499 { | 499 { |
500 const char* encoding; | |
501 | |
502 switch (sourceEncoding) | |
503 { | |
504 case Encoding_Utf8: | |
505 // Already in UTF-8: No conversion is required | |
506 return source; | |
507 | |
508 case Encoding_Latin1: | |
509 encoding = "ISO-8859-1"; | |
510 break; | |
511 | |
512 default: | |
513 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
514 } | |
515 | |
500 try | 516 try |
501 { | 517 { |
502 return boost::locale::conv::to_utf<char>(source, fromEncoding); | 518 return boost::locale::conv::to_utf<char>(source, encoding); |
503 } | 519 } |
504 catch (std::runtime_error&) | 520 catch (std::runtime_error&) |
505 { | 521 { |
506 // Bad input string or bad encoding | 522 // Bad input string or bad encoding |
507 return ConvertToAscii(source); | 523 return ConvertToAscii(source); |