protected DirectableEncConverter GetTempFixedValueConverter(string strFixedValue) { string strName = String.Format("{0}{1}", cstrFixedStringConverterPrefix, strFixedValue); EncConverters aECs = GetEncConverters; if (aECs != null) { IEncConverter aIEC = null; if (!aECs.ContainsKey(strName)) { aIEC = aECs.NewEncConverterByImplementationType(EncConverters.strTypeSILicuRegex); ConvType eConvType = ConvType.Unicode_to_Unicode; string strDummy = null; int nProcType = (int)ProcessTypeFlags.ICURegularExpression; aIEC.Initialize(strName, String.Format(".+->{0}", strFixedValue), ref strDummy, ref strDummy, ref eConvType, ref nProcType, 0, 0, true); aECs.Add(strName, aIEC); } else { aIEC = aECs[strName]; } return(new DirectableEncConverter(aIEC)); } return(null); }
// initialize an EncConverter which will tell us when we've hit a match. Uses ICU RegEx (though, there's // no reason this couldn't be .Net regex...) protected IEncConverter InitSearchFontConverter(string strFindWhat, string strReplaceWith, Font font, bool bMatchCase) { // we're going to use a temporary ICU RegEx EncConverter to do our 'searching' for us. // get a blank ICU Regex converter that we can program with our FindWhat string // but, it may be null if ICU isn't installed System.Diagnostics.Debug.Assert(m_aECs != null); IEncConverter aIEC = null; try { aIEC = m_aECs.NewEncConverterByImplementationType(EncConverters.strTypeSILicuRegex); } catch (Exception ex) { throw new ApplicationException("ICU doesn't appear to have been installed. This feature won't work without ICU.", ex); } // we search for different things depending on whether it's "Find" (only) vs. "Find & Replace" // delimit the replacement string with something we can detect, which we wouldn't otherwise expect // to find in user text. string strConverterSpec = String.Format("{0}->{2}{1}{2}{3}", strFindWhat, strReplaceWith, m_achDelimiter[0], (bMatchCase) ? " /i" : null); // Give it a friendly name that isn't likely to conflict with anything 'real' the user might name it. string strName = String.Format("{0} FindReplaceConverter", OfficeApp.cstrCaption); ConvType eConvType = ConvType.Unicode_to_Unicode; string strDummy = null; int nProcType = (int)ProcessTypeFlags.ICURegularExpression; // initialize it so it's ready and put it in the current repository object (as a temporary converter) aIEC.Initialize(strName, strConverterSpec, ref strDummy, ref strDummy, ref eConvType, ref nProcType, 0, 0, true); return(aIEC); }
private bool ChaChaChaChaChanges(IEncConverter aEC, string strFileName, string strWord) { string strDummy = null; int lProcessType = (int)SpellingFixerEC.SFProcessType; ConvType eConvType = (m_bLegacy) ? ConvType.Legacy_to_Legacy : ConvType.Unicode_to_Unicode; aEC.Initialize("dummyname", strFileName, ref strDummy, ref strDummy, ref eConvType, ref lProcessType, 0, 0, true); return(aEC.Convert(strWord) != strWord); }
public void SaveTempAndCompile() { File.WriteAllLines(m_strMapNameTemp, this.richTextBoxMapEditor.Lines, m_enc); try { string strTecName = m_strTecNameTemp; TECkitDllWrapper.CompileMap(m_strMapNameTemp, ref strTecName); // if the compiler had to use a different file, then clear the reference to rebuild it // if (m_strTecNameTemp != strTecName) m_aEC = null; this.textBoxCompilerResults.Text = "Compiled successfully!"; // now that we have something we can compile successfully, create a converter of it if (m_aEC == null) { m_strTecNameTemp = strTecName; m_aEC = new TecEncConverter(); string strDummy = null; int nProcType = (int)ProcessTypeFlags.DontKnow; m_aEC.Initialize(cstrMyEncConverterName, m_strTecNameTemp, ref strDummy, ref strDummy, ref m_eConvType, ref nProcType, m_nCodePageLegacyLhs, m_nCodePageLegacyRhs, true); } if (this.textBoxSample.Text.Length > 0) { UpdateTextChanged(this.textBoxSample, this.textBoxSampleForward, m_aEC, true); UpdateUnicodeDetails(this.textBoxSample); } } catch (Exception ex) { this.textBoxCompilerResults.Text = ex.Message; // clear the converter so we don't accidentally call it while we don't have a good map m_aEC = null; } }
private void addToSystemRepositoryToolStripMenuItem_Click(object sender, EventArgs e) { // we have to have a file saved to add it if (m_strMapNameReal == null) saveAsToolStripMenuItem_Click(sender, e); // check again, just in case they cancelled. if (m_strMapNameReal != null) { m_aEC = null; // free it so we can re-create it with the "real" content string strFriendlyName = null, strLhsEncodingID = null, strRhsEncodingID = null; if (CompileRealMap()) { m_aEC = new TecEncConverter(); int nProcType = (int)ProcessTypeFlags.DontKnow; m_aEC.Initialize(cstrMyEncConverterName, m_strTecNameReal, ref strLhsEncodingID, ref strRhsEncodingID, ref m_eConvType, ref nProcType, 0, 0, true); } else return; // compile failed, so just quit if (m_aEC != null) { try { strFriendlyName = String.Format("{0}{2}{1}", strLhsEncodingID, strRhsEncodingID, (EncConverters.IsUnidirectional(m_aEC.ConversionType)) ? ">" : "<>"); } catch { } EncConverters aECs = new EncConverters(); IEncConverterConfig rConfigurator = m_aEC.Configurator; // call its Configure method to do the UI rConfigurator.Configure(aECs, strFriendlyName, m_eConvType, strLhsEncodingID, strRhsEncodingID); } } }
protected bool Configure(AutoConfigDialog form) { m_strFriendlyName = form.FriendlyName; m_eConversionType = form.ConversionType; m_strLhsEncodingID = form.LhsEncodingId; m_strRhsEncodingID = form.RhsEncodingId; DialogResult res = form.ShowDialog(); // update our internal values from the config tab (but only if the user clicked OK or // if it is already in the repository--either editing or MetaCmpd type) // NOTE: I've taken out the OR case with IsInRepository, because even in that case // we have to require the OK result. If the user is editing and cancels, then we *don't* // want to update the results. This might mean that I've broken the MetaCmpd cases. // So we'll probably have to have special handling in that class to gracefully remove // the added converter if the user then cancels the dialog // NO: I figured out why that was there: if the converter "IsInRepository", it may mean that // the user has made changes and clicked the "Save In Repository" button. In that case, it // is in the repository, so this method needs to return 'true' (so the SelectConverter dialog // will update the list of converters (in case this one was added). However, if the user clicks // Cancel after saving in the repository and making some changes, then those changes should be // ignored. So we *do* want to remove the OR IsInRepository case for the following IF statement // and only update the EncConverter properties in the case where the user actually clicks OK. // But make the 'else' case return 'false', only if it isn't "in the repository". // if ((res == DialogResult.OK) || form.IsInRepository) if (res == DialogResult.OK) { if (!String.IsNullOrEmpty(form.FriendlyName)) { m_strFriendlyName = form.FriendlyName; } if (!String.IsNullOrEmpty(form.ConverterIdentifier)) { m_strConverterID = form.ConverterIdentifier; } if (!String.IsNullOrEmpty(form.LhsEncodingId)) { m_strLhsEncodingID = form.LhsEncodingId; } if (!String.IsNullOrEmpty(form.RhsEncodingId)) { m_strRhsEncodingID = form.RhsEncodingId; } if (form.ConversionType != ConvType.Unknown) { m_eConversionType = form.ConversionType; } m_lProcessType = (int)form.ProcessType; m_bIsInRepository = form.IsInRepository; // and... if we have the pointer to the parent EC, then go ahead and update that also // (to save *some* clients a step) if (m_pIECParent != null) { // initialize it with the details we have. m_pIECParent.Initialize(m_strFriendlyName, m_strConverterID, ref m_strLhsEncodingID, ref m_strRhsEncodingID, ref m_eConversionType, ref m_lProcessType, m_pIECParent.CodePageInput, m_pIECParent.CodePageOutput, true); // and update it's temporariness status m_pIECParent.IsInRepository = m_bIsInRepository; } } // it might either have already been in the repository (e.g. editing) or added while there (e.g. compound converters) // however, in any case, if we don't have a ConverterFriendlyName, all bets are off (and the caller will choke) else if (form.IsInRepository && !String.IsNullOrEmpty(ConverterFriendlyName)) { // and update it's temporariness status if (m_pIECParent != null) { m_pIECParent.IsInRepository = m_bIsInRepository; } // fall thru to return true (so the SelectConverter dialog will refresh) } else { return(false); } return(true); }
private bool ChaChaChaChaChanges(IEncConverter aEC, string strFileName, string strWord) { string strDummy = null; int lProcessType = (int)SpellingFixerEC.SFProcessType; ConvType eConvType = (m_bLegacy) ? ConvType.Legacy_to_Legacy : ConvType.Unicode_to_Unicode; aEC.Initialize("dummyname", strFileName, ref strDummy, ref strDummy, ref eConvType, ref lProcessType, 0, 0, true); return (aEC.Convert(strWord) != strWord); }