![]() |
|
|||
File indexing completed on 2025-08-28 08:27:10
0001 // Licensed to the Apache Software Foundation (ASF) under one 0002 // or more contributor license agreements. See the NOTICE file 0003 // distributed with this work for additional information 0004 // regarding copyright ownership. The ASF licenses this file 0005 // to you under the Apache License, Version 2.0 (the 0006 // "License"); you may not use this file except in compliance 0007 // with the License. You may obtain a copy of the License at 0008 // 0009 // http://www.apache.org/licenses/LICENSE-2.0 0010 // 0011 // Unless required by applicable law or agreed to in writing, 0012 // software distributed under the License is distributed on an 0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 0014 // KIND, either express or implied. See the License for the 0015 // specific language governing permissions and limitations 0016 // under the License. 0017 0018 #pragma once 0019 0020 #include <cassert> 0021 #include <initializer_list> 0022 #include <regex> 0023 #include <string_view> 0024 #include <type_traits> 0025 0026 #include "arrow/util/visibility.h" 0027 0028 namespace arrow { 0029 namespace internal { 0030 0031 /// Match regex against target and produce string_views out of matches. 0032 inline bool RegexMatch(const std::regex& regex, std::string_view target, 0033 std::initializer_list<std::string_view*> out_matches) { 0034 assert(regex.mark_count() == out_matches.size()); 0035 0036 std::match_results<decltype(target.begin())> match; 0037 if (!std::regex_match(target.begin(), target.end(), match, regex)) { 0038 return false; 0039 } 0040 0041 // Match #0 is the whole matched sequence 0042 assert(regex.mark_count() + 1 == match.size()); 0043 auto out_it = out_matches.begin(); 0044 for (size_t i = 1; i < match.size(); ++i) { 0045 **out_it++ = target.substr(match.position(i), match.length(i)); 0046 } 0047 return true; 0048 } 0049 0050 } // namespace internal 0051 } // namespace arrow
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |