/src/trafficserver/include/tsutil/ts_time_parser.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | Parse strings with units. |
4 | | |
5 | | @section license License |
6 | | |
7 | | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. |
8 | | See the NOTICE file distributed with this work for additional information regarding copyright |
9 | | ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the |
10 | | "License"); you may not use this file except in compliance with the License. You may obtain a |
11 | | copy of the License at |
12 | | |
13 | | http://www.apache.org/licenses/LICENSE-2.0 |
14 | | |
15 | | Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | or implied. See the License for the specific language governing permissions and limitations under |
18 | | the License. |
19 | | */ |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include "tsutil/ts_unit_parser.h" |
24 | | |
25 | | namespace ts |
26 | | { |
27 | | |
28 | | namespace detail |
29 | | { |
30 | | extern UnitParser const time_parser_ns; |
31 | | } |
32 | | /** Parse duration string. |
33 | | * |
34 | | * @param text Input text to parse. |
35 | | * @return A return value containing the time in nanoseconds or parsing errors. |
36 | | */ |
37 | | inline swoc::Rv<std::chrono::nanoseconds> |
38 | | time_parser(swoc::TextView text) |
39 | 0 | { |
40 | 0 | auto &&[duration, errata] = detail::time_parser_ns(text); |
41 | 0 | return {std::chrono::nanoseconds(duration), std::move(errata)}; |
42 | 0 | } |
43 | | } // namespace ts |