std::bitset<N> bitset_ctor (std::bitset<N>*, std::basic_string<charT, Traits, Allocator> *p, const char *str, std::size_t pos, std::size_t n) { charT wstr [1024]; for (std::size_t i = 0; i != sizeof wstr / sizeof *wstr; ++i) { if (str [i]) Traits::assign (wstr [i], make_char (str [i], (charT*)0)); else { Traits::assign (wstr [i], charT ()); break; } } typedef std::bitset<N> Bitset; typedef std::basic_string<charT, Traits, Allocator> String; if (p) { // use one of the const basic_string& overloads const String bstr (wstr); return bitset_ctor ((Bitset*)0, &bstr, 0, pos, n, (charT*)0); } else { // invoke one of the const charT* overloads return bitset_ctor ((Bitset*)0, (String*)0, wstr, pos, n, (charT*)0); } }
void test_long_double (charT, const char *cname) { if (rw_enabled ("long double")) test_get (charT (0 /* long double argument */), cname, "long double"); else rw_note (0, __FILE__, __LINE__, "long double test disabled"); }
void test_string (charT, const char *cname) { if (rw_enabled ("basic_string")) test_get (charT (1 /* basic_string argument */), cname, "basic_string"); else rw_note (0, __FILE__, __LINE__, "basic_string<%s> test disabled", cname); }
stringT pws_os::getprocessid() { #ifdef UNICODE std::wostringstream os; #else std::ostringstream os; #endif os.width(8); os.fill(charT('0')); os << getpid(); return os.str(); }
void print_cpp_char(charT c) { #ifndef BOOST_NO_STD_LOCALE std::locale l; const std::collate<charT>& col = BOOST_USE_FACET(std::collate<charT>, l); std::basic_string<charT> result = col.transform(&c, &c+1); std::cout << result.size() << " "; print_string(result); std::size_t n = result.find(charT(0)); if(n != std::basic_string<charT>::npos) { std::cerr << "(Error in location of null, found: " << n << ")"; } #endif }
void test_string_ctor (std::bitset<N>*, std::basic_string<charT, Traits, Allocator> *p, int line, const char *str, std::size_t pos, std::size_t n, const char *bitstr) { static const char* const tpfx = type_prefix (charT ()); typedef std::bitset<N> Bitset; typedef std::basic_string<charT, Traits, Allocator> String; static const char* const exstr[] = { "failed to throw", "caught std::invalid_argument", "caught std::out_of_range", "caught unknown exception" }; // compute which exception, if any, the ctor is expected to throw const int except = bitstr - (char*)0 < 3 ? bitstr - (char*)0 : 0; if (except && opt_no_exceptions) return; int caught = 0; _TRY { // invoke one of the overloads of the constructor const Bitset bset = bitset_ctor ((Bitset*)0, p, str, pos, n); if (!except) rw_assert (!bcmp (bset, bitstr), 0, line, "line %d: bitset<%u>::bitset(%s\"%s\"" "%{?}, %zu%{?}, %zu%{;}%{;}) " "== { %s }, got { %{.*b} }", __LINE__, N, tpfx, str, pos != std::size_t (-1), pos, n != std::size_t (-1), n, bitstr, int (N), &bset); } #ifndef _RWSTD_NO_EXCEPTIONS catch (const std::out_of_range&) {
stringT pws_os::getenv(const char *env, bool is_path) { assert(env != NULL); stringT retval; char *value = std::getenv(env); if (value != NULL) { #ifdef UNICODE retval = pws_os::towc(value); #else retval = value; #endif if (is_path) { // make sure path has trailing '\' if (retval[retval.length()-1] != charT('/')) retval += _S("/"); } // is_path } // value != NULL return retval; }
void print_c_info(charT, const char* name) { std::cout << "Info for " << name << " C API's:" << std::endl; std::cout << " \"a\" : "; print_c_char(charT('a')); std::cout << std::endl; std::cout << " \"A\" : "; print_c_char(charT('A')); std::cout << std::endl; std::cout << " \"z\" : "; print_c_char(charT('z')); std::cout << std::endl; std::cout << " \"Z\" : "; print_c_char(charT('Z')); std::cout << std::endl; std::cout << " \";\" : "; print_c_char(charT(';')); std::cout << std::endl; std::cout << " \"{\" : "; print_c_char(charT('{')); std::cout << std::endl; }
bool PerformConfigMigration() { /** * * We're here after the application's started and the conditions * listed above (in OfferConfigMigration) hold. * This constrains what we can assume and what we have to check. */ ASSERT(OfferConfigMigration()); // should not be here otherwise! if (!OfferConfigMigration()) return false; // I mean it! PWSprefs::ConfigOption configoption; // Note value meaningless at this point! std::wstring wsCnfgFile = PWSprefs::GetConfigFile(configoption); const std::wstring wsExecDir = pws_os::getexecdir(); const std::wstring wsUserCfgDir = pws_os::getuserprefsdir(); if (wsUserCfgDir.empty()) // couldn't find or create !? return false; std::wstring wsDefaultCfgFile = wsUserCfgDir + PWSprefs::cfgFileName; std::wstring wsExecDirCfgFile = wsExecDir + PWSprefs::cfgFileName; bool bRetVal(false); bool bExecCFRO(false); pws_os::FileExists(wsExecDirCfgFile, bExecCFRO); /** * MIGRATE **/ bRetVal = false; bool bNoMoreNodes(false); CXMLprefs newXMLConfig(wsExecDirCfgFile.c_str()); // for migrating user/host to new CXMLprefs oldXMLConfig(wsExecDirCfgFile.c_str()); // for removing user/host from old // Create the new one from it just containing our host/user if (!newXMLConfig.XML_Load()) return false; // WTF?!? const SysInfo *si = SysInfo::GetInstance(); stringT hn = si->GetEffectiveHost(); PWSprefs::XMLify(charT('H'), hn); stringT un = si->GetEffectiveUser(); PWSprefs::XMLify(charT('u'), un); stringT csHKCU_PREF = _T("Pwsafe_Settings\\"); csHKCU_PREF += hn.c_str(); csHKCU_PREF += _T("\\"); csHKCU_PREF += un.c_str(); csHKCU_PREF += _T("\\Preferences"); bool rc = newXMLConfig.MigrateSettings(wsDefaultCfgFile, hn, un); if (rc) { // That worked, now remove us from the old one config file // in the Installation directory newXMLConfig.Unlock(); // Since we now have new config file, remove host/user from old. if (!oldXMLConfig.XML_Load()) { rc = false; if (!oldXMLConfig.getReason().empty()) { CGeneralMsgBox gmb; gmb.SetMsg(oldXMLConfig.getReason().c_str()); gmb.AddButton(IDS_CONTINUE, IDS_CONTINUE); gmb.AddButton(IDS_EXIT, IDS_EXIT, TRUE, TRUE); if (gmb.DoModal() == IDS_EXIT) { goto exit; } // Problem loading XML file but user says continue rather than Exit PWS! // But we will not remove them from the old file and we will // delete the new file - better luck next time! pws_os::DeleteAFile(wsDefaultCfgFile); } } // Load failed // Now remove this hostname/username from old configuration file in the // installation directory (as long as everything OK and it is not R-O) if (rc && !bExecCFRO) { rc = oldXMLConfig.RemoveHostnameUsername(hn, un, bNoMoreNodes); if (rc) { oldXMLConfig.XML_Store(csHKCU_PREF); // However, if no more host/user nodes in this file - delete the // configuration file from the installation directory! if (bNoMoreNodes) { pws_os::DeleteAFile(wsExecDirCfgFile); } bRetVal = true; } // RemoveHostnameUsername } // rc && !bExecCFRO } // MigrateSettings // If this all worked, now copy autoload_filters.xml if it exists and not // already in the new location. // This is ONLY done when we migrate the user's settings. if (bRetVal == true) { bool bALFRO(false); std::wstring wsOldAutoLoadFilters = wsExecDir + L"autoload_filters.xml"; std::wstring wsNewAutoLoadFilters = wsUserCfgDir + L"autoload_filters.xml"; if (pws_os::FileExists(wsOldAutoLoadFilters, bALFRO) && !pws_os::FileExists(wsNewAutoLoadFilters)) { bool bCopyAutoloadFilters = pws_os::CopyAFile(wsOldAutoLoadFilters, wsNewAutoLoadFilters); // If we have copied it, there are no more nodes in the old configuration file // and it isn't read only - delete it from the installation directory if (bCopyAutoloadFilters && bNoMoreNodes && !bALFRO) pws_os::DeleteAFile(wsOldAutoLoadFilters); } } // Migration all done! exit: // Clean up newXMLConfig.Unlock(); oldXMLConfig.Unlock(); // Set config file if (bRetVal) PWSprefs::SetConfigFile(wsDefaultCfgFile); return bRetVal; }
iterator BOOST_REGEX_CALL re_is_set_member(iterator next, iterator last, const re_set_long<char_classT>* set_, const regex_data<charT, traits_type>& e, bool icase) { const charT* p = reinterpret_cast<const charT*>(set_+1); iterator ptr; unsigned int i; //bool icase = e.m_flags & regex_constants::icase; if(next == last) return next; typedef typename traits_type::string_type traits_string_type; const ::boost::regex_traits_wrapper<traits_type>& traits_inst = *(e.m_ptraits); // dwa 9/13/00 suppress incorrect MSVC warning - it claims this is never // referenced (void)traits_inst; // try and match a single character, could be a multi-character // collating element... for(i = 0; i < set_->csingles; ++i) { ptr = next; if(*p == static_cast<charT>(0)) { // treat null string as special case: if(traits_inst.translate(*ptr, icase) != *p) { while(*p == static_cast<charT>(0))++p; continue; } return set_->isnot ? next : (ptr == next) ? ++next : ptr; } else { while(*p && (ptr != last)) { if(traits_inst.translate(*ptr, icase) != *p) break; ++p; ++ptr; } if(*p == static_cast<charT>(0)) // if null we've matched return set_->isnot ? next : (ptr == next) ? ++next : ptr; p = re_skip_past_null(p); // skip null } } charT col = traits_inst.translate(*next, icase); if(set_->cranges || set_->cequivalents) { traits_string_type s1; // // try and match a range, NB only a single character can match if(set_->cranges) { if((e.m_flags & regex_constants::collate) == 0) s1.assign(1, col); else { charT a[2] = { col, charT(0), }; s1 = traits_inst.transform(a, a + 1); } for(i = 0; i < set_->cranges; ++i) { if(STR_COMP(s1, p) >= 0) { do{ ++p; }while(*p); ++p; if(STR_COMP(s1, p) <= 0) return set_->isnot ? next : ++next; } else { // skip first string do{ ++p; }while(*p); ++p; } // skip second string do{ ++p; }while(*p); ++p; } } // // try and match an equivalence class, NB only a single character can match if(set_->cequivalents) { charT a[2] = { col, charT(0), }; s1 = traits_inst.transform_primary(a, a +1); for(i = 0; i < set_->cequivalents; ++i) { if(STR_COMP(s1, p) == 0) return set_->isnot ? next : ++next; // skip string do{ ++p; }while(*p); ++p; } } } if(traits_inst.isctype(col, set_->cclasses) == true) return set_->isnot ? next : ++next; if((set_->cnclasses != 0) && (traits_inst.isctype(col, set_->cnclasses) == false)) return set_->isnot ? next : ++next; return set_->isnot ? ++next : next; }
inline std::size_t regex_split(OutputIterator out, std::basic_string<charT, Traits1, Alloc1>& s) { return regex_split(out, s, re_detail::get_default_expression(charT(0)), match_default, UINT_MAX); }
BOOL COptionsSystem::OnInitDialog() { COptions_PropertyPage::OnInitDialog(); PWSprefs *prefs = PWSprefs::GetInstance(); PWSprefs::ConfigOption configoption; StringX sx_CF = prefs->GetConfigFile(configoption).c_str(); std::wstring wsCO(L""); switch (configoption) { case PWSprefs::CF_NONE: LoadAString(sx_CF, IDS_NONE); break; case PWSprefs::CF_REGISTRY: LoadAString(sx_CF, IDS_REGISTRY); break; case PWSprefs::CF_FILE_RO: LoadAString(wsCO, IDS_READ_ONLY); break; case PWSprefs::CF_FILE_RW: case PWSprefs::CF_FILE_RW_NEW: LoadAString(wsCO, IDS_READ_WRITE); break; default: ASSERT(0); } CString cs_text; // R/W status GetDlgItem(IDC_STATIC_RWSTATUS)->SetWindowText(wsCO.c_str()); // Config file name & location cs_text = PWSUtil::NormalizeTTT(sx_CF, 60).c_str(); GetDlgItem(IDC_CONFIGFILE)->SetWindowText(cs_text); // Effective host & user used in config file if (configoption == PWSprefs::CF_FILE_RO || configoption == PWSprefs::CF_FILE_RW || configoption == PWSprefs::CF_FILE_RW_NEW) { stringT hn = SysInfo::GetInstance()->GetEffectiveHost(); PWSprefs::XMLify(charT('H'), hn); stringT un = SysInfo::GetInstance()->GetEffectiveUser(); PWSprefs::XMLify(charT('u'), un); cs_text.Format(IDS_HOSTUSER, static_cast<LPCWSTR>(hn.c_str()), static_cast<LPCWSTR>(un.c_str())); GetDlgItem(IDC_STATIC_HOSTUSER)->SetWindowText(cs_text); } bool bofferdeleteregistry = prefs->OfferDeleteRegistry(); bool boffermigrate2appdata = OfferConfigMigration(); if (!bofferdeleteregistry) { GetDlgItem(IDC_REGDEL)->ShowWindow(SW_HIDE); GetDlgItem(IDC_REGDEL)->EnableWindow(FALSE); } if (!boffermigrate2appdata) { GetDlgItem(IDC_MIGRATETOAPPDATA)->ShowWindow(SW_HIDE); GetDlgItem(IDC_MIGRATETOAPPDATA)->EnableWindow(FALSE); } if (!bofferdeleteregistry && !boffermigrate2appdata) { GetDlgItem(IDC_CONFIG_GRP)->ShowWindow(SW_HIDE); GetDlgItem(IDC_APPLYCONFIGCHANGES)->ShowWindow(SW_HIDE); } else { GetDlgItem(IDC_APPLYCONFIGCHANGES)->ShowWindow(SW_SHOW); } GetDlgItem(IDC_APPLYCONFIGCHANGES)->EnableWindow(FALSE); CSpinButtonCtrl *pspin = (CSpinButtonCtrl *)GetDlgItem(IDC_RESPIN); pspin->SetBuddy(GetDlgItem(IDC_MAXREITEMS)); pspin->SetRange(M_prefminREItems(), M_prefmaxREItems()); pspin->SetBase(10); pspin->SetPos(m_MaxREItems); pspin = (CSpinButtonCtrl *)GetDlgItem(IDC_MRUSPIN); pspin->SetBuddy(GetDlgItem(IDC_MAXMRUITEMS)); pspin->SetRange(M_prefminMRU(), M_prefmaxMRU()); pspin->SetBase(10); pspin->SetPos(m_MaxMRUItems); OnUseSystemTray(); if (InitToolTip(TTS_BALLOON | TTS_NOPREFIX, 0)) { m_Help1.Init(IDB_QUESTIONMARK); m_Help2.Init(IDB_QUESTIONMARK); // Note naming convention: string IDS_xxx corresponds to control IDC_xxx_HELP AddTool(IDC_REGDELHELP, IDS_REGDEL); AddTool(IDC_MIGRATETOAPPDATAHELP, IDS_MIGRATETOAPPDATA); ActivateToolTip(); } else { m_Help1.EnableWindow(FALSE); m_Help1.ShowWindow(SW_HIDE); m_Help2.EnableWindow(FALSE); m_Help2.ShowWindow(SW_HIDE); } if (!bofferdeleteregistry) { m_Help1.EnableWindow(FALSE); m_Help1.ShowWindow(SW_HIDE); } if (!boffermigrate2appdata) { m_Help2.EnableWindow(FALSE); m_Help2.ShowWindow(SW_HIDE); } return TRUE; // return TRUE unless you set the focus to a control }
void test_copy (charT, Traits*, Allocator*, const StringFunc &func, const StringTestCase &tcase) { typedef std::basic_string <charT, Traits, Allocator> String; static const std::size_t BUFSIZE = 256; static charT wstr_buf [BUFSIZE]; std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len); static charT wres_buf [BUFSIZE]; std::size_t res_len = sizeof wres_buf / sizeof *wres_buf; charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len); // construct the string object const String str (wstr, str_len); if (wstr != wstr_buf) delete[] wstr; wstr = 0; const std::size_t min_len = str_len < std::size_t (tcase.size) ? str_len : tcase.size; std::size_t res = 0; // create destination array and initialize it with garbage charT* const s_res = new charT [min_len + 2]; const char cgb [2] = "#"; const charT wcgb = make_char (cgb [0], (charT*)0); Traits::assign (s_res, min_len + 1, wcgb); s_res [min_len + 1] = charT (); // save the state of the string object before the call // to detect wxception safety violations (changes to // the state of the object after an exception) const StringState str_state (rw_get_string_state (str)); #ifndef _RWSTD_NO_EXCEPTIONS // is some exception expected? const char* const expected = tcase.bthrow ? exceptions [1] : 0; const char* caught = 0; #else // if defined (_RWSTD_NO_EXCEPTIONS) if (tcase.bthrow) { if (wres != wres_buf) delete[] wres; return; } #endif // _RWSTD_NO_EXCEPTIONS try { switch (func.which_) { case Copy (ptr_size): { res = str.copy (s_res, tcase.size); break; } case Copy (ptr_size_size): { res = str.copy (s_res, tcase.size, tcase.off); break; } default: RW_ASSERT (!"logic error: unknown copy overload"); return; } // verify the returned value rw_assert (res == res_len, 0, tcase.line, "line %d. %{$FUNCALL} == %zu, got %zu", __LINE__, res_len, res); if (res == res_len) { const std::size_t match = rw_match (tcase.res, s_res, res_len); bool success = match == res_len; rw_assert (success, 0, tcase.line, "line %d. %{$FUNCALL} expected %{#*s}, " "got %{/*.*Gs}, differ at pos %zu", __LINE__, int (tcase.nres), tcase.res, int (sizeof (charT)), int (res), s_res, match); success = 1 == rw_match (cgb, s_res + min_len, 1); rw_assert (success, 0, tcase.line, "line %d. %{$FUNCALL} detected writing past the end of " "the provided buffer", __LINE__); } } #ifndef _RWSTD_NO_EXCEPTIONS catch (const std::out_of_range &ex) { caught = exceptions [1]; rw_assert (caught == expected, 0, tcase.line, "line %d. %{$FUNCALL} %{?}expected %s,%{:}" "unexpectedly%{;} caught std::%s(%#s)", __LINE__, 0 != expected, expected, caught, ex.what ()); } catch (const std::exception &ex) { caught = exceptions [4]; rw_assert (0, 0, tcase.line, "line %d. %{$FUNCALL} %{?}expected %s,%{:}" "unexpectedly%{;} caught std::%s(%#s)", __LINE__, 0 != expected, expected, caught, ex.what ()); } catch (...) { caught = exceptions [0]; rw_assert (0, 0, tcase.line, "line %d. %{$FUNCALL} %{?}expected %s,%{:}" "unexpectedly%{;} caught %s", __LINE__, 0 != expected, expected, caught); } if (caught) { // verify that an exception thrown during allocation // didn't cause a change in the state of the object str_state.assert_equal (rw_get_string_state (str), __LINE__, tcase.line, caught); } else if (-1 != tcase.bthrow) { rw_assert (caught == expected, 0, tcase.line, "line %d. %{$FUNCALL} %{?}expected %s, caught %s" "%{:}unexpectedly caught %s%{;}", __LINE__, 0 != expected, expected, caught, caught); } #endif // _RWSTD_NO_EXCEPTIONS if (wres != wres_buf) delete[] wres; delete[] s_res; }