Mercurial > hg > orthanc
comparison Core/Toolbox.h @ 3991:5d2348b39392
turning toolbox namespaces into classes to control visibility in shared libraries
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 May 2020 21:23:57 +0200 |
parents | 226ab94a33cd |
children | f9863630ec7f |
comparison
equal
deleted
inserted
replaced
3990:226ab94a33cd | 3991:5d2348b39392 |
---|---|
80 | 80 |
81 class NullType | 81 class NullType |
82 { | 82 { |
83 }; | 83 }; |
84 | 84 |
85 namespace Toolbox | 85 class ORTHANC_PUBLIC Toolbox |
86 { | 86 { |
87 public: | |
87 class LinesIterator | 88 class LinesIterator |
88 { | 89 { |
89 private: | 90 private: |
90 const std::string& content_; | 91 const std::string& content_; |
91 size_t lineStart_; | 92 size_t lineStart_; |
99 bool GetLine(std::string& target) const; | 100 bool GetLine(std::string& target) const; |
100 | 101 |
101 void Next(); | 102 void Next(); |
102 }; | 103 }; |
103 | 104 |
105 static void ToUpperCase(std::string& s); // Inplace version | |
106 | |
107 static void ToLowerCase(std::string& s); // Inplace version | |
108 | |
109 static void ToUpperCase(std::string& result, | |
110 const std::string& source); | |
111 | |
112 static void ToLowerCase(std::string& result, | |
113 const std::string& source); | |
114 | |
115 static void SplitUriComponents(UriComponents& components, | |
116 const std::string& uri); | |
117 | |
118 static void TruncateUri(UriComponents& target, | |
119 const UriComponents& source, | |
120 size_t fromLevel); | |
121 | |
122 static bool IsChildUri(const UriComponents& baseUri, | |
123 const UriComponents& testedUri); | |
124 | |
125 static std::string FlattenUri(const UriComponents& components, | |
126 size_t fromLevel = 0); | |
127 | |
128 #if ORTHANC_ENABLE_MD5 == 1 | |
129 static void ComputeMD5(std::string& result, | |
130 const std::string& data); | |
131 | |
132 static void ComputeMD5(std::string& result, | |
133 const void* data, | |
134 size_t size); | |
135 #endif | |
136 | |
137 static void ComputeSHA1(std::string& result, | |
138 const std::string& data); | |
139 | |
140 static void ComputeSHA1(std::string& result, | |
141 const void* data, | |
142 size_t size); | |
143 | |
144 static bool IsSHA1(const void* str, | |
145 size_t size); | |
146 | |
147 static bool IsSHA1(const std::string& s); | |
148 | |
149 #if ORTHANC_ENABLE_BASE64 == 1 | |
150 static void DecodeBase64(std::string& result, | |
151 const std::string& data); | |
152 | |
153 static void EncodeBase64(std::string& result, | |
154 const std::string& data); | |
155 | |
156 static bool DecodeDataUriScheme(std::string& mime, | |
157 std::string& content, | |
158 const std::string& source); | |
159 | |
160 static void EncodeDataUriScheme(std::string& result, | |
161 const std::string& mime, | |
162 const std::string& content); | |
163 #endif | |
164 | |
165 #if ORTHANC_ENABLE_LOCALE == 1 | |
166 static std::string ConvertToUtf8(const std::string& source, | |
167 Encoding sourceEncoding, | |
168 bool hasCodeExtensions); | |
169 | |
170 static std::string ConvertFromUtf8(const std::string& source, | |
171 Encoding targetEncoding); | |
172 #endif | |
173 | |
174 static bool IsAsciiString(const void* data, | |
175 size_t size); | |
176 | |
177 static bool IsAsciiString(const std::string& s); | |
178 | |
179 static std::string ConvertToAscii(const std::string& source); | |
180 | |
181 static std::string StripSpaces(const std::string& source); | |
182 | |
183 // In-place percent-decoding for URL | |
184 static void UrlDecode(std::string& s); | |
185 | |
186 static Endianness DetectEndianness(); | |
187 | |
188 static std::string WildcardToRegularExpression(const std::string& s); | |
189 | |
190 static void TokenizeString(std::vector<std::string>& result, | |
191 const std::string& source, | |
192 char separator); | |
193 | |
194 #if ORTHANC_ENABLE_PUGIXML == 1 | |
195 static void JsonToXml(std::string& target, | |
196 const Json::Value& source, | |
197 const std::string& rootElement = "root", | |
198 const std::string& arrayElement = "item"); | |
199 #endif | |
200 | |
201 #if ORTHANC_ENABLE_PUGIXML == 1 | |
202 static void XmlToString(std::string& target, | |
203 const pugi::xml_document& source); | |
204 #endif | |
205 | |
206 static bool IsInteger(const std::string& str); | |
207 | |
208 static void CopyJsonWithoutComments(Json::Value& target, | |
209 const Json::Value& source); | |
210 | |
211 static bool StartsWith(const std::string& str, | |
212 const std::string& prefix); | |
213 | |
214 static void UriEncode(std::string& target, | |
215 const std::string& source); | |
216 | |
217 static std::string GetJsonStringField(const ::Json::Value& json, | |
218 const std::string& key, | |
219 const std::string& defaultValue); | |
220 | |
221 static bool GetJsonBooleanField(const ::Json::Value& json, | |
222 const std::string& key, | |
223 bool defaultValue); | |
224 | |
225 static int GetJsonIntegerField(const ::Json::Value& json, | |
226 const std::string& key, | |
227 int defaultValue); | |
228 | |
229 static unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, | |
230 const std::string& key, | |
231 unsigned int defaultValue); | |
232 | |
233 static bool IsUuid(const std::string& str); | |
234 | |
235 static bool StartsWithUuid(const std::string& str); | |
236 | |
237 #if ORTHANC_ENABLE_LOCALE == 1 | |
238 static void InitializeGlobalLocale(const char* locale); | |
239 | |
240 static void FinalizeGlobalLocale(); | |
241 | |
242 static std::string ToUpperCaseWithAccents(const std::string& source); | |
243 #endif | |
244 | |
245 static void InitializeOpenSsl(); | |
104 | 246 |
105 void ToUpperCase(std::string& s); // Inplace version | 247 static void FinalizeOpenSsl(); |
106 | 248 |
107 void ToLowerCase(std::string& s); // Inplace version | 249 static std::string GenerateUuid(); |
108 | 250 |
109 void ToUpperCase(std::string& result, | 251 static std::string SubstituteVariables(const std::string& source, |
110 const std::string& source); | 252 const std::map<std::string, std::string>& dictionary); |
111 | 253 |
112 void ToLowerCase(std::string& result, | 254 static void RemoveIso2022EscapeSequences(std::string& dest, |
113 const std::string& source); | 255 const std::string& src); |
114 | 256 |
115 void SplitUriComponents(UriComponents& components, | 257 static void Utf8ToUnicodeCharacter(uint32_t& unicode, |
116 const std::string& uri); | 258 size_t& utf8Length, |
117 | 259 const std::string& utf8, |
118 void TruncateUri(UriComponents& target, | 260 size_t position); |
119 const UriComponents& source, | 261 |
120 size_t fromLevel); | 262 static std::string LargeHexadecimalToDecimal(const std::string& hex); |
121 | |
122 bool IsChildUri(const UriComponents& baseUri, | |
123 const UriComponents& testedUri); | |
124 | |
125 std::string FlattenUri(const UriComponents& components, | |
126 size_t fromLevel = 0); | |
127 | |
128 #if ORTHANC_ENABLE_MD5 == 1 | |
129 void ComputeMD5(std::string& result, | |
130 const std::string& data); | |
131 | |
132 void ComputeMD5(std::string& result, | |
133 const void* data, | |
134 size_t size); | |
135 #endif | |
136 | |
137 void ComputeSHA1(std::string& result, | |
138 const std::string& data); | |
139 | |
140 void ComputeSHA1(std::string& result, | |
141 const void* data, | |
142 size_t size); | |
143 | |
144 bool IsSHA1(const void* str, | |
145 size_t size); | |
146 | |
147 bool IsSHA1(const std::string& s); | |
148 | |
149 #if ORTHANC_ENABLE_BASE64 == 1 | |
150 void DecodeBase64(std::string& result, | |
151 const std::string& data); | |
152 | |
153 void EncodeBase64(std::string& result, | |
154 const std::string& data); | |
155 | |
156 bool DecodeDataUriScheme(std::string& mime, | |
157 std::string& content, | |
158 const std::string& source); | |
159 | |
160 void EncodeDataUriScheme(std::string& result, | |
161 const std::string& mime, | |
162 const std::string& content); | |
163 #endif | |
164 | |
165 #if ORTHANC_ENABLE_LOCALE == 1 | |
166 std::string ConvertToUtf8(const std::string& source, | |
167 Encoding sourceEncoding, | |
168 bool hasCodeExtensions); | |
169 | |
170 std::string ConvertFromUtf8(const std::string& source, | |
171 Encoding targetEncoding); | |
172 #endif | |
173 | |
174 bool IsAsciiString(const void* data, | |
175 size_t size); | |
176 | |
177 bool IsAsciiString(const std::string& s); | |
178 | |
179 std::string ConvertToAscii(const std::string& source); | |
180 | |
181 std::string StripSpaces(const std::string& source); | |
182 | |
183 // In-place percent-decoding for URL | |
184 void UrlDecode(std::string& s); | |
185 | |
186 Endianness DetectEndianness(); | |
187 | |
188 std::string WildcardToRegularExpression(const std::string& s); | |
189 | |
190 void TokenizeString(std::vector<std::string>& result, | |
191 const std::string& source, | |
192 char separator); | |
193 | |
194 #if ORTHANC_ENABLE_PUGIXML == 1 | |
195 void JsonToXml(std::string& target, | |
196 const Json::Value& source, | |
197 const std::string& rootElement = "root", | |
198 const std::string& arrayElement = "item"); | |
199 #endif | |
200 | |
201 #if ORTHANC_ENABLE_PUGIXML == 1 | |
202 void XmlToString(std::string& target, | |
203 const pugi::xml_document& source); | |
204 #endif | |
205 | |
206 bool IsInteger(const std::string& str); | |
207 | |
208 void CopyJsonWithoutComments(Json::Value& target, | |
209 const Json::Value& source); | |
210 | |
211 bool StartsWith(const std::string& str, | |
212 const std::string& prefix); | |
213 | |
214 void UriEncode(std::string& target, | |
215 const std::string& source); | |
216 | |
217 std::string GetJsonStringField(const ::Json::Value& json, | |
218 const std::string& key, | |
219 const std::string& defaultValue); | |
220 | |
221 bool GetJsonBooleanField(const ::Json::Value& json, | |
222 const std::string& key, | |
223 bool defaultValue); | |
224 | |
225 int GetJsonIntegerField(const ::Json::Value& json, | |
226 const std::string& key, | |
227 int defaultValue); | |
228 | |
229 unsigned int GetJsonUnsignedIntegerField(const ::Json::Value& json, | |
230 const std::string& key, | |
231 unsigned int defaultValue); | |
232 | |
233 bool IsUuid(const std::string& str); | |
234 | |
235 bool StartsWithUuid(const std::string& str); | |
236 | |
237 #if ORTHANC_ENABLE_LOCALE == 1 | |
238 void InitializeGlobalLocale(const char* locale); | |
239 | |
240 void FinalizeGlobalLocale(); | |
241 | |
242 std::string ToUpperCaseWithAccents(const std::string& source); | |
243 #endif | |
244 | |
245 void InitializeOpenSsl(); | |
246 | |
247 void FinalizeOpenSsl(); | |
248 | |
249 std::string GenerateUuid(); | |
250 | |
251 std::string SubstituteVariables(const std::string& source, | |
252 const std::map<std::string, std::string>& dictionary); | |
253 | |
254 void RemoveIso2022EscapeSequences(std::string& dest, | |
255 const std::string& src); | |
256 | |
257 void Utf8ToUnicodeCharacter(uint32_t& unicode, | |
258 size_t& utf8Length, | |
259 const std::string& utf8, | |
260 size_t position); | |
261 | |
262 std::string LargeHexadecimalToDecimal(const std::string& hex); | |
263 | 263 |
264 // http://dicom.nema.org/medical/dicom/2019a/output/chtml/part05/sect_B.2.html | 264 // http://dicom.nema.org/medical/dicom/2019a/output/chtml/part05/sect_B.2.html |
265 std::string GenerateDicomPrivateUniqueIdentifier(); | 265 static std::string GenerateDicomPrivateUniqueIdentifier(); |
266 } | 266 }; |
267 } | 267 } |
268 | 268 |
269 | 269 |
270 | 270 |
271 | 271 |