comparison Core/Toolbox.cpp @ 2367:2aff870c2c58

refactoring of BoostConfiguration.cmake
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Aug 2017 17:32:13 +0200
parents 56504f89d4ac
children 68380777f9a6
comparison
equal deleted inserted replaced
2366:26f3a346226f 2367:2aff870c2c58
38 #include "Logging.h" 38 #include "Logging.h"
39 39
40 #include <boost/algorithm/string/case_conv.hpp> 40 #include <boost/algorithm/string/case_conv.hpp>
41 #include <boost/algorithm/string/replace.hpp> 41 #include <boost/algorithm/string/replace.hpp>
42 #include <boost/lexical_cast.hpp> 42 #include <boost/lexical_cast.hpp>
43 #include <boost/locale.hpp> 43 #include <boost/regex.hpp>
44 #include <boost/uuid/sha1.hpp> 44 #include <boost/uuid/sha1.hpp>
45 45
46 #include <string> 46 #include <string>
47 #include <stdint.h> 47 #include <stdint.h>
48 #include <string.h> 48 #include <string.h>
49 #include <algorithm> 49 #include <algorithm>
50 #include <ctype.h> 50 #include <ctype.h>
51 51
52 #if BOOST_HAS_REGEX == 1
53 # include <boost/regex.hpp>
54 #endif
55
56 #if BOOST_HAS_LOCALE != 1
57 # error Since version 0.7.6, Orthanc entirely relies on boost::locale
58 #endif
59 52
60 #if ORTHANC_ENABLE_MD5 == 1 53 #if ORTHANC_ENABLE_MD5 == 1
61 # include "../Resources/ThirdParty/md5/md5.h" 54 # include "../Resources/ThirdParty/md5/md5.h"
62 #endif 55 #endif
63 56
64 #if ORTHANC_ENABLE_BASE64 == 1 57 #if ORTHANC_ENABLE_BASE64 == 1
65 # include "../Resources/ThirdParty/base64/base64.h" 58 # include "../Resources/ThirdParty/base64/base64.h"
59 #endif
60
61 #if ORTHANC_ENABLE_LOCALE == 1
62 # include <boost/locale.hpp>
66 #endif 63 #endif
67 64
68 65
69 #if defined(_MSC_VER) && (_MSC_VER < 1800) 66 #if defined(_MSC_VER) && (_MSC_VER < 1800)
70 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013 67 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013
367 364
368 result = base64_decode(data); 365 result = base64_decode(data);
369 } 366 }
370 367
371 368
372 # if BOOST_HAS_REGEX == 1
373 bool Toolbox::DecodeDataUriScheme(std::string& mime, 369 bool Toolbox::DecodeDataUriScheme(std::string& mime,
374 std::string& content, 370 std::string& content,
375 const std::string& source) 371 const std::string& source)
376 { 372 {
377 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)", 373 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)",
387 else 383 else
388 { 384 {
389 return false; 385 return false;
390 } 386 }
391 } 387 }
392 # endif
393 388
394 389
395 void Toolbox::EncodeDataUriScheme(std::string& result, 390 void Toolbox::EncodeDataUriScheme(std::string& result,
396 const std::string& mime, 391 const std::string& mime,
397 const std::string& content) 392 const std::string& content)
468 throw OrthancException(ErrorCode_NotImplemented); 463 throw OrthancException(ErrorCode_NotImplemented);
469 } 464 }
470 } 465 }
471 466
472 467
468 #if ORTHANC_ENABLE_LOCALE == 1
473 std::string Toolbox::ConvertToUtf8(const std::string& source, 469 std::string Toolbox::ConvertToUtf8(const std::string& source,
474 Encoding sourceEncoding) 470 Encoding sourceEncoding)
475 { 471 {
476 if (sourceEncoding == Encoding_Utf8) 472 if (sourceEncoding == Encoding_Utf8)
477 { 473 {
494 { 490 {
495 // Bad input string or bad encoding 491 // Bad input string or bad encoding
496 return ConvertToAscii(source); 492 return ConvertToAscii(source);
497 } 493 }
498 } 494 }
499 495 #endif
500 496
497
498 #if ORTHANC_ENABLE_LOCALE == 1
501 std::string Toolbox::ConvertFromUtf8(const std::string& source, 499 std::string Toolbox::ConvertFromUtf8(const std::string& source,
502 Encoding targetEncoding) 500 Encoding targetEncoding)
503 { 501 {
504 if (targetEncoding == Encoding_Utf8) 502 if (targetEncoding == Encoding_Utf8)
505 { 503 {
522 { 520 {
523 // Bad input string or bad encoding 521 // Bad input string or bad encoding
524 return ConvertToAscii(source); 522 return ConvertToAscii(source);
525 } 523 }
526 } 524 }
525 #endif
527 526
528 527
529 bool Toolbox::IsAsciiString(const void* data, 528 bool Toolbox::IsAsciiString(const void* data,
530 size_t size) 529 size_t size)
531 { 530 {
777 throw OrthancException(ErrorCode_NotImplemented); 776 throw OrthancException(ErrorCode_NotImplemented);
778 } 777 }
779 } 778 }
780 779
781 780
782 #if BOOST_HAS_REGEX == 1
783 std::string Toolbox::WildcardToRegularExpression(const std::string& source) 781 std::string Toolbox::WildcardToRegularExpression(const std::string& source)
784 { 782 {
785 // TODO - Speed up this with a regular expression 783 // TODO - Speed up this with a regular expression
786 784
787 std::string result = source; 785 std::string result = source;
805 boost::replace_all(result, "?", "."); 803 boost::replace_all(result, "?", ".");
806 boost::replace_all(result, "*", ".*"); 804 boost::replace_all(result, "*", ".*");
807 805
808 return result; 806 return result;
809 } 807 }
810 #endif
811
812 808
813 809
814 void Toolbox::TokenizeString(std::vector<std::string>& result, 810 void Toolbox::TokenizeString(std::vector<std::string>& result,
815 const std::string& value, 811 const std::string& value,
816 char separator) 812 char separator)
1252 1248
1253 return IsUuid(str.substr(0, 36)); 1249 return IsUuid(str.substr(0, 36));
1254 } 1250 }
1255 1251
1256 1252
1253 #if ORTHANC_ENABLE_LOCALE == 1
1257 static std::auto_ptr<std::locale> globalLocale_; 1254 static std::auto_ptr<std::locale> globalLocale_;
1258 1255
1259 static bool SetGlobalLocale(const char* locale) 1256 static bool SetGlobalLocale(const char* locale)
1260 { 1257 {
1261 globalLocale_.reset(NULL); 1258 globalLocale_.reset(NULL);
1327 1324
1328 void Toolbox::FinalizeGlobalLocale() 1325 void Toolbox::FinalizeGlobalLocale()
1329 { 1326 {
1330 globalLocale_.reset(); 1327 globalLocale_.reset();
1331 } 1328 }
1329 #endif
1332 1330
1333 1331
1334 std::string Toolbox::ToUpperCaseWithAccents(const std::string& source) 1332 std::string Toolbox::ToUpperCaseWithAccents(const std::string& source)
1335 { 1333 {
1336 if (globalLocale_.get() == NULL) 1334 if (globalLocale_.get() == NULL)