function status = iscvar(s)
%ISCVAR True for valid C variables.
%    For a string S, ISCVAR(S) is 1 for alphanumeric variables starting
%    with [_a-zA-Z] and 0 otherwise. 

% Copyright 2012-2018 The MathWorks, Inc.

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% Important:
% This file is a copy of toolbox\simulink\simulink\iscvar.m
% Changes made to the original code: comments; addressed MLint warnings;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
s = convertStringsToChars(s);

status = 0;

% Must be at least 1 character
if numel(s) == 0
   return
end

% First character must be [_A-Za-z]
if ~isletter(s(1)) && ~strcmp(s(1), '_')
   return
end

persistent asciitable
if isempty(asciitable)
   asciitable = false(1,122); 
   asciitable(48:57) = true;
   asciitable(65:90) = true;
   asciitable(95) = true;
   asciitable(97:122) = true;
end

% Everything else must be alphanumeric
ds = double(s);
if all( ds < 123 ) && all( asciitable(ds) )
    status = 1;
end
