kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #36339
[PATCH] 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.
---
common/lib_id.cpp | 71 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 32 deletions(-)
diff --git a/common/lib_id.cpp b/common/lib_id.cpp
index f7b57e5c6..44ec03548 100644
--- a/common/lib_id.cpp
+++ b/common/lib_id.cpp
@@ -388,29 +388,36 @@ 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 )
{
- const unsigned (&illegalChars)[ILL_CHAR_SIZE] =
- aType == ID_SCH ? schIllegalChars :
- aType == ID_ALIAS ? schAliasIllegalChars : pcbIllegalChars;
+ if( aUniChar < ' ' )
+ return false;
- for( const unsigned ch : illegalChars )
+ switch( aUniChar )
{
- if( ch == aUniChar )
- return false;
- }
-
- // Test for "printable" code (aUniChar is a unicode (32 bits) char, not a ASCII value )
- if( aUniChar < ' ' )
+ case '/':
+ case '\\':
return false;
+ case ':':
+ switch( aType )
+ {
+ case ID_SCH: return false;
+ case ID_ALIAS: return true;
+ case ID_PCB: return false;
+ }
+ break;
+
+ case ' ':
+ switch( aType )
+ {
+ case ID_SCH: return false;
+ case ID_ALIAS: return true;
+ case ID_PCB: return true;
+ }
+ break;
+ }
+
return true;
}
@@ -427,27 +434,27 @@ 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 )
{
- const unsigned (&illegalChars)[ILL_LIB_NICKNAME_CHAR_SIZE] =
- aType == ID_SCH ? schIllegalLibNicknameChars : pcbIllegalLibNicknameChars;
+ if( aUniChar < ' ' )
+ return false;
- for( const unsigned ch : illegalChars )
+ switch( aUniChar )
{
- if( ch == aUniChar )
- return false;
- }
-
- // Test for "printable" code (aUniChar is a unicode (32 bits) char, not a ASCII value )
- if( aUniChar < ' ' )
+ case '\\':
+ case ':':
return false;
+ case ' ':
+ switch( aType )
+ {
+ case ID_SCH: return false;
+ case ID_ALIAS: wxFAIL; return false;
+ case ID_PCB: return true;
+ }
+ break;
+ }
+
return true;
}
Follow ups