@@ -114,33 +114,52 @@ ROOT::CmdLine::GetMatchingPathsInFile(std::string_view fileName, std::string_vie
114114 return source;
115115}
116116
117- ROOT::CmdLine::RootSource ROOT::CmdLine::ParseRootSource (std::string_view sourceRaw, std::uint32_t flags)
117+ ROOT::RResult<std::pair<std::string_view, std::string_view>>
118+ ROOT::CmdLine::SplitIntoFileNameAndPattern (std::string_view sourceRaw)
118119{
119- ROOT::CmdLine::RootSource source;
120- const char *str = sourceRaw.data ();
121-
122- // Handle known URI prefixes
123- static const char *const specialPrefixes[] = {" http" , " https" , " root" , " gs" , " s3" };
124- for (const char *prefix : specialPrefixes) {
125- const auto prefixLen = strlen (prefix);
126- if (strncmp (str, prefix, prefixLen) == 0 && strncmp (str + prefixLen, " ://" , 3 ) == 0 ) {
127- source.fFileName = std::string (prefix) + " ://" ;
128- str += prefixLen + 3 ;
129- break ;
120+ auto prefixIdx = sourceRaw.find (" ://" );
121+ std::string_view::size_type separatorIdx = 0 ;
122+ if (prefixIdx != std::string_view::npos) {
123+ bool prefixFound = false ;
124+ // Handle known URI prefixes
125+ static const char *const specialPrefixes[] = {" http" , " https" , " root" , " gs" , " s3" };
126+ auto prefix = sourceRaw.substr (0 , prefixIdx);
127+ for (std::string_view knownPrefix : specialPrefixes) {
128+ if (prefix == knownPrefix) {
129+ prefixFound = true ;
130+ break ;
131+ }
132+ }
133+ if (!prefixFound) {
134+ return R__FAIL (" unknown file protocol" );
130135 }
136+ separatorIdx = sourceRaw.substr (prefixIdx + 3 ).find_first_of (' :' );
137+ if (separatorIdx != std::string_view::npos)
138+ separatorIdx += prefixIdx + 3 ;
139+ } else {
140+ separatorIdx = sourceRaw.find_first_of (' :' );
131141 }
132142
133- auto tokens = ROOT::Split (str, " :" );
134- if (tokens.empty ())
135- return source;
143+ if (separatorIdx != std::string_view::npos) {
144+ return {{sourceRaw.substr (0 , separatorIdx), sourceRaw.substr (separatorIdx + 1 )}};
145+ }
146+ return {{sourceRaw, std::string_view{}}};
147+ }
136148
137- source.fFileName += tokens[0 ];
138- if (tokens.size () > 1 ) {
139- source = ROOT::CmdLine::GetMatchingPathsInFile (source.fFileName , tokens[1 ], flags);
140- } else {
141- source = ROOT::CmdLine::GetMatchingPathsInFile (source.fFileName , " " , flags);
149+ ROOT::CmdLine::RootSource ROOT::CmdLine::ParseRootSource (std::string_view sourceRaw, std::uint32_t flags)
150+ {
151+ ROOT::CmdLine::RootSource source;
152+
153+ auto res = SplitIntoFileNameAndPattern (sourceRaw);
154+ if (!res) {
155+ source.fErrors .push_back (res.GetError ()->GetReport ());
156+ return source;
142157 }
143158
159+ auto [fileName, tokens] = res.Unwrap ();
160+ source = ROOT::CmdLine::GetMatchingPathsInFile (fileName, tokens, flags);
161+
162+ assert (source.fErrors .empty () == !!source.fObjectTree .fFile );
144163 return source;
145164}
146165
0 commit comments