Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 2513:97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Mar 2018 18:02:07 +0200 |
parents | 4dcafa8d6633 |
children | 0196d07a900f |
comparison
equal
deleted
inserted
replaced
2512:4dcafa8d6633 | 2513:97a74f0eac7a |
---|---|
101 | 101 |
102 | 102 |
103 | 103 |
104 namespace Orthanc | 104 namespace Orthanc |
105 { | 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 | |
106 void Toolbox::ToUpperCase(std::string& s) | 178 void Toolbox::ToUpperCase(std::string& s) |
107 { | 179 { |
108 std::transform(s.begin(), s.end(), s.begin(), toupper); | 180 std::transform(s.begin(), s.end(), s.begin(), toupper); |
109 } | 181 } |
110 | 182 |
1411 uuid_unparse ( uuid, s ); | 1483 uuid_unparse ( uuid, s ); |
1412 #endif | 1484 #endif |
1413 return s; | 1485 return s; |
1414 } | 1486 } |
1415 } | 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 } |