comparison Resources/Orthanc/Core/Toolbox.cpp @ 116:a18bfe1fdd62

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jan 2018 10:49:34 +0100
parents a3e8ac8b7256
children 0a1443204818
comparison
equal deleted inserted replaced
115:a51dee6a1515 116:a18bfe1fdd62
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017 Osimis, Belgium 5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 * 6 *
7 * This program is free software: you can redistribute it and/or 7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the 9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version. 10 * License, or (at your option) any later version.
395 } 395 }
396 396
397 #endif 397 #endif
398 398
399 399
400 #if ORTHANC_ENABLE_LOCALE == 1
400 static const char* GetBoostLocaleEncoding(const Encoding sourceEncoding) 401 static const char* GetBoostLocaleEncoding(const Encoding sourceEncoding)
401 { 402 {
402 switch (sourceEncoding) 403 switch (sourceEncoding)
403 { 404 {
404 case Encoding_Utf8: 405 case Encoding_Utf8:
461 462
462 default: 463 default:
463 throw OrthancException(ErrorCode_NotImplemented); 464 throw OrthancException(ErrorCode_NotImplemented);
464 } 465 }
465 } 466 }
467 #endif
466 468
467 469
468 #if ORTHANC_ENABLE_LOCALE == 1 470 #if ORTHANC_ENABLE_LOCALE == 1
469 std::string Toolbox::ConvertToUtf8(const std::string& source, 471 std::string Toolbox::ConvertToUtf8(const std::string& source,
470 Encoding sourceEncoding) 472 Encoding sourceEncoding)
530 { 532 {
531 const uint8_t* p = reinterpret_cast<const uint8_t*>(data); 533 const uint8_t* p = reinterpret_cast<const uint8_t*>(data);
532 534
533 for (size_t i = 0; i < size; i++, p++) 535 for (size_t i = 0; i < size; i++, p++)
534 { 536 {
535 if (*p > 127 || (*p != 0 && iscntrl(*p))) 537 if (*p > 127 || *p == 0 || iscntrl(*p))
536 { 538 {
537 return false; 539 return false;
538 } 540 }
539 } 541 }
540 542
541 return true; 543 return true;
542 } 544 }
543 545
546
547 bool Toolbox::IsAsciiString(const std::string& s)
548 {
549 return IsAsciiString(s.c_str(), s.size());
550 }
551
544 552
545 std::string Toolbox::ConvertToAscii(const std::string& source) 553 std::string Toolbox::ConvertToAscii(const std::string& source)
546 { 554 {
547 std::string result; 555 std::string result;
548 556