From 8394e2b71efa98c384f21e4c4bb1c30af7f360f6 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 20 Jun 2018 14:34:06 -0400 Subject: [PATCH] Fix broken LIB_ID library nickname illegal character tests. During the symbol library table implementation, the legal character tests for the footprint library table were changed and the forward slash '/' character became illegal. This change broke editing some users footprint library tables that already had '/' in library table nicknames. This change split the library nickname and library item name illegal character tests. --- common/lib_id.cpp | 53 +++++++++++++++++------ eeschema/dialogs/dialog_sym_lib_table.cpp | 2 +- include/lib_id.h | 22 +++++++--- pcbnew/dialogs/dialog_fp_lib_table.cpp | 2 +- 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/common/lib_id.cpp b/common/lib_id.cpp index f92d3ce314..b10a82ce1f 100644 --- a/common/lib_id.cpp +++ b/common/lib_id.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 2010-2017 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2010-2018 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -385,19 +385,7 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType ) } -unsigned LIB_ID::FindIllegalChar( const UTF8& aNickname, LIB_ID_TYPE aType ) -{ - for( unsigned ch : aNickname ) - { - if( !isLegalChar( ch, aType ) ) - return ch; - } - - return 0; -} - - -///> Set of characters not accepted in library and entry names +///> Set of characters not accepted library entry names. #define BASE_ILLEGAL_CHARS '\t', '\n', '\r', ':', '/', '\\' const unsigned schIllegalChars[] = { BASE_ILLEGAL_CHARS, ' ' }; const unsigned pcbIllegalChars[] = { BASE_ILLEGAL_CHARS, 0 }; @@ -422,6 +410,43 @@ bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType ) } +unsigned LIB_ID::FindIllegalLibNicknameChar( const UTF8& aNickname, LIB_ID_TYPE aType ) +{ + for( unsigned ch : aNickname ) + { + if( !isLegalLibNicknameChar( ch, aType ) ) + return ch; + } + + return 0; +} + + +///> 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; + + 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 < ' ' ) + return false; + + return true; +} + + #if 0 && defined(DEBUG) // build this with Debug CMAKE_BUILD_TYPE diff --git a/eeschema/dialogs/dialog_sym_lib_table.cpp b/eeschema/dialogs/dialog_sym_lib_table.cpp index a61596e1fc..5c1105eb64 100644 --- a/eeschema/dialogs/dialog_sym_lib_table.cpp +++ b/eeschema/dialogs/dialog_sym_lib_table.cpp @@ -268,7 +268,7 @@ bool DIALOG_SYMBOL_LIB_TABLE::verifyTables() // button. model.DeleteRows( r, 1 ); } - else if( ( illegalCh = LIB_ID::FindIllegalChar( nick, LIB_ID::ID_SCH ) ) ) + else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_SCH ) ) ) { wxString msg = wxString::Format( _( "Illegal character \"%c\" found in Nickname: \"%s\" in row %d" ), diff --git a/include/lib_id.h b/include/lib_id.h index 3b17789e13..052f415904 100644 --- a/include/lib_id.h +++ b/include/lib_id.h @@ -3,7 +3,7 @@ * * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 2010-2017 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2010-2018 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -223,25 +223,35 @@ public: static UTF8 FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType ); /** - * Looks for characters that are illegal in library and item names. + * Looks for characters that are illegal in library nicknames. * * @param aNickname is the logical library name to be tested. * @param aType is the library identifier type * @return Invalid character found in the name or 0 is the name is valid. */ - static unsigned FindIllegalChar( const UTF8& aNickname, LIB_ID_TYPE aType ); + static unsigned FindIllegalLibNicknameChar( const UTF8& aNickname, LIB_ID_TYPE aType ); #if defined(DEBUG) static void Test(); #endif protected: - /** Tests whether a unicode character is a legal LIB_ID character - * note: aUniChar is expected to be a unicode 32 bits char, not a UTF8 char, that use - * a variable lenght coding value + /** + * Tests whether a unicode character is a legal LIB_ID item name character + * + * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use + * a variable length coding value. */ static bool isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType ); + /** + * Tests whether a unicode character is a legal LIB_ID library nickname character + * + * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use + * a variable length coding value. + */ + static bool isLegalLibNicknameChar( unsigned aUniChar, LIB_ID_TYPE aType ); + UTF8 nickname; ///< The nickname of the library or empty. UTF8 item_name; ///< The name of the entry in the logical library. UTF8 revision; ///< The revision of the entry. diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index d41562a96b..11909fe617 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -353,7 +353,7 @@ private: // button. model.DeleteRows( r, 1 ); } - else if( ( illegalCh = LIB_ID::FindIllegalChar( nick, LIB_ID::ID_PCB ) ) ) + else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) ) { wxString msg = wxString::Format( _( "Illegal character \"%c\" found in Nickname: \"%s\" in row %d" ),