Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Toolbox.cpp @ 4932:b7ce2bb6b881 more-tags
refactored the list of MainDicomTags to be able to change it dynamicaly. Unit tests and Integration tests ok
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 09 Mar 2022 11:17:08 +0100 |
parents | 6eff25f70121 |
children | f630796a59b1 |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1145
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
11 * the License, or (at your option) any later version. |
136 | 12 * |
0 | 13 * This program is distributed in the hope that it will be useful, but |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
16 * Lesser General Public License for more details. |
0 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4055
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
0 | 21 **/ |
22 | |
23 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
24 #include "PrecompiledHeaders.h" |
0 | 25 #include "Toolbox.h" |
26 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 #include "Compatibility.h" |
59 | 28 #include "OrthancException.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1480
diff
changeset
|
29 #include "Logging.h" |
0 | 30 |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
31 #include <json/reader.h> |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
32 #include <json/version.h> |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
33 #include <json/writer.h> |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
34 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
35 #if !defined(JSONCPP_VERSION_MAJOR) || !defined(JSONCPP_VERSION_MINOR) |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
36 # error Cannot access the version of JsonCpp |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
37 #endif |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
38 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
39 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
40 /** |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
41 * We use deprecated "Json::Reader", "Json::StyledWriter" and |
4396 | 42 * "Json::FastWriter" if JsonCpp < 1.7.0. This choice is rather |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
43 * arbitrary, but if Json >= 1.9.0, gcc generates explicit deprecation |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
44 * warnings (clang was warning in earlier versions). For reference, |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
45 * these classes seem to have been deprecated since JsonCpp 1.4.0 (on |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
46 * February 2015) by the following changeset: |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
47 * https://github.com/open-source-parsers/jsoncpp/commit/8df98f6112890d6272734975dd6d70cf8999bb22 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
48 **/ |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
49 #if (JSONCPP_VERSION_MAJOR >= 2 || \ |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
50 (JSONCPP_VERSION_MAJOR == 1 && JSONCPP_VERSION_MINOR >= 8)) |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
51 # define JSONCPP_USE_DEPRECATED 0 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
52 #else |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
53 # define JSONCPP_USE_DEPRECATED 1 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
54 #endif |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
55 |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
56 |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
57 #include <boost/algorithm/string/case_conv.hpp> |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2141
diff
changeset
|
58 #include <boost/algorithm/string/replace.hpp> |
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2141
diff
changeset
|
59 #include <boost/lexical_cast.hpp> |
2931 | 60 #include <boost/regex.hpp> |
61 | |
62 #if BOOST_VERSION >= 106600 | |
63 # include <boost/uuid/detail/sha1.hpp> | |
64 #else | |
65 # include <boost/uuid/sha1.hpp> | |
66 #endif | |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
67 |
1397 | 68 #include <string> |
453 | 69 #include <stdint.h> |
0 | 70 #include <string.h> |
71 #include <algorithm> | |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
72 #include <ctype.h> |
1397 | 73 |
915
703bef350e89
Orthanc now relies entirely on boost::locale
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
74 |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
75 #if ORTHANC_ENABLE_MD5 == 1 |
2931 | 76 // TODO - Could be replaced by <boost/uuid/detail/md5.hpp> starting |
77 // with Boost >= 1.66.0 | |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
78 # include "../Resources/ThirdParty/md5/md5.h" |
1479
8f28a1cd2354
possibility to disable md5 and base64 support in the toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
79 #endif |
8f28a1cd2354
possibility to disable md5 and base64 support in the toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
80 |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
81 #if ORTHANC_ENABLE_BASE64 == 1 |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
82 # include "../Resources/ThirdParty/base64/base64.h" |
1479
8f28a1cd2354
possibility to disable md5 and base64 support in the toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
83 #endif |
0 | 84 |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
85 #if ORTHANC_ENABLE_LOCALE == 1 |
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
86 # include <boost/locale.hpp> |
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
87 #endif |
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
88 |
2677
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
89 #if ORTHANC_ENABLE_SSL == 1 |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
90 // For OpenSSL initialization and finalization |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
91 # include <openssl/conf.h> |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
92 # include <openssl/engine.h> |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
93 # include <openssl/err.h> |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
94 # include <openssl/evp.h> |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
95 # include <openssl/ssl.h> |
4741
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4706
diff
changeset
|
96 |
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4706
diff
changeset
|
97 # if OPENSSL_VERSION_NUMBER < 0x30000000L |
4892
6eff25f70121
integration mainline->openssl-3.x
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
98 # warning You are linking Orthanc against OpenSSL 1.x, whose license is incompatible with the GPLv3+ used by Orthanc >= 1.10.0. Please update to OpenSSL 3.x, that uses the Apache 2 license. |
4741
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4706
diff
changeset
|
99 # endif |
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4706
diff
changeset
|
100 |
2677
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
101 #endif |
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
102 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
103 |
1111
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1103
diff
changeset
|
104 #if defined(_MSC_VER) && (_MSC_VER < 1800) |
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1103
diff
changeset
|
105 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio < 2013 |
570 | 106 extern "C" |
107 { | |
915
703bef350e89
Orthanc now relies entirely on boost::locale
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
108 int64_t _strtoi64(const char *nptr, char **endptr, int base); |
703bef350e89
Orthanc now relies entirely on boost::locale
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
109 int64_t strtoll(const char *nptr, char **endptr, int base) |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
110 { |
915
703bef350e89
Orthanc now relies entirely on boost::locale
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
111 return _strtoi64(nptr, endptr, base); |
703bef350e89
Orthanc now relies entirely on boost::locale
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
112 } |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
113 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
114 #endif |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
115 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
116 |
2173 | 117 #if defined(_WIN32) |
118 # include <windows.h> // For ::Sleep | |
119 #endif | |
120 | |
2141 | 121 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
122 #if ORTHANC_ENABLE_PUGIXML == 1 |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2141
diff
changeset
|
123 # include "ChunkedBuffer.h" |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
124 #endif |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
125 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
126 |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
127 // Inclusions for UUID |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
128 // http://stackoverflow.com/a/1626302 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
129 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
130 extern "C" |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
131 { |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
132 #if defined(_WIN32) |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
133 # include <rpc.h> |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
134 #else |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
135 # include <uuid/uuid.h> |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
136 #endif |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
137 } |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
138 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
139 |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
140 #if defined(ORTHANC_STATIC_ICU) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
141 # if (ORTHANC_STATIC_ICU == 1 && ORTHANC_ENABLE_LOCALE == 1) |
4032
058b5ade8acd
renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
142 # include <OrthancFrameworkResources.h> |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
143 # include <unicode/udata.h> |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
144 # include <unicode/uloc.h> |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
145 # include "Compression/GzipCompressor.h" |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
146 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
147 static std::string globalIcuData_; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
148 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
149 extern "C" |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
150 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
151 // This is dummy content for the "icudt58_dat" (resp. "icudt63_dat") |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
152 // global variable from the autogenerated "icudt58l_dat.c" |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
153 // (resp. "icudt63l_dat.c") file that contains a huge C array. In |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
154 // Orthanc, this array is compressed using gzip and attached as a |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
155 // resource, then uncompressed during the launch of Orthanc by |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
156 // static function "InitializeIcu()". |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
157 struct |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
158 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
159 double bogus; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
160 uint8_t *bytes; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
161 } U_ICUDATA_ENTRY_POINT = { 0.0, NULL }; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
162 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
163 |
3462
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
164 # if defined(__LSB_VERSION__) |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
165 extern "C" |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
166 { |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
167 /** |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
168 * The "tzname" global variable is declared as "extern" but is not |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
169 * defined in any compilation module, if using Linux Standard Base, |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
170 * as soon as OpenSSL or cURL is in use on Ubuntu >= 18.04 (glibc >= |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
171 * 2.27). The variable "__tzname" is always properly declared *and* |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
172 * defined. The reason is unclear, and is maybe a bug in the gcc 4.8 |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
173 * linker that is used by LSB if facing a weak symbol (as "tzname"). |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
174 * This makes Orthanc crash if the timezone is set to UTC. |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
175 * https://groups.google.com/d/msg/orthanc-users/0m8sxxwSm1E/2p8du_89CAAJ |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
176 **/ |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
177 char *tzname[2] = { (char *) "GMT", (char *) "GMT" }; |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
178 } |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
179 # endif |
7d72e43f4a2d
attempt to fix LSB on Ubuntu 18.04
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3459
diff
changeset
|
180 |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
181 # endif |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
182 #endif |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
183 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
184 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
185 |
3459
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
186 #if defined(__unix__) && ORTHANC_SANDBOXED != 1 |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
187 # include "SystemToolbox.h" // Check out "InitializeGlobalLocale()" |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
188 #endif |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
189 |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
190 |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
191 |
59 | 192 namespace Orthanc |
0 | 193 { |
2513
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
194 void Toolbox::LinesIterator::FindEndOfLine() |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
195 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
196 lineEnd_ = lineStart_; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
197 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
198 while (lineEnd_ < content_.size() && |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
199 content_[lineEnd_] != '\n' && |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
200 content_[lineEnd_] != '\r') |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
201 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
202 lineEnd_ += 1; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
203 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
204 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
205 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
206 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
207 Toolbox::LinesIterator::LinesIterator(const std::string& content) : |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
208 content_(content), |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
209 lineStart_(0) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
210 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
211 FindEndOfLine(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
212 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
213 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
214 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
215 bool Toolbox::LinesIterator::GetLine(std::string& target) const |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
216 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
217 assert(lineStart_ <= content_.size() && |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
218 lineEnd_ <= content_.size() && |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
219 lineStart_ <= lineEnd_); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
220 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
221 if (lineStart_ == content_.size()) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
222 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
223 return false; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
224 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
225 else |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
226 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
227 target = content_.substr(lineStart_, lineEnd_ - lineStart_); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
228 return true; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
229 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
230 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
231 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
232 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
233 void Toolbox::LinesIterator::Next() |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
234 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
235 lineStart_ = lineEnd_; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
236 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
237 if (lineStart_ != content_.size()) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
238 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
239 assert(content_[lineStart_] == '\r' || |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
240 content_[lineStart_] == '\n'); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
241 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
242 char second; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
243 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
244 if (content_[lineStart_] == '\r') |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
245 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
246 second = '\n'; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
247 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
248 else |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
249 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
250 second = '\r'; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
251 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
252 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
253 lineStart_ += 1; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
254 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
255 if (lineStart_ < content_.size() && |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
256 content_[lineStart_] == second) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
257 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
258 lineStart_ += 1; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
259 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
260 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
261 FindEndOfLine(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
262 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
263 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
264 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
265 |
0 | 266 void Toolbox::ToUpperCase(std::string& s) |
267 { | |
268 std::transform(s.begin(), s.end(), s.begin(), toupper); | |
269 } | |
270 | |
271 | |
272 void Toolbox::ToLowerCase(std::string& s) | |
273 { | |
274 std::transform(s.begin(), s.end(), s.begin(), tolower); | |
275 } | |
276 | |
277 | |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
278 void Toolbox::ToUpperCase(std::string& result, |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
279 const std::string& source) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
280 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
281 result = source; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
282 ToUpperCase(result); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
283 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
284 |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
285 void Toolbox::ToLowerCase(std::string& result, |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
286 const std::string& source) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
287 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
288 result = source; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
289 ToLowerCase(result); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
290 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
291 |
0 | 292 |
293 void Toolbox::SplitUriComponents(UriComponents& components, | |
294 const std::string& uri) | |
295 { | |
296 static const char URI_SEPARATOR = '/'; | |
297 | |
298 components.clear(); | |
299 | |
300 if (uri.size() == 0 || | |
301 uri[0] != URI_SEPARATOR) | |
302 { | |
59 | 303 throw OrthancException(ErrorCode_UriSyntax); |
0 | 304 } |
305 | |
306 // Count the number of slashes in the URI to make an assumption | |
307 // about the number of components in the URI | |
308 unsigned int estimatedSize = 0; | |
309 for (unsigned int i = 0; i < uri.size(); i++) | |
310 { | |
311 if (uri[i] == URI_SEPARATOR) | |
312 estimatedSize++; | |
313 } | |
314 | |
315 components.reserve(estimatedSize - 1); | |
316 | |
317 unsigned int start = 1; | |
318 unsigned int end = 1; | |
319 while (end < uri.size()) | |
320 { | |
321 // This is the loop invariant | |
322 assert(uri[start - 1] == '/' && (end >= start)); | |
323 | |
324 if (uri[end] == '/') | |
325 { | |
326 components.push_back(std::string(&uri[start], end - start)); | |
327 end++; | |
328 start = end; | |
329 } | |
330 else | |
331 { | |
332 end++; | |
333 } | |
334 } | |
335 | |
336 if (start < uri.size()) | |
337 { | |
338 components.push_back(std::string(&uri[start], end - start)); | |
339 } | |
207 | 340 |
341 for (size_t i = 0; i < components.size(); i++) | |
342 { | |
343 if (components[i].size() == 0) | |
344 { | |
345 // Empty component, as in: "/coucou//e" | |
346 throw OrthancException(ErrorCode_UriSyntax); | |
347 } | |
348 } | |
0 | 349 } |
350 | |
351 | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
352 void Toolbox::TruncateUri(UriComponents& target, |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
353 const UriComponents& source, |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
354 size_t fromLevel) |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
355 { |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
356 target.clear(); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
357 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
358 if (source.size() > fromLevel) |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
359 { |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
360 target.resize(source.size() - fromLevel); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
361 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
362 size_t j = 0; |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
363 for (size_t i = fromLevel; i < source.size(); i++, j++) |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
364 { |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
365 target[j] = source[i]; |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
366 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
367 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
368 assert(j == target.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
369 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
370 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
371 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
372 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
957
diff
changeset
|
373 |
0 | 374 bool Toolbox::IsChildUri(const UriComponents& baseUri, |
375 const UriComponents& testedUri) | |
376 { | |
377 if (testedUri.size() < baseUri.size()) | |
378 { | |
379 return false; | |
380 } | |
381 | |
382 for (size_t i = 0; i < baseUri.size(); i++) | |
383 { | |
384 if (baseUri[i] != testedUri[i]) | |
385 return false; | |
386 } | |
387 | |
388 return true; | |
389 } | |
390 | |
391 | |
392 std::string Toolbox::FlattenUri(const UriComponents& components, | |
393 size_t fromLevel) | |
394 { | |
395 if (components.size() <= fromLevel) | |
396 { | |
397 return "/"; | |
398 } | |
399 else | |
400 { | |
401 std::string r; | |
402 | |
403 for (size_t i = fromLevel; i < components.size(); i++) | |
404 { | |
405 r += "/" + components[i]; | |
406 } | |
407 | |
408 return r; | |
409 } | |
410 } | |
411 | |
412 | |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
413 #if ORTHANC_ENABLE_MD5 == 1 |
22 | 414 static char GetHexadecimalCharacter(uint8_t value) |
415 { | |
416 assert(value < 16); | |
417 | |
418 if (value < 10) | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
419 { |
22 | 420 return value + '0'; |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
421 } |
22 | 422 else |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
423 { |
22 | 424 return (value - 10) + 'a'; |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
425 } |
22 | 426 } |
427 | |
23 | 428 |
22 | 429 void Toolbox::ComputeMD5(std::string& result, |
430 const std::string& data) | |
431 { | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
432 if (data.size() > 0) |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
433 { |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
434 ComputeMD5(result, &data[0], data.size()); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
435 } |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
436 else |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
437 { |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
438 ComputeMD5(result, NULL, 0); |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
439 } |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
440 } |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
441 |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
442 |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
443 void Toolbox::ComputeMD5(std::string& result, |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
444 const void* data, |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
445 size_t size) |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
446 { |
22 | 447 md5_state_s state; |
448 md5_init(&state); | |
449 | |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
450 if (size > 0) |
22 | 451 { |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
452 md5_append(&state, |
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
453 reinterpret_cast<const md5_byte_t*>(data), |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
454 static_cast<int>(size)); |
22 | 455 } |
456 | |
457 md5_byte_t actualHash[16]; | |
458 md5_finish(&state, actualHash); | |
459 | |
460 result.resize(32); | |
461 for (unsigned int i = 0; i < 16; i++) | |
462 { | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
463 result[2 * i] = GetHexadecimalCharacter(static_cast<uint8_t>(actualHash[i] / 16)); |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
464 result[2 * i + 1] = GetHexadecimalCharacter(static_cast<uint8_t>(actualHash[i] % 16)); |
22 | 465 } |
466 } | |
1479
8f28a1cd2354
possibility to disable md5 and base64 support in the toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
467 #endif |
24 | 468 |
469 | |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
470 #if ORTHANC_ENABLE_BASE64 == 1 |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
471 void Toolbox::EncodeBase64(std::string& result, |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
472 const std::string& data) |
24 | 473 { |
3326
b21d4cc8e5d1
speed up base64 decoding + added tests
Alain Mazy <alain@mazy.be>
parents:
3325
diff
changeset
|
474 result.clear(); |
3325
2e7c5c15ba25
reserve size for base64 decoding + avoid copy. In a test in WASM, encoding 3MB took 110ms instead of 1400ms previously
Alain Mazy <alain@mazy.be>
parents:
3322
diff
changeset
|
475 base64_encode(result, data); |
24 | 476 } |
477 | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
478 void Toolbox::DecodeBase64(std::string& result, |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
479 const std::string& data) |
365 | 480 { |
1988
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
481 for (size_t i = 0; i < data.length(); i++) |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
482 { |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
483 if (!isalnum(data[i]) && |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
484 data[i] != '+' && |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
485 data[i] != '/' && |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
486 data[i] != '=') |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
487 { |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
488 // This is not a valid character for a Base64 string |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
489 throw OrthancException(ErrorCode_BadFileFormat); |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
490 } |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
491 } |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1981
diff
changeset
|
492 |
3326
b21d4cc8e5d1
speed up base64 decoding + added tests
Alain Mazy <alain@mazy.be>
parents:
3325
diff
changeset
|
493 result.clear(); |
3325
2e7c5c15ba25
reserve size for base64 decoding + avoid copy. In a test in WASM, encoding 3MB took 110ms instead of 1400ms previously
Alain Mazy <alain@mazy.be>
parents:
3322
diff
changeset
|
494 base64_decode(result, data); |
365 | 495 } |
1648 | 496 |
497 | |
1981
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
498 bool Toolbox::DecodeDataUriScheme(std::string& mime, |
1648 | 499 std::string& content, |
500 const std::string& source) | |
501 { | |
502 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)", | |
503 boost::regex::icase /* case insensitive search */); | |
504 | |
505 boost::cmatch what; | |
506 if (regex_match(source.c_str(), what, pattern)) | |
507 { | |
508 mime = what[1]; | |
509 DecodeBase64(content, what[2]); | |
1981
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
510 return true; |
1648 | 511 } |
512 else | |
513 { | |
1981
4b545a8b1f95
return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
514 return false; |
1648 | 515 } |
516 } | |
517 | |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
518 |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
519 void Toolbox::EncodeDataUriScheme(std::string& result, |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
520 const std::string& mime, |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
521 const std::string& content) |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
522 { |
3325
2e7c5c15ba25
reserve size for base64 decoding + avoid copy. In a test in WASM, encoding 3MB took 110ms instead of 1400ms previously
Alain Mazy <alain@mazy.be>
parents:
3322
diff
changeset
|
523 result = "data:" + mime + ";base64,"; |
2e7c5c15ba25
reserve size for base64 decoding + avoid copy. In a test in WASM, encoding 3MB took 110ms instead of 1400ms previously
Alain Mazy <alain@mazy.be>
parents:
3322
diff
changeset
|
524 base64_encode(result, content); |
1818
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
525 } |
1065401501fb
ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1767
diff
changeset
|
526 |
1479
8f28a1cd2354
possibility to disable md5 and base64 support in the toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
527 #endif |
8f28a1cd2354
possibility to disable md5 and base64 support in the toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
528 |
365 | 529 |
2412
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2373
diff
changeset
|
530 #if ORTHANC_ENABLE_LOCALE == 1 |
1557 | 531 static const char* GetBoostLocaleEncoding(const Encoding sourceEncoding) |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
532 { |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
533 switch (sourceEncoding) |
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
534 { |
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
535 case Encoding_Utf8: |
1557 | 536 return "UTF-8"; |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
537 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
950
diff
changeset
|
538 case Encoding_Ascii: |
1557 | 539 return "ASCII"; |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
950
diff
changeset
|
540 |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
541 case Encoding_Latin1: |
1557 | 542 return "ISO-8859-1"; |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
543 |
1087 | 544 case Encoding_Latin2: |
1557 | 545 return "ISO-8859-2"; |
1087 | 546 |
547 case Encoding_Latin3: | |
1557 | 548 return "ISO-8859-3"; |
1087 | 549 |
550 case Encoding_Latin4: | |
1557 | 551 return "ISO-8859-4"; |
1087 | 552 |
553 case Encoding_Latin5: | |
1557 | 554 return "ISO-8859-9"; |
1087 | 555 |
556 case Encoding_Cyrillic: | |
1557 | 557 return "ISO-8859-5"; |
1087 | 558 |
1347 | 559 case Encoding_Windows1251: |
1557 | 560 return "WINDOWS-1251"; |
1347 | 561 |
1087 | 562 case Encoding_Arabic: |
1557 | 563 return "ISO-8859-6"; |
1087 | 564 |
565 case Encoding_Greek: | |
1557 | 566 return "ISO-8859-7"; |
1087 | 567 |
568 case Encoding_Hebrew: | |
1557 | 569 return "ISO-8859-8"; |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
570 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
571 case Encoding_Japanese: |
1557 | 572 return "SHIFT-JIS"; |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
573 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
574 case Encoding_Chinese: |
1557 | 575 return "GB18030"; |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
576 |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
577 case Encoding_Thai: |
3230
4b042ec734c1
dynamic linking against libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
578 #if BOOST_LOCALE_WITH_ICU == 1 |
4b042ec734c1
dynamic linking against libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
579 return "tis620.2533"; |
4b042ec734c1
dynamic linking against libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
580 #else |
1557 | 581 return "TIS620.2533-0"; |
3230
4b042ec734c1
dynamic linking against libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
582 #endif |
1087 | 583 |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
584 case Encoding_Korean: |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
585 return "ISO-IR-149"; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
586 |
3218 | 587 case Encoding_JapaneseKanji: |
588 return "JIS"; | |
589 | |
3226
45e1631febbb
support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3221
diff
changeset
|
590 case Encoding_SimplifiedChinese: |
45e1631febbb
support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3221
diff
changeset
|
591 return "GB2312"; |
45e1631febbb
support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3221
diff
changeset
|
592 |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
593 default: |
957
63973b76a51f
detection of encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
956
diff
changeset
|
594 throw OrthancException(ErrorCode_NotImplemented); |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
595 } |
1557 | 596 } |
2412
cad393b41bc3
handy shortcuts in DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2373
diff
changeset
|
597 #endif |
1557 | 598 |
599 | |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
600 #if ORTHANC_ENABLE_LOCALE == 1 |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
601 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.12.html#sect_C.12.1.1.2 |
1557 | 602 std::string Toolbox::ConvertToUtf8(const std::string& source, |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
603 Encoding sourceEncoding, |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
604 bool hasCodeExtensions) |
1557 | 605 { |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
606 #if ORTHANC_STATIC_ICU == 1 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
607 if (globalIcuData_.empty()) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
608 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
609 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
610 "Call Toolbox::InitializeGlobalLocale()"); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
611 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
612 #endif |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
613 |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
614 // The "::skip" flag makes boost skip invalid UTF-8 |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
615 // characters. This can occur in badly-encoded DICOM files. |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
616 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
617 try |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
618 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
619 if (sourceEncoding == Encoding_Ascii) |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
620 { |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
621 return ConvertToAscii(source); |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
622 } |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
623 else |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
624 { |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
625 std::string s; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
626 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
627 if (sourceEncoding == Encoding_Utf8) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
628 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
629 // Already in UTF-8: No conversion is required, but we ensure |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
630 // the output is correctly encoded |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
631 s = boost::locale::conv::utf_to_utf<char>(source, boost::locale::conv::skip); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
632 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
633 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
634 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
635 const char* encoding = GetBoostLocaleEncoding(sourceEncoding); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
636 s = boost::locale::conv::to_utf<char>(source, encoding, boost::locale::conv::skip); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
637 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
638 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
639 if (hasCodeExtensions) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
640 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
641 std::string t; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
642 RemoveIso2022EscapeSequences(t, s); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
643 return t; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
644 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
645 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
646 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
647 return s; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
648 } |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
649 } |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
650 } |
3218 | 651 catch (std::runtime_error& e) |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
652 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
653 // Bad input string or bad encoding |
3218 | 654 LOG(INFO) << e.what(); |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
655 return ConvertToAscii(source); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
656 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
657 } |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
658 #endif |
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
659 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
660 |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
661 #if ORTHANC_ENABLE_LOCALE == 1 |
1557 | 662 std::string Toolbox::ConvertFromUtf8(const std::string& source, |
663 Encoding targetEncoding) | |
664 { | |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
665 #if ORTHANC_STATIC_ICU == 1 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
666 if (globalIcuData_.empty()) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
667 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
668 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
669 "Call Toolbox::InitializeGlobalLocale()"); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
670 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
671 #endif |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
672 |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
673 // The "::skip" flag makes boost skip invalid UTF-8 |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
674 // characters. This can occur in badly-encoded DICOM files. |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
675 |
1557 | 676 try |
677 { | |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
678 if (targetEncoding == Encoding_Utf8) |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
679 { |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
680 // Already in UTF-8: No conversion is required. |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
681 return boost::locale::conv::utf_to_utf<char>(source, boost::locale::conv::skip); |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
682 } |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
683 else if (targetEncoding == Encoding_Ascii) |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
684 { |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
685 return ConvertToAscii(source); |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
686 } |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
687 else |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
688 { |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
689 const char* encoding = GetBoostLocaleEncoding(targetEncoding); |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
690 return boost::locale::conv::from_utf<char>(source, encoding, boost::locale::conv::skip); |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
691 } |
1557 | 692 } |
693 catch (std::runtime_error&) | |
694 { | |
695 // Bad input string or bad encoding | |
696 return ConvertToAscii(source); | |
697 } | |
698 } | |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
699 #endif |
1557 | 700 |
701 | |
2900 | 702 static bool IsAsciiCharacter(uint8_t c) |
703 { | |
704 return (c != 0 && | |
705 c <= 127 && | |
706 (c == '\n' || !iscntrl(c))); | |
707 } | |
708 | |
709 | |
2129
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
710 bool Toolbox::IsAsciiString(const void* data, |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
711 size_t size) |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
712 { |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
713 const uint8_t* p = reinterpret_cast<const uint8_t*>(data); |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
714 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
715 for (size_t i = 0; i < size; i++, p++) |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
716 { |
2900 | 717 if (!IsAsciiCharacter(*p)) |
2129
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
718 { |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
719 return false; |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
720 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
721 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
722 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
723 return true; |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
724 } |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
725 |
0c09d1af22f3
"/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2087
diff
changeset
|
726 |
2442
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2412
diff
changeset
|
727 bool Toolbox::IsAsciiString(const std::string& s) |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2412
diff
changeset
|
728 { |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2412
diff
changeset
|
729 return IsAsciiString(s.c_str(), s.size()); |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2412
diff
changeset
|
730 } |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2412
diff
changeset
|
731 |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2412
diff
changeset
|
732 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
733 std::string Toolbox::ConvertToAscii(const std::string& source) |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
734 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
735 std::string result; |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
736 |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
930
diff
changeset
|
737 result.reserve(source.size() + 1); |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
738 for (size_t i = 0; i < source.size(); i++) |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
739 { |
2900 | 740 if (IsAsciiCharacter(source[i])) |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
741 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
742 result.push_back(source[i]); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
743 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
744 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
745 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
746 return result; |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
747 } |
177 | 748 |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
749 |
177 | 750 void Toolbox::ComputeSHA1(std::string& result, |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
751 const void* data, |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
752 size_t size) |
177 | 753 { |
560
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
754 boost::uuids::detail::sha1 sha1; |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
755 |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
756 if (size > 0) |
177 | 757 { |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
758 sha1.process_bytes(data, size); |
177 | 759 } |
760 | |
560
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
761 unsigned int digest[5]; |
177 | 762 |
763 // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide | |
560
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
764 assert(sizeof(unsigned int) == 4 && sizeof(digest) == (160 / 8)); |
177 | 765 |
560
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
766 sha1.get_digest(digest); |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
767 |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
768 result.resize(8 * 5 + 4); |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
769 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
770 digest[0], |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
771 digest[1], |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
772 digest[2], |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
773 digest[3], |
69c024f9c06b
fix of Debian bug #724947
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
483
diff
changeset
|
774 digest[4]); |
177 | 775 } |
776 | |
1833
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
777 void Toolbox::ComputeSHA1(std::string& result, |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
778 const std::string& data) |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
779 { |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
780 if (data.size() > 0) |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
781 { |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
782 ComputeSHA1(result, data.c_str(), data.size()); |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
783 } |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
784 else |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
785 { |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
786 ComputeSHA1(result, NULL, 0); |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
787 } |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
788 } |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
789 |
47d032c48818
"OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1818
diff
changeset
|
790 |
3401 | 791 bool Toolbox::IsSHA1(const void* str, |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
792 size_t size) |
402 | 793 { |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
794 if (size == 0) |
1428 | 795 { |
796 return false; | |
797 } | |
798 | |
3401 | 799 const char* start = reinterpret_cast<const char*>(str); |
800 const char* end = start + size; | |
1428 | 801 |
802 // Trim the beginning of the string | |
803 while (start < end) | |
804 { | |
805 if (*start == '\0' || | |
806 isspace(*start)) | |
807 { | |
808 start++; | |
809 } | |
810 else | |
811 { | |
812 break; | |
813 } | |
814 } | |
815 | |
816 // Trim the trailing of the string | |
817 while (start < end) | |
818 { | |
819 if (*(end - 1) == '\0' || | |
820 isspace(*(end - 1))) | |
821 { | |
822 end--; | |
823 } | |
824 else | |
825 { | |
826 break; | |
827 } | |
828 } | |
829 | |
830 if (end - start != 44) | |
402 | 831 { |
832 return false; | |
833 } | |
834 | |
835 for (unsigned int i = 0; i < 44; i++) | |
836 { | |
837 if (i == 8 || | |
838 i == 17 || | |
839 i == 26 || | |
840 i == 35) | |
841 { | |
1428 | 842 if (start[i] != '-') |
402 | 843 return false; |
844 } | |
845 else | |
846 { | |
1428 | 847 if (!isalnum(start[i])) |
402 | 848 return false; |
849 } | |
850 } | |
851 | |
852 return true; | |
853 } | |
854 | |
1397 | 855 |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
856 bool Toolbox::IsSHA1(const std::string& s) |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
857 { |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
858 if (s.size() == 0) |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
859 { |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
860 return false; |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
861 } |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
862 else |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
863 { |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
864 return IsSHA1(s.c_str(), s.size()); |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
865 } |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
866 } |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
867 |
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
868 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
869 std::string Toolbox::StripSpaces(const std::string& source) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
870 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
871 size_t first = 0; |
177 | 872 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
873 while (first < source.length() && |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
874 isspace(source[first])) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
875 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
876 first++; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
877 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
878 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
879 if (first == source.length()) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
880 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
881 // String containing only spaces |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
882 return ""; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
883 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
884 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
885 size_t last = source.length(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
886 while (last > first && |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
887 isspace(source[last - 1])) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
888 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
889 last--; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
890 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
891 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
892 assert(first <= last); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
893 return source.substr(first, last - first); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
894 } |
336 | 895 |
896 | |
337 | 897 static char Hex2Dec(char c) |
336 | 898 { |
899 return ((c >= '0' && c <= '9') ? c - '0' : | |
900 ((c >= 'a' && c <= 'f') ? c - 'a' + 10 : c - 'A' + 10)); | |
901 } | |
902 | |
903 void Toolbox::UrlDecode(std::string& s) | |
904 { | |
905 // http://en.wikipedia.org/wiki/Percent-encoding | |
906 // http://www.w3schools.com/tags/ref_urlencode.asp | |
907 // http://stackoverflow.com/questions/154536/encode-decode-urls-in-c | |
908 | |
909 if (s.size() == 0) | |
910 { | |
911 return; | |
912 } | |
913 | |
914 size_t source = 0; | |
915 size_t target = 0; | |
916 | |
917 while (source < s.size()) | |
918 { | |
919 if (s[source] == '%' && | |
920 source + 2 < s.size() && | |
921 isalnum(s[source + 1]) && | |
922 isalnum(s[source + 2])) | |
923 { | |
924 s[target] = (Hex2Dec(s[source + 1]) << 4) | Hex2Dec(s[source + 2]); | |
925 source += 3; | |
926 target += 1; | |
927 } | |
928 else | |
929 { | |
930 if (s[source] == '+') | |
931 s[target] = ' '; | |
932 else | |
933 s[target] = s[source]; | |
934 | |
935 source++; | |
936 target++; | |
937 } | |
938 } | |
939 | |
940 s.resize(target); | |
941 } | |
453 | 942 |
943 | |
944 Endianness Toolbox::DetectEndianness() | |
945 { | |
946 // http://sourceforge.net/p/predef/wiki/Endianness/ | |
947 | |
4203
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
948 uint32_t bufferView = 0; |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3462
diff
changeset
|
949 |
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3462
diff
changeset
|
950 uint8_t* buffer = reinterpret_cast<uint8_t*>(&bufferView); |
453 | 951 |
952 buffer[0] = 0x00; | |
953 buffer[1] = 0x01; | |
954 buffer[2] = 0x02; | |
955 buffer[3] = 0x03; | |
956 | |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3462
diff
changeset
|
957 switch (bufferView) |
453 | 958 { |
959 case 0x00010203: | |
960 return Endianness_Big; | |
961 | |
962 case 0x03020100: | |
963 return Endianness_Little; | |
964 | |
965 default: | |
966 throw OrthancException(ErrorCode_NotImplemented); | |
967 } | |
968 } | |
608 | 969 |
970 std::string Toolbox::WildcardToRegularExpression(const std::string& source) | |
971 { | |
972 // TODO - Speed up this with a regular expression | |
973 | |
974 std::string result = source; | |
975 | |
976 // Escape all special characters | |
977 boost::replace_all(result, "\\", "\\\\"); | |
978 boost::replace_all(result, "^", "\\^"); | |
979 boost::replace_all(result, ".", "\\."); | |
980 boost::replace_all(result, "$", "\\$"); | |
981 boost::replace_all(result, "|", "\\|"); | |
982 boost::replace_all(result, "(", "\\("); | |
983 boost::replace_all(result, ")", "\\)"); | |
984 boost::replace_all(result, "[", "\\["); | |
985 boost::replace_all(result, "]", "\\]"); | |
986 boost::replace_all(result, "+", "\\+"); | |
987 boost::replace_all(result, "/", "\\/"); | |
988 boost::replace_all(result, "{", "\\{"); | |
989 boost::replace_all(result, "}", "\\}"); | |
990 | |
991 // Convert wildcards '*' and '?' to their regex equivalents | |
992 boost::replace_all(result, "?", "."); | |
993 boost::replace_all(result, "*", ".*"); | |
994 | |
995 return result; | |
996 } | |
997 | |
998 | |
999 void Toolbox::TokenizeString(std::vector<std::string>& result, | |
1000 const std::string& value, | |
1001 char separator) | |
1002 { | |
3382
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1003 size_t countSeparators = 0; |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1004 |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1005 for (size_t i = 0; i < value.size(); i++) |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1006 { |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1007 if (value[i] == separator) |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1008 { |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1009 countSeparators++; |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1010 } |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1011 } |
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1012 |
608 | 1013 result.clear(); |
3382
a2862d4484f5
optimization of Toolbox::TokenizeString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3333
diff
changeset
|
1014 result.reserve(countSeparators + 1); |
608 | 1015 |
1016 std::string currentItem; | |
1017 | |
1018 for (size_t i = 0; i < value.size(); i++) | |
1019 { | |
1020 if (value[i] == separator) | |
1021 { | |
1022 result.push_back(currentItem); | |
1023 currentItem.clear(); | |
1024 } | |
1025 else | |
1026 { | |
1027 currentItem.push_back(value[i]); | |
1028 } | |
1029 } | |
1030 | |
1031 result.push_back(currentItem); | |
1032 } | |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
1033 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
1034 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2129
diff
changeset
|
1035 #if ORTHANC_ENABLE_PUGIXML == 1 |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1036 class ChunkedBufferWriter : public pugi::xml_writer |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1037 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1038 private: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1039 ChunkedBuffer buffer_; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1040 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1041 public: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1042 virtual void write(const void *data, size_t size) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1043 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1044 if (size > 0) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1045 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1046 buffer_.AddChunk(reinterpret_cast<const char*>(data), size); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1047 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1048 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1049 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1050 void Flatten(std::string& s) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1051 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1052 buffer_.Flatten(s); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1053 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1054 }; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1055 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1056 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1057 static void JsonToXmlInternal(pugi::xml_node& target, |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1058 const Json::Value& source, |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1059 const std::string& arrayElement) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1060 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1061 // http://jsoncpp.sourceforge.net/value_8h_source.html#l00030 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1062 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1063 switch (source.type()) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1064 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1065 case Json::nullValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1066 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1067 target.append_child(pugi::node_pcdata).set_value("null"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1068 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1069 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1070 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1071 case Json::intValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1072 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1073 std::string s = boost::lexical_cast<std::string>(source.asInt()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1074 target.append_child(pugi::node_pcdata).set_value(s.c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1075 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1076 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1077 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1078 case Json::uintValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1079 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1080 std::string s = boost::lexical_cast<std::string>(source.asUInt()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1081 target.append_child(pugi::node_pcdata).set_value(s.c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1082 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1083 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1084 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1085 case Json::realValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1086 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1087 std::string s = boost::lexical_cast<std::string>(source.asFloat()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1088 target.append_child(pugi::node_pcdata).set_value(s.c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1089 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1090 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1091 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1092 case Json::stringValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1093 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1094 target.append_child(pugi::node_pcdata).set_value(source.asString().c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1095 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1096 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1097 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1098 case Json::booleanValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1099 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1100 target.append_child(pugi::node_pcdata).set_value(source.asBool() ? "true" : "false"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1101 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1102 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1103 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1104 case Json::arrayValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1105 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1106 for (Json::Value::ArrayIndex i = 0; i < source.size(); i++) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1107 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1108 pugi::xml_node node = target.append_child(); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1109 node.set_name(arrayElement.c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1110 JsonToXmlInternal(node, source[i], arrayElement); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1111 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1112 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1113 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1114 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1115 case Json::objectValue: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1116 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1117 Json::Value::Members members = source.getMemberNames(); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1118 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1119 for (size_t i = 0; i < members.size(); i++) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1120 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1121 pugi::xml_node node = target.append_child(); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1122 node.set_name(members[i].c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1123 JsonToXmlInternal(node, source[members[i]], arrayElement); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1124 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1125 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1126 break; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1127 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1128 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1129 default: |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1130 throw OrthancException(ErrorCode_NotImplemented); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1131 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1132 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1133 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1134 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1135 void Toolbox::JsonToXml(std::string& target, |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1136 const Json::Value& source, |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1137 const std::string& rootElement, |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1138 const std::string& arrayElement) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1139 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1140 pugi::xml_document doc; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1141 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1142 pugi::xml_node n = doc.append_child(rootElement.c_str()); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1143 JsonToXmlInternal(n, source, arrayElement); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1144 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1145 pugi::xml_node decl = doc.prepend_child(pugi::node_declaration); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1146 decl.append_attribute("version").set_value("1.0"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1147 decl.append_attribute("encoding").set_value("utf-8"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1148 |
3203
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1149 XmlToString(target, doc); |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1150 } |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1151 |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1152 void Toolbox::XmlToString(std::string& target, |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1153 const pugi::xml_document& source) |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1154 { |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1155 ChunkedBufferWriter writer; |
3203
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1156 source.save(writer, " ", pugi::format_default, pugi::encoding_utf8); |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1157 writer.Flatten(target); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1158 } |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1159 #endif |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1160 |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1161 |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1162 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1163 bool Toolbox::IsInteger(const std::string& str) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1164 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1165 std::string s = StripSpaces(str); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1166 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1167 if (s.size() == 0) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1168 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1169 return false; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1170 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1171 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1172 size_t pos = 0; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1173 if (s[0] == '-') |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1174 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1175 if (s.size() == 1) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1176 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1177 return false; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1178 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1179 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1180 pos = 1; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1181 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1182 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1183 while (pos < s.size()) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1184 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1185 if (!isdigit(s[pos])) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1186 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1187 return false; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1188 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1189 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1190 pos++; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1191 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1192 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1193 return true; |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1101
diff
changeset
|
1194 } |
1424
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1195 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1196 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1197 void Toolbox::CopyJsonWithoutComments(Json::Value& target, |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1198 const Json::Value& source) |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1199 { |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1200 switch (source.type()) |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1201 { |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1202 case Json::nullValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1203 target = Json::nullValue; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1204 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1205 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1206 case Json::intValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1207 target = source.asInt64(); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1208 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1209 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1210 case Json::uintValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1211 target = source.asUInt64(); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1212 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1213 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1214 case Json::realValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1215 target = source.asDouble(); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1216 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1217 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1218 case Json::stringValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1219 target = source.asString(); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1220 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1221 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1222 case Json::booleanValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1223 target = source.asBool(); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1224 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1225 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1226 case Json::arrayValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1227 { |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1228 target = Json::arrayValue; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1229 for (Json::Value::ArrayIndex i = 0; i < source.size(); i++) |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1230 { |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1231 Json::Value& item = target.append(Json::nullValue); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1232 CopyJsonWithoutComments(item, source[i]); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1233 } |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1234 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1235 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1236 } |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1237 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1238 case Json::objectValue: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1239 { |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1240 target = Json::objectValue; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1241 Json::Value::Members members = source.getMemberNames(); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1242 for (Json::Value::ArrayIndex i = 0; i < members.size(); i++) |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1243 { |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1244 const std::string item = members[i]; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1245 CopyJsonWithoutComments(target[item], source[item]); |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1246 } |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1247 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1248 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1249 } |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1250 |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1251 default: |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1252 break; |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1253 } |
fe384a9d3b51
OrthancPluginGetConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
1254 } |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1255 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1256 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1257 bool Toolbox::StartsWith(const std::string& str, |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1258 const std::string& prefix) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1259 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1260 if (str.size() < prefix.size()) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1261 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1262 return false; |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1263 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1264 else |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1265 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1266 return str.compare(0, prefix.size(), prefix) == 0; |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1267 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
1268 } |
2043
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1269 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1270 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1271 static bool IsUnreservedCharacter(char c) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1272 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1273 // This function checks whether "c" is an unserved character |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1274 // wrt. an URI percent-encoding |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1275 // https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding%5Fin%5Fa%5FURI |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1276 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1277 return ((c >= 'A' && c <= 'Z') || |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1278 (c >= 'a' && c <= 'z') || |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1279 (c >= '0' && c <= '9') || |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1280 c == '-' || |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1281 c == '_' || |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1282 c == '.' || |
4234
a38376b80cd1
WebDAV: by-studies and by-patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4203
diff
changeset
|
1283 c == '~' || |
a38376b80cd1
WebDAV: by-studies and by-patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4203
diff
changeset
|
1284 c == '/'); |
2043
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1285 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1286 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1287 void Toolbox::UriEncode(std::string& target, |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1288 const std::string& source) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1289 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1290 // Estimate the length of the percent-encoded URI |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1291 size_t length = 0; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1292 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1293 for (size_t i = 0; i < source.size(); i++) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1294 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1295 if (IsUnreservedCharacter(source[i])) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1296 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1297 length += 1; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1298 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1299 else |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1300 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1301 // This character must be percent-encoded |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1302 length += 3; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1303 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1304 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1305 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1306 target.clear(); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1307 target.reserve(length); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1308 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1309 for (size_t i = 0; i < source.size(); i++) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1310 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1311 if (IsUnreservedCharacter(source[i])) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1312 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1313 target.push_back(source[i]); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1314 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1315 else |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1316 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1317 // This character must be percent-encoded |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1318 uint8_t byte = static_cast<uint8_t>(source[i]); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1319 uint8_t a = byte >> 4; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1320 uint8_t b = byte & 0x0f; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1321 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1322 target.push_back('%'); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1323 target.push_back(a < 10 ? a + '0' : a - 10 + 'A'); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1324 target.push_back(b < 10 ? b + '0' : b - 10 + 'A'); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1325 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1326 } |
2071 | 1327 } |
1328 | |
1329 | |
1330 static bool HasField(const Json::Value& json, | |
1331 const std::string& key, | |
1332 Json::ValueType expectedType) | |
1333 { | |
1334 if (json.type() != Json::objectValue || | |
1335 !json.isMember(key)) | |
1336 { | |
1337 return false; | |
1338 } | |
1339 else if (json[key].type() == expectedType) | |
1340 { | |
1341 return true; | |
1342 } | |
1343 else | |
1344 { | |
1345 throw OrthancException(ErrorCode_BadParameterType); | |
1346 } | |
1347 } | |
1348 | |
1349 | |
1350 std::string Toolbox::GetJsonStringField(const Json::Value& json, | |
1351 const std::string& key, | |
1352 const std::string& defaultValue) | |
1353 { | |
1354 if (HasField(json, key, Json::stringValue)) | |
1355 { | |
1356 return json[key].asString(); | |
1357 } | |
1358 else | |
1359 { | |
1360 return defaultValue; | |
1361 } | |
1362 } | |
1363 | |
1364 | |
1365 bool Toolbox::GetJsonBooleanField(const ::Json::Value& json, | |
1366 const std::string& key, | |
1367 bool defaultValue) | |
1368 { | |
1369 if (HasField(json, key, Json::booleanValue)) | |
1370 { | |
1371 return json[key].asBool(); | |
1372 } | |
1373 else | |
1374 { | |
1375 return defaultValue; | |
1376 } | |
1377 } | |
1378 | |
1379 | |
1380 int Toolbox::GetJsonIntegerField(const ::Json::Value& json, | |
1381 const std::string& key, | |
1382 int defaultValue) | |
1383 { | |
1384 if (HasField(json, key, Json::intValue)) | |
1385 { | |
1386 return json[key].asInt(); | |
1387 } | |
1388 else | |
1389 { | |
1390 return defaultValue; | |
1391 } | |
1392 } | |
1393 | |
1394 | |
1395 unsigned int Toolbox::GetJsonUnsignedIntegerField(const ::Json::Value& json, | |
1396 const std::string& key, | |
1397 unsigned int defaultValue) | |
1398 { | |
1399 int v = GetJsonIntegerField(json, key, defaultValue); | |
1400 | |
1401 if (v < 0) | |
1402 { | |
1403 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1404 } | |
1405 else | |
1406 { | |
1407 return static_cast<unsigned int>(v); | |
1408 } | |
1409 } | |
2140 | 1410 |
1411 | |
2141 | 1412 bool Toolbox::IsUuid(const std::string& str) |
1413 { | |
1414 if (str.size() != 36) | |
1415 { | |
1416 return false; | |
1417 } | |
1418 | |
1419 for (size_t i = 0; i < str.length(); i++) | |
1420 { | |
1421 if (i == 8 || i == 13 || i == 18 || i == 23) | |
1422 { | |
1423 if (str[i] != '-') | |
1424 return false; | |
1425 } | |
1426 else | |
1427 { | |
1428 if (!isalnum(str[i])) | |
1429 return false; | |
1430 } | |
1431 } | |
1432 | |
1433 return true; | |
1434 } | |
1435 | |
1436 | |
1437 bool Toolbox::StartsWithUuid(const std::string& str) | |
1438 { | |
1439 if (str.size() < 36) | |
1440 { | |
1441 return false; | |
1442 } | |
1443 | |
1444 if (str.size() == 36) | |
1445 { | |
1446 return IsUuid(str); | |
1447 } | |
1448 | |
1449 assert(str.size() > 36); | |
1450 if (!isspace(str[36])) | |
1451 { | |
1452 return false; | |
1453 } | |
1454 | |
1455 return IsUuid(str.substr(0, 36)); | |
1456 } | |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1457 |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1458 |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2351
diff
changeset
|
1459 #if ORTHANC_ENABLE_LOCALE == 1 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1460 static std::unique_ptr<std::locale> globalLocale_; |
2334 | 1461 |
1462 static bool SetGlobalLocale(const char* locale) | |
1463 { | |
1464 try | |
1465 { | |
1466 if (locale == NULL) | |
1467 { | |
1468 LOG(WARNING) << "Falling back to system-wide default locale"; | |
1469 globalLocale_.reset(new std::locale()); | |
1470 } | |
1471 else | |
1472 { | |
2351 | 1473 LOG(INFO) << "Using locale: \"" << locale << "\" for case-insensitive comparison of strings"; |
2334 | 1474 globalLocale_.reset(new std::locale(locale)); |
1475 } | |
1476 } | |
3459
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1477 catch (std::runtime_error& e) |
2334 | 1478 { |
3459
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1479 LOG(ERROR) << "Cannot set globale locale to " |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1480 << (locale ? std::string(locale) : "(null)") |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1481 << ": " << e.what(); |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1482 globalLocale_.reset(NULL); |
2334 | 1483 } |
1484 | |
1485 return (globalLocale_.get() != NULL); | |
1486 } | |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1487 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1488 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1489 static void InitializeIcu() |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1490 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1491 #if ORTHANC_STATIC_ICU == 1 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1492 if (globalIcuData_.empty()) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1493 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1494 LOG(INFO) << "Setting up the ICU common data"; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1495 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1496 GzipCompressor compressor; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1497 compressor.Uncompress(globalIcuData_, |
4032
058b5ade8acd
renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
1498 FrameworkResources::GetFileResourceBuffer(FrameworkResources::LIBICU_DATA), |
058b5ade8acd
renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4030
diff
changeset
|
1499 FrameworkResources::GetFileResourceSize(FrameworkResources::LIBICU_DATA)); |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1500 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1501 std::string md5; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1502 Toolbox::ComputeMD5(md5, globalIcuData_); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1503 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1504 if (md5 != ORTHANC_ICU_DATA_MD5 || |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1505 globalIcuData_.empty()) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1506 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1507 throw OrthancException(ErrorCode_InternalError, |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1508 "Cannot decode the ICU common data"); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1509 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1510 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1511 // "ICU data is designed to be 16-aligned" |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1512 // http://userguide.icu-project.org/icudata#TOC-Alignment |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1513 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1514 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1515 static const size_t ALIGN = 16; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1516 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1517 UErrorCode status = U_ZERO_ERROR; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1518 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1519 if (reinterpret_cast<intptr_t>(globalIcuData_.c_str()) % ALIGN == 0) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1520 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1521 // Data is already properly aligned |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1522 udata_setCommonData(globalIcuData_.c_str(), &status); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1523 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1524 else |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1525 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1526 std::string aligned; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1527 aligned.resize(globalIcuData_.size() + ALIGN - 1); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1528 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1529 intptr_t offset = reinterpret_cast<intptr_t>(aligned.c_str()) % ALIGN; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1530 if (offset != 0) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1531 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1532 offset = ALIGN - offset; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1533 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1534 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1535 if (offset + globalIcuData_.size() > aligned.size()) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1536 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1537 throw OrthancException(ErrorCode_InternalError, "Cannot align on 16-bytes boundary"); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1538 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1539 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1540 // We don't use "memcpy()", as it expects its data to be aligned |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1541 const uint8_t* p = reinterpret_cast<uint8_t*>(&globalIcuData_[0]); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1542 uint8_t* q = reinterpret_cast<uint8_t*>(&aligned[0]) + offset; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1543 for (size_t i = 0; i < globalIcuData_.size(); i++, p++, q++) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1544 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1545 *q = *p; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1546 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1547 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1548 globalIcuData_.swap(aligned); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1549 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1550 const uint8_t* data = reinterpret_cast<const uint8_t*>(globalIcuData_.c_str()) + offset; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1551 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1552 if (reinterpret_cast<intptr_t>(data) % ALIGN != 0) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1553 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1554 throw OrthancException(ErrorCode_InternalError, "Cannot align on 16-bytes boundary"); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1555 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1556 else |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1557 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1558 udata_setCommonData(data, &status); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1559 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1560 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1561 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1562 if (status != U_ZERO_ERROR) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1563 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1564 throw OrthancException(ErrorCode_InternalError, "Cannot initialize ICU"); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1565 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1566 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1567 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1568 if (Toolbox::DetectEndianness() != Endianness_Little) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1569 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1570 // TODO - The data table must be swapped (uint16_t) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1571 throw OrthancException(ErrorCode_NotImplemented); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1572 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1573 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1574 // "First-use of ICU from a single thread before the |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1575 // multi-threaded use of ICU begins", to make sure everything is |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1576 // properly initialized (should not be mandatory in our |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1577 // case). We let boost handle calls to "u_init()" and "u_cleanup()". |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1578 // http://userguide.icu-project.org/design#TOC-ICU-Initialization-and-Termination |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1579 uloc_getDefault(); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1580 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1581 #endif |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1582 } |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1583 |
2330
9c7a80c87ae9
"Locale" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2326
diff
changeset
|
1584 void Toolbox::InitializeGlobalLocale(const char* locale) |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1585 { |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1586 InitializeIcu(); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1587 |
3459
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1588 #if defined(__unix__) && ORTHANC_SANDBOXED != 1 |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1589 static const char* LOCALTIME = "/etc/localtime"; |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1590 |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1591 if (!SystemToolbox::IsExistingFile(LOCALTIME)) |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1592 { |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1593 // Check out file |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1594 // "boost_1_69_0/libs/locale/src/icu/time_zone.cpp": Direct |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1595 // access is made to this file if ICU is not used. Crash arises |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1596 // in Boost if the file is a symbolic link to a non-existing |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1597 // file (such as in Ubuntu 16.04 base Docker image). |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1598 throw OrthancException( |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1599 ErrorCode_InternalError, |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1600 "On UNIX-like systems, the file " + std::string(LOCALTIME) + |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1601 " must be present on the filesystem (install \"tzdata\" package on Debian)"); |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1602 } |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1603 #endif |
cbbe0bb80bd4
explicit error message if missing /etc/localtime
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3401
diff
changeset
|
1604 |
2334 | 1605 bool ok; |
1606 | |
1607 if (locale == NULL) | |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1608 { |
4203
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1609 // Make Orthanc use English, United States locale |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1610 // Linux: use "en_US.UTF-8" |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1611 // Windows: use "" |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1612 // Wine: use NULL |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1613 |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1614 #if defined(__MINGW32__) |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1615 // Visibly, there is no support of locales in MinGW yet |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1616 // http://mingw.5.n7.nabble.com/How-to-use-std-locale-global-with-MinGW-correct-td33048.html |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1617 static const char* DEFAULT_LOCALE = NULL; |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1618 #elif defined(_WIN32) |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1619 // For Windows: use default locale (using "en_US" does not work) |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1620 static const char* DEFAULT_LOCALE = ""; |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1621 #else |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1622 // For Linux & cie |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1623 static const char* DEFAULT_LOCALE = "en_US.UTF-8"; |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1624 #endif |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1625 |
2334 | 1626 ok = SetGlobalLocale(DEFAULT_LOCALE); |
1627 | |
1628 #if defined(__MINGW32__) | |
1629 LOG(WARNING) << "This is a MinGW build, case-insensitive comparison of " | |
1630 << "strings with accents will not work outside of Wine"; | |
1631 #endif | |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1632 } |
2334 | 1633 else |
1634 { | |
1635 ok = SetGlobalLocale(locale); | |
1636 } | |
1637 | |
1638 if (!ok && | |
1639 !SetGlobalLocale(NULL)) | |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1640 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2931
diff
changeset
|
1641 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2931
diff
changeset
|
1642 "Cannot initialize global locale"); |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1643 } |
2334 | 1644 |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1645 } |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1646 |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1647 |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1648 void Toolbox::FinalizeGlobalLocale() |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1649 { |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1650 globalLocale_.reset(); |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1651 } |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1652 |
2677
0196d07a900f
migrate OpenSSL initialization to Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2513
diff
changeset
|
1653 |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1654 std::string Toolbox::ToUpperCaseWithAccents(const std::string& source) |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1655 { |
3333
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1656 bool error = (globalLocale_.get() == NULL); |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1657 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1658 #if ORTHANC_STATIC_ICU == 1 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1659 if (globalIcuData_.empty()) |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1660 { |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1661 error = true; |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1662 } |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1663 #endif |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1664 |
2a38e00a0638
Size of the Orthanc static binaries are reduced by compressing ICU data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3328
diff
changeset
|
1665 if (error) |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1666 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2931
diff
changeset
|
1667 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2931
diff
changeset
|
1668 "No global locale was set, call Toolbox::InitializeGlobalLocale()"); |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1669 } |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1670 |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1671 /** |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1672 * A few notes about locales: |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1673 * |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1674 * (1) We don't use "case folding": |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1675 * http://www.boost.org/doc/libs/1_64_0/libs/locale/doc/html/conversions.html |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1676 * |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1677 * Characters are made uppercase one by one. This is because, in |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1678 * static builds, we are using iconv, which is visibly not |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1679 * supported correctly (TODO: Understand why). Case folding seems |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1680 * to be working correctly if using the default backend under |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1681 * Linux (ICU or POSIX?). If one wishes to use case folding, one |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1682 * would use: |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1683 * |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1684 * boost::locale::generator gen; |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1685 * std::locale::global(gen(DEFAULT_LOCALE)); |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1686 * return boost::locale::to_upper(source); |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1687 * |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1688 * (2) The function "boost::algorithm::to_upper_copy" does not |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1689 * make use of the "std::locale::global()". We therefore create a |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1690 * global variable "globalLocale_". |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1691 * |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1692 * (3) The variant of "boost::algorithm::to_upper_copy()" that |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1693 * uses std::string does not work properly. We need to apply it |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1694 * one wide strings (std::wstring). This explains the two calls to |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1695 * "utf_to_utf" in order to convert to/from std::wstring. |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1696 **/ |
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1697 |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
1698 std::wstring w = boost::locale::conv::utf_to_utf<wchar_t>(source, boost::locale::conv::skip); |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1699 w = boost::algorithm::to_upper_copy<std::wstring>(w, *globalLocale_); |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
1700 return boost::locale::conv::utf_to_utf<char>(w, boost::locale::conv::skip); |
2326
423d3b692bb9
Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1701 } |
2373 | 1702 #endif |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1703 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1704 |
3802
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1705 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1706 #if ORTHANC_ENABLE_SSL == 0 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1707 /** |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1708 * OpenSSL is disabled |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1709 **/ |
2678 | 1710 void Toolbox::InitializeOpenSsl() |
1711 { | |
4706
dbee8bd8ee1f
display OpenSSL version in the logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
1712 LOG(INFO) << "OpenSSL is disabled"; |
3802
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1713 } |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1714 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1715 void Toolbox::FinalizeOpenSsl() |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1716 { |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1717 } |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1718 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1719 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1720 #elif (ORTHANC_ENABLE_SSL == 1 && \ |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1721 OPENSSL_VERSION_NUMBER < 0x10100000L) |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1722 /** |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1723 * OpenSSL < 1.1.0 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1724 **/ |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1725 void Toolbox::InitializeOpenSsl() |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1726 { |
4706
dbee8bd8ee1f
display OpenSSL version in the logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
1727 LOG(INFO) << "OpenSSL version: " << OPENSSL_VERSION_TEXT; |
dbee8bd8ee1f
display OpenSSL version in the logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
1728 |
2678 | 1729 // https://wiki.openssl.org/index.php/Library_Initialization |
1730 SSL_library_init(); | |
1731 SSL_load_error_strings(); | |
1732 OpenSSL_add_all_algorithms(); | |
1733 ERR_load_crypto_strings(); | |
1734 } | |
1735 | |
1736 void Toolbox::FinalizeOpenSsl() | |
1737 { | |
1738 // Finalize OpenSSL | |
1739 // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup | |
1740 #ifdef FIPS_mode_set | |
1741 FIPS_mode_set(0); | |
1742 #endif | |
3720
faa695f433d5
upgraded OpenSSL to 1.1.1d
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1743 |
faa695f433d5
upgraded OpenSSL to 1.1.1d
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1744 #if !defined(OPENSSL_NO_ENGINE) |
2678 | 1745 ENGINE_cleanup(); |
3720
faa695f433d5
upgraded OpenSSL to 1.1.1d
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1746 #endif |
faa695f433d5
upgraded OpenSSL to 1.1.1d
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1747 |
2678 | 1748 CONF_modules_unload(1); |
1749 EVP_cleanup(); | |
1750 CRYPTO_cleanup_all_ex_data(); | |
1751 ERR_remove_state(0); | |
1752 ERR_free_strings(); | |
3802
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1753 } |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1754 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1755 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1756 #elif (ORTHANC_ENABLE_SSL == 1 && \ |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1757 OPENSSL_VERSION_NUMBER >= 0x10100000L) |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1758 /** |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1759 * OpenSSL >= 1.1.0. In this case, the initialization is |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1760 * automatically done by the functions of OpenSSL. |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1761 * https://wiki.openssl.org/index.php/Library_Initialization |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1762 **/ |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1763 void Toolbox::InitializeOpenSsl() |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1764 { |
4706
dbee8bd8ee1f
display OpenSSL version in the logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
1765 LOG(INFO) << "OpenSSL version: " << OPENSSL_VERSION_TEXT; |
3802
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1766 } |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1767 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1768 void Toolbox::FinalizeOpenSsl() |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1769 { |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1770 } |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1771 |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1772 #else |
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1773 # error "Support your platform here" |
2678 | 1774 #endif |
3802
6462ecaa045b
fix unit test, reorganization of OpenSSL initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3731
diff
changeset
|
1775 |
2678 | 1776 |
1777 | |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1778 std::string Toolbox::GenerateUuid() |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1779 { |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1780 #ifdef WIN32 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1781 UUID uuid; |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1782 UuidCreate ( &uuid ); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1783 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1784 unsigned char * str; |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1785 UuidToStringA ( &uuid, &str ); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1786 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1787 std::string s( ( char* ) str ); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1788 |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1789 RpcStringFreeA ( &str ); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1790 #else |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1791 uuid_t uuid; |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1792 uuid_generate_random ( uuid ); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1793 char s[37]; |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1794 uuid_unparse ( uuid, s ); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1795 #endif |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1796 return s; |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1797 } |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1798 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1799 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1800 namespace |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1801 { |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1802 // Anonymous namespace to avoid clashes between compilation modules |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1803 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1804 class VariableFormatter |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1805 { |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1806 public: |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1807 typedef std::map<std::string, std::string> Dictionary; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1808 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1809 private: |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1810 const Dictionary& dictionary_; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1811 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1812 public: |
4203
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1813 explicit VariableFormatter(const Dictionary& dictionary) : |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1814 dictionary_(dictionary) |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1815 { |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1816 } |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1817 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1818 template<typename Out> |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1819 Out operator()(const boost::smatch& what, |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1820 Out out) const |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1821 { |
2921
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1822 if (!what[1].str().empty()) |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1823 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1824 // Variable without a default value |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1825 Dictionary::const_iterator found = dictionary_.find(what[1]); |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1826 |
2921
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1827 if (found != dictionary_.end()) |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1828 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1829 const std::string& value = found->second; |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1830 out = std::copy(value.begin(), value.end(), out); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1831 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1832 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1833 else |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1834 { |
2921
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1835 // Variable with a default value |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1836 std::string key; |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1837 std::string defaultValue; |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1838 |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1839 if (!what[2].str().empty()) |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1840 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1841 key = what[2].str(); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1842 defaultValue = what[3].str(); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1843 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1844 else if (!what[4].str().empty()) |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1845 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1846 key = what[4].str(); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1847 defaultValue = what[5].str(); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1848 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1849 else if (!what[6].str().empty()) |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1850 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1851 key = what[6].str(); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1852 defaultValue = what[7].str(); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1853 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1854 else |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1855 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1856 throw OrthancException(ErrorCode_InternalError); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1857 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1858 |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1859 Dictionary::const_iterator found = dictionary_.find(key); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1860 |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1861 if (found == dictionary_.end()) |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1862 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1863 out = std::copy(defaultValue.begin(), defaultValue.end(), out); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1864 } |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1865 else |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1866 { |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1867 const std::string& value = found->second; |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1868 out = std::copy(value.begin(), value.end(), out); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1869 } |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1870 } |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1871 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1872 return out; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1873 } |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1874 }; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1875 } |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1876 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1877 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1878 std::string Toolbox::SubstituteVariables(const std::string& source, |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1879 const std::map<std::string, std::string>& dictionary) |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1880 { |
2926
0bcf46cea4e4
fix for older versions of boost::regex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
1881 const boost::regex pattern("\\$\\{([^:]*?)\\}|" // ${what[1]} |
0bcf46cea4e4
fix for older versions of boost::regex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
1882 "\\$\\{([^:]*?):-([^'\"]*?)\\}|" // ${what[2]:-what[3]} |
0bcf46cea4e4
fix for older versions of boost::regex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
1883 "\\$\\{([^:]*?):-\"([^\"]*?)\"\\}|" // ${what[4]:-"what[5]"} |
0bcf46cea4e4
fix for older versions of boost::regex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
1884 "\\$\\{([^:]*?):-'([^']*?)'\\}"); // ${what[6]:-'what[7]'} |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1885 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1886 VariableFormatter formatter(dictionary); |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1887 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1888 return boost::regex_replace(source, pattern, formatter); |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
1889 } |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1890 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1891 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1892 namespace Iso2022 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1893 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1894 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1895 Returns whether the string s contains a single-byte control message |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1896 at index i |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1897 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1898 static inline bool IsControlMessage1(const std::string& s, size_t i) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1899 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1900 if (i < s.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1901 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1902 char c = s[i]; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1903 return |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1904 (c == '\x0f') || // Locking shift zero |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1905 (c == '\x0e'); // Locking shift one |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1906 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1907 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1908 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1909 return false; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1910 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1911 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1912 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1913 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1914 Returns whether the string s contains a double-byte control message |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1915 at index i |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1916 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1917 static inline size_t IsControlMessage2(const std::string& s, size_t i) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1918 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1919 if (i + 1 < s.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1920 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1921 char c1 = s[i]; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1922 char c2 = s[i + 1]; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1923 return (c1 == 0x1b) && ( |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1924 (c2 == '\x6e') || // Locking shift two |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1925 (c2 == '\x6f') || // Locking shift three |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1926 (c2 == '\x4e') || // Single shift two (alt) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1927 (c2 == '\x4f') || // Single shift three (alt) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1928 (c2 == '\x7c') || // Locking shift three right |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1929 (c2 == '\x7d') || // Locking shift two right |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1930 (c2 == '\x7e') // Locking shift one right |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1931 ); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1932 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1933 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1934 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1935 return false; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1936 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1937 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1938 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1939 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1940 Returns whether the string s contains a triple-byte control message |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1941 at index i |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1942 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1943 static inline size_t IsControlMessage3(const std::string& s, size_t i) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1944 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1945 if (i + 2 < s.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1946 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1947 char c1 = s[i]; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1948 char c2 = s[i + 1]; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1949 char c3 = s[i + 2]; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1950 return ((c1 == '\x8e' && c2 == 0x1b && c3 == '\x4e') || |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1951 (c1 == '\x8f' && c2 == 0x1b && c3 == '\x4f')); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1952 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1953 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1954 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1955 return false; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1956 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1957 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1958 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1959 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1960 This function returns true if the index i in the supplied string s: |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1961 - is valid |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1962 - contains the c character |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1963 This function returns false otherwise. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1964 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1965 static inline bool TestCharValue( |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1966 const std::string& s, size_t i, char c) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1967 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1968 if (i < s.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1969 return s[i] == c; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1970 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1971 return false; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1972 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1973 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1974 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1975 This function returns true if the index i in the supplied string s: |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1976 - is valid |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1977 - has a c character that is >= cMin and <= cMax (included) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1978 This function returns false otherwise. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1979 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1980 static inline bool TestCharRange( |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1981 const std::string& s, size_t i, char cMin, char cMax) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1982 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1983 if (i < s.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1984 return (s[i] >= cMin) && (s[i] <= cMax); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1985 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1986 return false; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1987 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1988 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1989 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1990 This function returns the total length in bytes of the escape sequence |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1991 located in string s at index i, if there is one, or 0 otherwise. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1992 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1993 static inline size_t GetEscapeSequenceLength(const std::string& s, size_t i) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1994 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1995 if (TestCharValue(s, i, 0x1b)) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1996 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1997 size_t j = i+1; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1998 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
1999 // advance reading cursor while we are in a sequence |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2000 while (TestCharRange(s, j, '\x20', '\x2f')) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2001 ++j; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2002 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2003 // check there is a valid termination byte AND we're long enough (there |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2004 // must be at least one byte between 0x20 and 0x2f |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2005 if (TestCharRange(s, j, '\x30', '\x7f') && (j - i) >= 2) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2006 return j - i + 1; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2007 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2008 return 0; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2009 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2010 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2011 return 0; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2012 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2013 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2014 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2015 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2016 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2017 /** |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2018 This function will strip all ISO/IEC 2022 control codes and escape |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2019 sequences. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2020 Please see https://en.wikipedia.org/wiki/ISO/IEC_2022 (as of 2019-02) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2021 for a list of those. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2022 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2023 Please note that this operation is potentially destructive, because |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2024 it removes the character set information from the byte stream. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2025 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2026 However, in the case where the encoding is unique, then suppressing |
3973
d86bddb50972
fix spelling errors according to debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3802
diff
changeset
|
2027 the escape sequences allows one to provide us with a clean string after |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2028 conversion to utf-8 with boost. |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2029 **/ |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2030 void Toolbox::RemoveIso2022EscapeSequences(std::string& dest, const std::string& src) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2031 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2032 // we need AT MOST the same size as the source string in the output |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2033 dest.clear(); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2034 if (dest.capacity() < src.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2035 dest.reserve(src.size()); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2036 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2037 size_t i = 0; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2038 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2039 // uint8_t view to the string |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2040 while (i < src.size()) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2041 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2042 size_t j = i; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2043 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2044 // The i index will only be incremented if a message is detected |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2045 // in that case, the message is skipped and the index is set to the |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2046 // next position to read |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2047 if (Iso2022::IsControlMessage1(src, i)) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2048 i += 1; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2049 else if (Iso2022::IsControlMessage2(src, i)) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2050 i += 2; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2051 else if (Iso2022::IsControlMessage3(src, i)) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2052 i += 3; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2053 else |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2054 i += Iso2022::GetEscapeSequenceLength(src, i); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2055 |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2056 // if the index was NOT incremented, this means there was no message at |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2057 // this location: we then may copy the character at this index and |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2058 // increment the index to point to the next read position |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2059 if (j == i) |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2060 { |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2061 dest.push_back(src[i]); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2062 i++; |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2063 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2064 } |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
2065 } |
3322
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2066 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2067 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2068 void Toolbox::Utf8ToUnicodeCharacter(uint32_t& unicode, |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2069 size_t& length, |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2070 const std::string& utf8, |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2071 size_t position) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2072 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2073 // https://en.wikipedia.org/wiki/UTF-8 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2074 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2075 static const uint8_t MASK_IS_1_BYTE = 0x80; // printf '0x%x\n' "$((2#10000000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2076 static const uint8_t TEST_IS_1_BYTE = 0x00; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2077 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2078 static const uint8_t MASK_IS_2_BYTES = 0xe0; // printf '0x%x\n' "$((2#11100000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2079 static const uint8_t TEST_IS_2_BYTES = 0xc0; // printf '0x%x\n' "$((2#11000000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2080 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2081 static const uint8_t MASK_IS_3_BYTES = 0xf0; // printf '0x%x\n' "$((2#11110000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2082 static const uint8_t TEST_IS_3_BYTES = 0xe0; // printf '0x%x\n' "$((2#11100000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2083 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2084 static const uint8_t MASK_IS_4_BYTES = 0xf8; // printf '0x%x\n' "$((2#11111000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2085 static const uint8_t TEST_IS_4_BYTES = 0xf0; // printf '0x%x\n' "$((2#11110000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2086 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2087 static const uint8_t MASK_CONTINUATION = 0xc0; // printf '0x%x\n' "$((2#11000000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2088 static const uint8_t TEST_CONTINUATION = 0x80; // printf '0x%x\n' "$((2#10000000))" |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2089 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2090 if (position >= utf8.size()) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2091 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2092 throw OrthancException(ErrorCode_ParameterOutOfRange); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2093 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2094 |
3324 | 2095 assert(sizeof(uint8_t) == sizeof(char)); |
2096 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(utf8.c_str()) + position; | |
3322
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2097 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2098 if ((buffer[0] & MASK_IS_1_BYTE) == TEST_IS_1_BYTE) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2099 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2100 length = 1; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2101 unicode = buffer[0] & ~MASK_IS_1_BYTE; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2102 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2103 else if ((buffer[0] & MASK_IS_2_BYTES) == TEST_IS_2_BYTES && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2104 position + 1 < utf8.size() && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2105 (buffer[1] & MASK_CONTINUATION) == TEST_CONTINUATION) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2106 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2107 length = 2; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2108 uint32_t a = buffer[0] & ~MASK_IS_2_BYTES; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2109 uint32_t b = buffer[1] & ~MASK_CONTINUATION; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2110 unicode = (a << 6) | b; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2111 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2112 else if ((buffer[0] & MASK_IS_3_BYTES) == TEST_IS_3_BYTES && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2113 position + 2 < utf8.size() && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2114 (buffer[1] & MASK_CONTINUATION) == TEST_CONTINUATION && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2115 (buffer[2] & MASK_CONTINUATION) == TEST_CONTINUATION) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2116 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2117 length = 3; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2118 uint32_t a = buffer[0] & ~MASK_IS_3_BYTES; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2119 uint32_t b = buffer[1] & ~MASK_CONTINUATION; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2120 uint32_t c = buffer[2] & ~MASK_CONTINUATION; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2121 unicode = (a << 12) | (b << 6) | c; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2122 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2123 else if ((buffer[0] & MASK_IS_4_BYTES) == TEST_IS_4_BYTES && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2124 position + 3 < utf8.size() && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2125 (buffer[1] & MASK_CONTINUATION) == TEST_CONTINUATION && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2126 (buffer[2] & MASK_CONTINUATION) == TEST_CONTINUATION && |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2127 (buffer[3] & MASK_CONTINUATION) == TEST_CONTINUATION) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2128 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2129 length = 4; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2130 uint32_t a = buffer[0] & ~MASK_IS_4_BYTES; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2131 uint32_t b = buffer[1] & ~MASK_CONTINUATION; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2132 uint32_t c = buffer[2] & ~MASK_CONTINUATION; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2133 uint32_t d = buffer[3] & ~MASK_CONTINUATION; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2134 unicode = (a << 18) | (b << 12) | (c << 6) | d; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2135 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2136 else |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2137 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2138 // This is not a valid UTF-8 encoding |
3324 | 2139 throw OrthancException(ErrorCode_BadFileFormat, "Invalid UTF-8 string"); |
3322
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2140 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3230
diff
changeset
|
2141 } |
3608
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2142 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2143 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2144 std::string Toolbox::LargeHexadecimalToDecimal(const std::string& hex) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2145 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2146 /** |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2147 * NB: Focus of the code below is *not* efficiency, but |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2148 * readability! |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2149 **/ |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2150 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2151 for (size_t i = 0; i < hex.size(); i++) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2152 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2153 const char c = hex[i]; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2154 if (!((c >= 'A' && c <= 'F') || |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2155 (c >= 'a' && c <= 'f') || |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2156 (c >= '0' && c <= '9'))) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2157 { |
4297 | 2158 throw OrthancException(ErrorCode_ParameterOutOfRange, |
2159 "Not an hexadecimal number"); | |
3608
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2160 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2161 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2162 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2163 std::vector<uint8_t> decimal; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2164 decimal.push_back(0); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2165 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2166 for (size_t i = 0; i < hex.size(); i++) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2167 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2168 uint8_t hexDigit = static_cast<uint8_t>(Hex2Dec(hex[i])); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2169 assert(hexDigit <= 15); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2170 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2171 for (size_t j = 0; j < decimal.size(); j++) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2172 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2173 uint8_t val = static_cast<uint8_t>(decimal[j]) * 16 + hexDigit; // Maximum: 9 * 16 + 15 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2174 assert(val <= 159 /* == 9 * 16 + 15 */); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2175 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2176 decimal[j] = val % 10; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2177 hexDigit = val / 10; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2178 assert(hexDigit <= 15 /* == 159 / 10 */); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2179 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2180 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2181 while (hexDigit > 0) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2182 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2183 decimal.push_back(hexDigit % 10); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2184 hexDigit /= 10; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2185 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2186 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2187 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2188 size_t start = 0; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2189 while (start < decimal.size() && |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2190 decimal[start] == '0') |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2191 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2192 start++; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2193 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2194 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2195 std::string s; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2196 s.reserve(decimal.size() - start); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2197 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2198 for (size_t i = decimal.size(); i > start; i--) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2199 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2200 s.push_back(decimal[i - 1] + '0'); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2201 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2202 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2203 return s; |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2204 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2205 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2206 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2207 std::string Toolbox::GenerateDicomPrivateUniqueIdentifier() |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2208 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2209 /** |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2210 * REFERENCE: "Creating a Privately Defined Unique Identifier |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2211 * (Informative)" / "UUID Derived UID" |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2212 * http://dicom.nema.org/medical/dicom/2019a/output/chtml/part05/sect_B.2.html |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2213 * https://stackoverflow.com/a/46316162/881731 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2214 **/ |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2215 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2216 std::string uuid = GenerateUuid(); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2217 assert(IsUuid(uuid) && uuid.size() == 36); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2218 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2219 /** |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2220 * After removing the four dashes ("-") out of the 36-character |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2221 * UUID, we get a large hexadecimal number with 32 characters, |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2222 * each of those characters lying in the range [0,16[. The large |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2223 * number is thus in the [0,16^32[ = [0,256^16[ range. This number |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2224 * has a maximum of 39 decimal digits, as can be seen in Python: |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2225 * |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2226 * # python -c 'import math; print(math.log(16**32))/math.log(10))' |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2227 * 38.531839445 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2228 * |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2229 * We now to convert the large hexadecimal number to a decimal |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2230 * number with up to 39 digits, remove the leading zeros, then |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2231 * prefix it with "2.25." |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2232 **/ |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2233 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2234 // Remove the dashes |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2235 std::string hex = (uuid.substr(0, 8) + |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2236 uuid.substr(9, 4) + |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2237 uuid.substr(14, 4) + |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2238 uuid.substr(19, 4) + |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2239 uuid.substr(24, 12)); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2240 assert(hex.size() == 32); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2241 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2242 return "2.25." + LargeHexadecimalToDecimal(hex); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
2243 } |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2244 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2245 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2246 void Toolbox::SimplifyDicomAsJson(Json::Value& target, |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2247 const Json::Value& source, |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2248 DicomToJsonFormat format) |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2249 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2250 if (!source.isObject()) |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2251 { |
4297 | 2252 throw OrthancException(ErrorCode_BadFileFormat); |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2253 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2254 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2255 target = Json::objectValue; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2256 Json::Value::Members members = source.getMemberNames(); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2257 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2258 for (size_t i = 0; i < members.size(); i++) |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2259 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2260 const Json::Value& v = source[members[i]]; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2261 const std::string& type = v["Type"].asString(); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2262 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2263 std::string name; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2264 switch (format) |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2265 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2266 case DicomToJsonFormat_Human: |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2267 name = v["Name"].asString(); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2268 break; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2269 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2270 case DicomToJsonFormat_Short: |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2271 name = members[i]; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2272 break; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2273 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2274 default: |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2275 throw OrthancException(ErrorCode_ParameterOutOfRange); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2276 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2277 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2278 if (type == "String") |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2279 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2280 target[name] = v["Value"].asString(); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2281 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2282 else if (type == "TooLong" || |
4527
31f940334496
Handle public tags with "UN" value representation and containing a string (cf. DICOM CP 246)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
2283 type == "Null" || |
31f940334496
Handle public tags with "UN" value representation and containing a string (cf. DICOM CP 246)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
2284 type == "Binary") |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2285 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2286 target[name] = Json::nullValue; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2287 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2288 else if (type == "Sequence") |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2289 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2290 const Json::Value& array = v["Value"]; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2291 assert(array.isArray()); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2292 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2293 Json::Value children = Json::arrayValue; |
4203
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
2294 for (Json::Value::ArrayIndex j = 0; j < array.size(); j++) |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2295 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2296 Json::Value c; |
4203
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
2297 SimplifyDicomAsJson(c, array[j], format); |
4055
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2298 children.append(c); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2299 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2300 |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2301 target[name] = children; |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2302 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2303 else |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2304 { |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2305 assert(0); |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2306 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2307 } |
9214e3a7b0a2
moving FromDcmtkTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
2308 } |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2309 |
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2310 |
4397
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2311 static bool ReadJsonInternal(Json::Value& target, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2312 const void* buffer, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2313 size_t size, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2314 bool collectComments) |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2315 { |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2316 #if JSONCPP_USE_DEPRECATED == 1 |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2317 Json::Reader reader; |
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2318 return reader.parse(reinterpret_cast<const char*>(buffer), |
4397
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2319 reinterpret_cast<const char*>(buffer) + size, target, collectComments); |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2320 #else |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2321 Json::CharReaderBuilder builder; |
4397
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2322 builder.settings_["collectComments"] = collectComments; |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2323 |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2324 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2325 assert(reader.get() != NULL); |
4397
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2326 |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2327 JSONCPP_STRING err; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2328 if (reader->parse(reinterpret_cast<const char*>(buffer), |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2329 reinterpret_cast<const char*>(buffer) + size, &target, &err)) |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2330 { |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2331 return true; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2332 } |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2333 else |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2334 { |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2335 LOG(ERROR) << "Cannot parse JSON: " << err; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2336 return false; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2337 } |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2338 #endif |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2339 } |
4397
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2340 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2341 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2342 bool Toolbox::ReadJson(Json::Value& target, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2343 const std::string& source) |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2344 { |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2345 return ReadJson(target, source.empty() ? NULL : source.c_str(), source.size()); |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2346 } |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2347 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2348 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2349 bool Toolbox::ReadJson(Json::Value& target, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2350 const void* buffer, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2351 size_t size) |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2352 { |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2353 return ReadJsonInternal(target, buffer, size, true); |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2354 } |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2355 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2356 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2357 bool Toolbox::ReadJsonWithoutComments(Json::Value& target, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2358 const std::string& source) |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2359 { |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2360 return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size()); |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2361 } |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2362 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2363 |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2364 bool Toolbox::ReadJsonWithoutComments(Json::Value& target, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2365 const void* buffer, |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2366 size_t size) |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2367 { |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2368 return ReadJsonInternal(target, buffer, size, false); |
3aeb5171fbd4
new function Toolbox::ReadJsonWithoutComments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4396
diff
changeset
|
2369 } |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2370 |
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2371 |
4394
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2372 void Toolbox::WriteFastJson(std::string& target, |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2373 const Json::Value& source) |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2374 { |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2375 #if JSONCPP_USE_DEPRECATED == 1 |
4394
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2376 Json::FastWriter writer; |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2377 target = writer.write(source); |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2378 #else |
4394
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2379 Json::StreamWriterBuilder builder; |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2380 builder.settings_["indentation"] = ""; |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2381 target = Json::writeString(builder, source); |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2382 #endif |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2383 } |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2384 |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2385 |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2386 void Toolbox::WriteStyledJson(std::string& target, |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2387 const Json::Value& source) |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2388 { |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2389 #if JSONCPP_USE_DEPRECATED == 1 |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2390 Json::StyledWriter writer; |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2391 target = writer.write(source); |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2392 #else |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2393 Json::StreamWriterBuilder builder; |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2394 builder.settings_["indentation"] = " "; |
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4393
diff
changeset
|
2395 target = Json::writeString(builder, source); |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
2396 #endif |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
2397 } |
4622
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2398 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2399 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2400 void Toolbox::RemoveSurroundingQuotes(std::string& value) |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2401 { |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2402 if (!value.empty() && |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2403 value[0] == '\"' && |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2404 value[value.size() - 1] == '\"') |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2405 { |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2406 value = value.substr(1, value.size() - 2); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2407 } |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4527
diff
changeset
|
2408 } |
0 | 2409 } |
2513
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2410 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2411 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2412 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2413 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2414 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2415 return reinterpret_cast<OrthancLinesIterator*>(new Orthanc::Toolbox::LinesIterator(content)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2416 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2417 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2418 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2419 bool OrthancLinesIterator_GetLine(std::string& target, |
4026
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3973
diff
changeset
|
2420 const OrthancLinesIterator* iterator) |
2513
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2421 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2422 if (iterator != NULL) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2423 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2424 return reinterpret_cast<const Orthanc::Toolbox::LinesIterator*>(iterator)->GetLine(target); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2425 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2426 else |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2427 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2428 return false; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2429 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2430 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2431 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2432 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2433 void OrthancLinesIterator_Next(OrthancLinesIterator* iterator) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2434 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2435 if (iterator != NULL) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2436 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2437 reinterpret_cast<Orthanc::Toolbox::LinesIterator*>(iterator)->Next(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2438 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2439 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2440 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2441 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2442 void OrthancLinesIterator_Free(OrthancLinesIterator* iterator) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2443 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2444 if (iterator != NULL) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2445 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2446 delete reinterpret_cast<const Orthanc::Toolbox::LinesIterator*>(iterator); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2447 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
2448 } |