Rewrite test for valid characters in names
The ternary operator decays array arguments to pointers, so they can no longer be assigned to array references.
This commit is contained in:
parent
47c44b4d83
commit
d3deaf5ff5
|
@ -388,30 +388,29 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///> Set of characters not accepted library entry names.
|
|
||||||
#define BASE_ILLEGAL_CHARS '\t', '\n', '\r', '/', '\\'
|
|
||||||
const unsigned schIllegalChars[] = { BASE_ILLEGAL_CHARS, ':', ' ' };
|
|
||||||
const unsigned schAliasIllegalChars[] = { BASE_ILLEGAL_CHARS, 0, 0 };
|
|
||||||
const unsigned pcbIllegalChars[] = { BASE_ILLEGAL_CHARS, ':', 0 };
|
|
||||||
#define ILL_CHAR_SIZE (sizeof(schIllegalChars) / sizeof(int))
|
|
||||||
|
|
||||||
bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
|
bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
|
||||||
{
|
{
|
||||||
const unsigned (&illegalChars)[ILL_CHAR_SIZE] =
|
bool const colon_allowed = ( aType == ID_ALIAS );
|
||||||
aType == ID_SCH ? schIllegalChars :
|
bool const space_allowed = ( aType != ID_SCH );
|
||||||
aType == ID_ALIAS ? schAliasIllegalChars : pcbIllegalChars;
|
|
||||||
|
|
||||||
for( const unsigned ch : illegalChars )
|
|
||||||
{
|
|
||||||
if( ch == aUniChar )
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test for "printable" code (aUniChar is a unicode (32 bits) char, not a ASCII value )
|
|
||||||
if( aUniChar < ' ' )
|
if( aUniChar < ' ' )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
switch( aUniChar )
|
||||||
|
{
|
||||||
|
case '/':
|
||||||
|
case '\\':
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case ':':
|
||||||
|
return colon_allowed;
|
||||||
|
|
||||||
|
case ' ':
|
||||||
|
return space_allowed;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -427,28 +426,25 @@ unsigned LIB_ID::FindIllegalLibNicknameChar( const UTF8& aNickname, LIB_ID_TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///> Set of characters not accepted library nicknames which is different for item names.
|
|
||||||
#define BASE_ILLEGAL_LIB_NICKNAME_CHARS '\t', '\n', '\r', ':', '\\'
|
|
||||||
const unsigned schIllegalLibNicknameChars[] = { BASE_ILLEGAL_LIB_NICKNAME_CHARS, ' ' };
|
|
||||||
const unsigned pcbIllegalLibNicknameChars[] = { BASE_ILLEGAL_LIB_NICKNAME_CHARS, 0 };
|
|
||||||
#define ILL_LIB_NICKNAME_CHAR_SIZE ( sizeof( schIllegalLibNicknameChars ) / sizeof( unsigned ) )
|
|
||||||
|
|
||||||
bool LIB_ID::isLegalLibNicknameChar( unsigned aUniChar, LIB_ID_TYPE aType )
|
bool LIB_ID::isLegalLibNicknameChar( unsigned aUniChar, LIB_ID_TYPE aType )
|
||||||
{
|
{
|
||||||
const unsigned (&illegalChars)[ILL_LIB_NICKNAME_CHAR_SIZE] =
|
bool const space_allowed = ( aType != ID_SCH );
|
||||||
aType == ID_SCH ? schIllegalLibNicknameChars : pcbIllegalLibNicknameChars;
|
|
||||||
|
|
||||||
for( const unsigned ch : illegalChars )
|
|
||||||
{
|
|
||||||
if( ch == aUniChar )
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test for "printable" code (aUniChar is a unicode (32 bits) char, not a ASCII value )
|
|
||||||
if( aUniChar < ' ' )
|
if( aUniChar < ' ' )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
switch( aUniChar )
|
||||||
|
{
|
||||||
|
case '\\':
|
||||||
|
case ':':
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case ' ':
|
||||||
|
return space_allowed;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue