Mercurial > hg > orthanc-stone
annotate Resources/Orthanc/Core/Toolbox.h @ 81:8677d95753f8 wasm
switching to Oracle in SDL samples
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 May 2017 22:54:09 +0200 |
parents | 7207a407bcd8 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
39
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
1 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #include "Enumerations.h" | |
37 | |
38 #include <stdint.h> | |
39 #include <vector> | |
40 #include <string> | |
41 #include <json/json.h> | |
42 | |
14 | 43 |
44 #if !defined(ORTHANC_ENABLE_BASE64) | |
45 # error The macro ORTHANC_ENABLE_BASE64 must be defined | |
46 #endif | |
47 | |
48 #if !defined(ORTHANC_ENABLE_MD5) | |
49 # error The macro ORTHANC_ENABLE_MD5 must be defined | |
50 #endif | |
51 | |
52 #if !defined(ORTHANC_ENABLE_PUGIXML) | |
53 # error The macro ORTHANC_ENABLE_PUGIXML must be defined | |
54 #endif | |
55 | |
56 #if !defined(BOOST_HAS_REGEX) | |
57 # error The macro BOOST_HAS_REGEX must be defined | |
58 #endif | |
59 | |
15 | 60 |
61 /** | |
62 * NOTE: GUID vs. UUID | |
63 * The simple answer is: no difference, they are the same thing. Treat | |
64 * them as a 16 byte (128 bits) value that is used as a unique | |
65 * value. In Microsoft-speak they are called GUIDs, but call them | |
66 * UUIDs when not using Microsoft-speak. | |
67 * http://stackoverflow.com/questions/246930/is-there-any-difference-between-a-guid-and-a-uuid | |
68 **/ | |
69 | |
70 | |
14 | 71 |
1 | 72 namespace Orthanc |
73 { | |
74 typedef std::vector<std::string> UriComponents; | |
75 | |
76 class NullType | |
77 { | |
78 }; | |
79 | |
80 namespace Toolbox | |
81 { | |
82 void ToUpperCase(std::string& s); // Inplace version | |
83 | |
84 void ToLowerCase(std::string& s); // Inplace version | |
85 | |
86 void ToUpperCase(std::string& result, | |
87 const std::string& source); | |
88 | |
89 void ToLowerCase(std::string& result, | |
90 const std::string& source); | |
91 | |
92 void SplitUriComponents(UriComponents& components, | |
93 const std::string& uri); | |
94 | |
95 void TruncateUri(UriComponents& target, | |
96 const UriComponents& source, | |
97 size_t fromLevel); | |
98 | |
99 bool IsChildUri(const UriComponents& baseUri, | |
100 const UriComponents& testedUri); | |
101 | |
102 std::string AutodetectMimeType(const std::string& path); | |
103 | |
104 std::string FlattenUri(const UriComponents& components, | |
105 size_t fromLevel = 0); | |
106 | |
14 | 107 #if ORTHANC_ENABLE_MD5 == 1 |
1 | 108 void ComputeMD5(std::string& result, |
109 const std::string& data); | |
110 | |
111 void ComputeMD5(std::string& result, | |
112 const void* data, | |
113 size_t size); | |
114 #endif | |
115 | |
116 void ComputeSHA1(std::string& result, | |
117 const std::string& data); | |
118 | |
119 void ComputeSHA1(std::string& result, | |
120 const void* data, | |
121 size_t size); | |
122 | |
123 bool IsSHA1(const char* str, | |
124 size_t size); | |
125 | |
126 bool IsSHA1(const std::string& s); | |
127 | |
14 | 128 #if ORTHANC_ENABLE_BASE64 == 1 |
1 | 129 void DecodeBase64(std::string& result, |
130 const std::string& data); | |
131 | |
132 void EncodeBase64(std::string& result, | |
133 const std::string& data); | |
134 | |
135 # if BOOST_HAS_REGEX == 1 | |
136 bool DecodeDataUriScheme(std::string& mime, | |
137 std::string& content, | |
138 const std::string& source); | |
139 # endif | |
140 | |
141 void EncodeDataUriScheme(std::string& result, | |
142 const std::string& mime, | |
143 const std::string& content); | |
144 #endif | |
145 | |
146 std::string ConvertToUtf8(const std::string& source, | |
147 Encoding sourceEncoding); | |
148 | |
149 std::string ConvertFromUtf8(const std::string& source, | |
150 Encoding targetEncoding); | |
151 | |
12 | 152 bool IsAsciiString(const void* data, |
153 size_t size); | |
154 | |
1 | 155 std::string ConvertToAscii(const std::string& source); |
156 | |
157 std::string StripSpaces(const std::string& source); | |
158 | |
159 // In-place percent-decoding for URL | |
160 void UrlDecode(std::string& s); | |
161 | |
162 Endianness DetectEndianness(); | |
163 | |
164 #if BOOST_HAS_REGEX == 1 | |
165 std::string WildcardToRegularExpression(const std::string& s); | |
166 #endif | |
167 | |
168 void TokenizeString(std::vector<std::string>& result, | |
169 const std::string& source, | |
170 char separator); | |
171 | |
12 | 172 #if ORTHANC_ENABLE_PUGIXML == 1 |
1 | 173 void JsonToXml(std::string& target, |
174 const Json::Value& source, | |
175 const std::string& rootElement = "root", | |
176 const std::string& arrayElement = "item"); | |
177 #endif | |
178 | |
179 bool IsInteger(const std::string& str); | |
180 | |
181 void CopyJsonWithoutComments(Json::Value& target, | |
182 const Json::Value& source); | |
183 | |
184 bool StartsWith(const std::string& str, | |
185 const std::string& prefix); | |
186 | |
187 void UriEncode(std::string& target, | |
188 const std::string& source); | |
189 | |
190 std::string GetJsonStringField(const ::Json::Value& json, | |
191 const std::string& key, | |
192 const std::string& defaultValue); | |
193 | |
194 bool GetJsonBooleanField(const ::Json::Value& json, | |
195 const std::string& key, | |
196 bool defaultValue); | |
197 | |
198 int GetJsonIntegerField(const ::Json::Value& json, | |
199 const std::string& key, | |
200 int defaultValue); | |
201 | |
202 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, | |
203 const std::string& key, | |
204 unsigned int defaultValue); | |
15 | 205 |
206 bool IsUuid(const std::string& str); | |
207 | |
208 bool StartsWithUuid(const std::string& str); | |
1 | 209 } |
210 } |