cwText,cwPianoScore : Added textCopy()

This commit is contained in:
kevin 2023-12-06 15:22:41 -05:00
parent 11cfb2cedc
commit b5eaa633ef
4 changed files with 43 additions and 7 deletions

View File

@ -167,7 +167,7 @@ namespace cw
goto errLabel;
}
strncpy(e->sci_pitch,sci_pitch,sizeof(e->sci_pitch));
strncpy(e->sci_pitch,sci_pitch,sizeof(e->sci_pitch)-1);
if( p->end == nullptr )
{
@ -570,16 +570,21 @@ namespace cw
goto errLabel;
}
textCopy( e->sci_pitch,sizeof(e->sci_pitch),sci_pitch);
textCopy( e->dmark,sizeof(e->dmark),dmark);
textCopy( e->grace_mark, sizeof(e->grace_mark),grace_mark);
/*
if( sci_pitch != nullptr )
strncpy(e->sci_pitch,sci_pitch,sizeof(e->sci_pitch));
strncpy(e->sci_pitch,sci_pitch,sizeof(e->sci_pitch)-1);
if( dmark != nullptr )
strncpy(e->dmark,dmark,sizeof(e->dmark));
strncpy(e->dmark,dmark,sizeof(e->dmark)-1);
if( grace_mark != nullptr )
strncpy(e->grace_mark,grace_mark,sizeof(e->grace_mark));
strncpy(e->grace_mark,grace_mark,sizeof(e->grace_mark)-1);
*/
// assign the UID
e->uid = i;

View File

@ -263,7 +263,7 @@ namespace cw
rc_t _parse_note_on_row( score_parse_t* p, csv::handle_t csvH, event_t* e )
{
rc_t rc,rc0,rc1,rc2;
rc_t rc,rc0=kOkRC,rc1=kOkRC,rc2=kOkRC;
const char* sciPitch = nullptr;
const char* dmark = nullptr;
const char* graceLabel = nullptr;

View File

@ -54,6 +54,30 @@ namespace cw
unsigned cw::textLength( const char* s )
{ return s == nullptr ? 0 : strlen(s); }
const char* cw::textCopy( char* dst, unsigned dstN, const char* src, unsigned srcN )
{
if( dst == nullptr || dstN == 0 )
return nullptr;
if( srcN == 0 )
srcN = textLength(src);
if( src == nullptr || srcN==0 || dstN==1 )
{
dst[0] = 0;
}
else
{
assert( dstN >= 2 );
unsigned n = std::min( dstN-1, srcN );
memcpy(dst,src,n);
dst[n] = 0;
}
return dst;
}
void textToLower( char* s )
{
if( s != nullptr )

View File

@ -7,6 +7,13 @@ namespace cw
// Return 0 if s is null.
unsigned textLength( const char* s );
// If dst is non-null then dst is always 0-terminated.
// If src will be truncated if srcN > dstN-1.
// If dst is null then null is returned
// if src is null then dst[0] = 0.
// if srcN is 0 then textLength(src) is used for srcN
const char* textCopy( char* dst, unsigned dstN, const char* src, unsigned srcN=0 );
void textToLower( char* s );
void textToUpper( char* s );