comparison Resources/Orthanc/Core/Toolbox.cpp @ 206:795d71f66f31

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Mar 2018 10:09:03 +0200
parents 03afbee0cc7b
children
comparison
equal deleted inserted replaced
205:886230938339 206:795d71f66f31
85 # include "ChunkedBuffer.h" 85 # include "ChunkedBuffer.h"
86 # include <pugixml.hpp> 86 # include <pugixml.hpp>
87 #endif 87 #endif
88 88
89 89
90 // Inclusions for UUID
91 // http://stackoverflow.com/a/1626302
92
93 extern "C"
94 {
95 #if defined(_WIN32)
96 # include <rpc.h>
97 #else
98 # include <uuid/uuid.h>
99 #endif
100 }
101
102
103
90 namespace Orthanc 104 namespace Orthanc
91 { 105 {
106 void Toolbox::LinesIterator::FindEndOfLine()
107 {
108 lineEnd_ = lineStart_;
109
110 while (lineEnd_ < content_.size() &&
111 content_[lineEnd_] != '\n' &&
112 content_[lineEnd_] != '\r')
113 {
114 lineEnd_ += 1;
115 }
116 }
117
118
119 Toolbox::LinesIterator::LinesIterator(const std::string& content) :
120 content_(content),
121 lineStart_(0)
122 {
123 FindEndOfLine();
124 }
125
126
127 bool Toolbox::LinesIterator::GetLine(std::string& target) const
128 {
129 assert(lineStart_ <= content_.size() &&
130 lineEnd_ <= content_.size() &&
131 lineStart_ <= lineEnd_);
132
133 if (lineStart_ == content_.size())
134 {
135 return false;
136 }
137 else
138 {
139 target = content_.substr(lineStart_, lineEnd_ - lineStart_);
140 return true;
141 }
142 }
143
144
145 void Toolbox::LinesIterator::Next()
146 {
147 lineStart_ = lineEnd_;
148
149 if (lineStart_ != content_.size())
150 {
151 assert(content_[lineStart_] == '\r' ||
152 content_[lineStart_] == '\n');
153
154 char second;
155
156 if (content_[lineStart_] == '\r')
157 {
158 second = '\n';
159 }
160 else
161 {
162 second = '\r';
163 }
164
165 lineStart_ += 1;
166
167 if (lineStart_ < content_.size() &&
168 content_[lineStart_] == second)
169 {
170 lineStart_ += 1;
171 }
172
173 FindEndOfLine();
174 }
175 }
176
177
92 void Toolbox::ToUpperCase(std::string& s) 178 void Toolbox::ToUpperCase(std::string& s)
93 { 179 {
94 std::transform(s.begin(), s.end(), s.begin(), toupper); 180 std::transform(s.begin(), s.end(), s.begin(), toupper);
95 } 181 }
96 182
1374 std::wstring w = boost::locale::conv::utf_to_utf<wchar_t>(source); 1460 std::wstring w = boost::locale::conv::utf_to_utf<wchar_t>(source);
1375 w = boost::algorithm::to_upper_copy<std::wstring>(w, *globalLocale_); 1461 w = boost::algorithm::to_upper_copy<std::wstring>(w, *globalLocale_);
1376 return boost::locale::conv::utf_to_utf<char>(w); 1462 return boost::locale::conv::utf_to_utf<char>(w);
1377 } 1463 }
1378 #endif 1464 #endif
1465
1466
1467 std::string Toolbox::GenerateUuid()
1468 {
1469 #ifdef WIN32
1470 UUID uuid;
1471 UuidCreate ( &uuid );
1472
1473 unsigned char * str;
1474 UuidToStringA ( &uuid, &str );
1475
1476 std::string s( ( char* ) str );
1477
1478 RpcStringFreeA ( &str );
1479 #else
1480 uuid_t uuid;
1481 uuid_generate_random ( uuid );
1482 char s[37];
1483 uuid_unparse ( uuid, s );
1484 #endif
1485 return s;
1486 }
1379 } 1487 }
1488
1489
1490
1491 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content)
1492 {
1493 return reinterpret_cast<OrthancLinesIterator*>(new Orthanc::Toolbox::LinesIterator(content));
1494 }
1495
1496
1497 bool OrthancLinesIterator_GetLine(std::string& target,
1498 const OrthancLinesIterator* iterator)
1499 {
1500 if (iterator != NULL)
1501 {
1502 return reinterpret_cast<const Orthanc::Toolbox::LinesIterator*>(iterator)->GetLine(target);
1503 }
1504 else
1505 {
1506 return false;
1507 }
1508 }
1509
1510
1511 void OrthancLinesIterator_Next(OrthancLinesIterator* iterator)
1512 {
1513 if (iterator != NULL)
1514 {
1515 reinterpret_cast<Orthanc::Toolbox::LinesIterator*>(iterator)->Next();
1516 }
1517 }
1518
1519
1520 void OrthancLinesIterator_Free(OrthancLinesIterator* iterator)
1521 {
1522 if (iterator != NULL)
1523 {
1524 delete reinterpret_cast<const Orthanc::Toolbox::LinesIterator*>(iterator);
1525 }
1526 }