Skip to content

Commit

Permalink
add sstring string_view constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwonko committed May 8, 2016
1 parent 1ee49cc commit 329ddc6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions code/qcommon/sstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#define SSTRING_H

#include "../qcommon/q_shared.h"
#include "qcommon/safe/gsl.h"
#include <algorithm>

template<int MaxSize>
class sstring
Expand Down Expand Up @@ -59,6 +61,15 @@ class sstring
//strcpy(mStorage.data,s);
Q_strncpyz(mStorage.data,s,sizeof(mStorage.data),qtrue);
}
sstring( const gsl::cstring_view& v )
{
if( v.size() + 1 > sizeof( mStorage.data ) )
{
Com_Error( ERR_FATAL, "String dest buffer too small (%d) to hold string of length %d", sizeof( mStorage.data ), v.size() );
}
std::copy( v.begin(), v.end(), mStorage.data );
mStorage.data[ v.size() ] = '\0';
}
sstring()
{
mStorage.data[0]=0;
Expand Down

0 comments on commit 329ddc6

Please sign in to comment.