1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
//------------------------------------------------------------------------------
// gb_mxstring_to_string: copy a built-in string into a C string
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// The string is converted to lower case, so that all input strings to the
// SuiteSparse:GraphBLAS interface are case-insensitive.
#include "gb_interface.h"
void gb_mxstring_to_string // copy a built-in string into a C string
(
char *string, // size at least maxlen+1
const size_t maxlen, // length of string
const mxArray *S, // built-in mxArray containing a string
const char *name // name of the mxArray
)
{
size_t len = 0 ;
string [0] = '\0' ;
if (S != NULL && mxGetNumberOfElements (S) > 0)
{
if (!mxIsChar (S))
{
ERROR2 ("%s must be a string", name) ;
}
len = mxGetNumberOfElements (S) ;
if (len > 0)
{
mxGetString (S, string, maxlen) ;
string [maxlen] = '\0' ;
// convert the string to lower case
for (int k = 0 ; k < maxlen && string [k] != '\0' ; k++)
{
string [k] = tolower (string [k]) ;
}
}
}
}
|