From 2cf3a6d7bef6f20bea35062dd3d4dbf0aec9efb5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Jul 2006 22:46:31 +0000 Subject: [PATCH] don't create non-existing groups in HasEntry() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40096 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/fileconf.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 8078b6f5d4..a3bcdb5983 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -889,12 +889,44 @@ bool wxFileConfig::HasGroup(const wxString& strName) const return rc; } -bool wxFileConfig::HasEntry(const wxString& strName) const +bool wxFileConfig::HasEntry(const wxString& entry) const { - wxConfigPathChanger path(this, strName); + // path is the part before the last "/" + wxString path = entry.BeforeLast(wxCONFIG_PATH_SEPARATOR); - wxFileConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name()); - return pEntry != NULL; + // except in the special case of "/keyname" when there is nothing before "/" + if ( path.empty() && *entry.c_str() == wxCONFIG_PATH_SEPARATOR ) + { + path = wxCONFIG_PATH_SEPARATOR; + } + + // change to the path of the entry if necessary and remember the old path + // to restore it later + wxString pathOld; + wxFileConfig * const self = wx_const_cast(wxFileConfig *, this); + if ( !path.empty() ) + { + pathOld = GetPath(); + if ( pathOld.empty() ) + pathOld = wxCONFIG_PATH_SEPARATOR; + + if ( !self->DoSetPath(path, false /* don't create if doesn't exist */) ) + { + return false; + } + } + + // check if the entry exists in this group + const bool exists = m_pCurrentGroup->FindEntry( + entry.AfterLast(wxCONFIG_PATH_SEPARATOR)) != NULL; + + // restore the old path if we changed it above + if ( !pathOld.empty() ) + { + self->SetPath(pathOld); + } + + return exists; } // ----------------------------------------------------------------------------