ATLAS Offline Software
Loading...
Searching...
No Matches
IdentifierFieldParser.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <string>
8#include <iostream>
9#include <charconv>
10#include <cctype>
11
12
13
14namespace Identifier{
15 bool
16 isDigit(const char c){
17 return std::isdigit(c) or c=='-' or c=='+';
18 }
19
21 parseStreamDigits(std::istream & is){
22 static constexpr std::errc ok{};
23 char buffer[20]{};
24 int i{};
26 for(int c{};isDigit(is.peek()) and i<20;++i ){
27 if (c == '+') is.ignore();
28 c=is.get();
29 buffer[i] = c;
30 }
31 const auto [ptr,ec] = std::from_chars(buffer, buffer+i, v);
32 if (ec != ok) throw std::invalid_argument("Invalid argument in parseStreamDigits");
33 return v;
34 }
35
37 parseStreamList(std::istream & is){
39 for (int c{};(not is.eof());c=is.peek()){
40 while (std::isspace(is.peek())){is.ignore();}
41 if (isDigit(c)){
42 if (c =='+') is.ignore();
43 int v = parseStreamDigits(is);
44 result.push_back(v);
45 } else if (c == ','){
46 is.ignore();
47 } else if (c == '/' ){
48 break;
49 }
50 }
51 return result;
52 }
53}
54
std::vector< element_type > element_vector
ExpandedIdentifier::element_type element_type
bool isDigit(const char c)
IdentifierField::element_type parseStreamDigits(std::istream &is)
IdentifierField::element_vector parseStreamList(std::istream &is)