Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/CStringMatcher.cpp @ 5853:4d932683049d get-scu tip
very first implementation of C-Get SCU
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 29 Oct 2024 17:25:49 +0100 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
4652
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4652
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * the License, or (at your option) any later version. |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * Lesser General Public License for more details. |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * License along with this program. If not, see |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 **/ |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../PrecompiledHeaders.h" |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "CStringMatcher.h" |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include "../OrthancException.h" |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include <boost/algorithm/searching/boyer_moore.hpp> |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 namespace Orthanc |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 class CStringMatcher::Search : public boost::noncopyable |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 private: |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 typedef boost::algorithm::boyer_moore<const char*> Algorithm; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 Algorithm algorithm_; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 public: |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 // WARNING - The lifetime of "pattern_" must be larger than |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 // "search_", as the latter internally keeps a pointer to "pattern" (*) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 explicit Search(const std::string& pattern) : |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 algorithm_(pattern.c_str(), pattern.c_str() + pattern.size()) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 const char* Apply(const char* start, |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 const char* end) const |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 #if BOOST_VERSION >= 106200 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 return algorithm_(start, end).first; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 #else |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 return algorithm_(start, end); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 #endif |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 }; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 CStringMatcher::CStringMatcher(const std::string& pattern) : |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 pattern_(pattern), |
4657 | 64 valid_(false), |
65 matchBegin_(NULL), | |
66 matchEnd_(NULL) | |
4652
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 // WARNING - Don't use "pattern" (local variable, will be |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 // destroyed once exiting the constructor) but "pattern_" |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 // (variable member, will last as long as the algorithm), |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 // otherwise lifetime is bad! (*) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 search_.reset(new Search(pattern_)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 const std::string& CStringMatcher::GetPattern() const |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 return pattern_; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 bool CStringMatcher::IsValid() const |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 return valid_; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 bool CStringMatcher::Apply(const char* start, |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 const char* end) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 assert(search_.get() != NULL); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 if (start > end) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 throw OrthancException(ErrorCode_ParameterOutOfRange); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 matchBegin_ = search_->Apply(start, end); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 if (matchBegin_ == end) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 valid_ = false; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 else |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 matchEnd_ = matchBegin_ + pattern_.size(); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 assert(matchEnd_ <= end); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 valid_ = true; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 return valid_; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 bool CStringMatcher::Apply(const std::string& corpus) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 if (corpus.empty()) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 return false; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 else |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 return Apply(corpus.c_str(), corpus.c_str() + corpus.size()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 const char* CStringMatcher::GetMatchBegin() const |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 if (valid_) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 return matchBegin_; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 else |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 const char* CStringMatcher::GetMatchEnd() const |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 if (valid_) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 return matchEnd_; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 else |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 } |