Skip to content

Commit

Permalink
Added Q::sscanf string reading (like %s)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwonko committed Nov 3, 2015
1 parent fe8ad95 commit 34dc437
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shared/qcommon/safe/sscanf.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ namespace Q
}
}

// Whitespace-terminated string
template< typename... Tail >
std::size_t sscanf_impl( const gsl::cstring_view& input, const std::size_t accumulator, gsl::cstring_view& string, Tail&&... tail )
{
// skip leading whitespace
auto begin = skipWhitespace( input.begin(), input.end() );
// string is whitespace-terminated
auto end = std::find_if< gsl::cstring_view::const_iterator, int( *)( int ) >(
begin, input.end(),
std::isspace
);
if( begin == end )
{
// empty string is not accepted
return accumulator;
}
string = { begin, end };
return sscanf_impl( { end, input.end() }, accumulator + 1, std::forward< Tail >( tail )... );
}

/**
A non-owning stream buffer; for adapting a gsl::cstring_view to std::istream
*/
Expand Down

0 comments on commit 34dc437

Please sign in to comment.