public void TestStringCase() { CaseFunctions cf = new CaseFunctions("en"); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase("abc")); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase("")); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(null)); Assert.AreEqual(StringCaseStatus.title, cf.StringCase("Abc")); Assert.AreEqual(StringCaseStatus.title, cf.StringCase("A")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("AbC")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("ABC")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase("aBC")); int surrogateUc = 0x10400; // DESERET CAPITAL LETTER LONG I int surrogateLc = 0x10428; // DESERET SMALL LETTER LONG I string strUcSurrogate = Surrogates.StringFromCodePoint(surrogateUc); string strLcSurrogate = Surrogates.StringFromCodePoint(surrogateLc); // A single upper case surrogate is treated as title. Assert.AreEqual(StringCaseStatus.title, cf.StringCase(strUcSurrogate)); Assert.AreEqual(StringCaseStatus.title, cf.StringCase(strUcSurrogate + "bc")); Assert.AreEqual(StringCaseStatus.mixed, cf.StringCase(strUcSurrogate + "bC")); Assert.AreEqual(StringCaseStatus.allLower, cf.StringCase(strLcSurrogate + "bc")); }
/// <summary> /// Gets the case function for the given writing system. /// </summary> internal CaseFunctions GetCaseFunctionFor(int ws) { CaseFunctions cf; if (!m_caseFunctions.TryGetValue(ws, out cf)) { string icuLocale = m_cache.ServiceLocator.WritingSystemManager.Get(ws).IcuLocale; cf = new CaseFunctions(icuLocale); m_caseFunctions[ws] = cf; } return cf; }
public void TestToLower() { CaseFunctions cf = new CaseFunctions("en"); Assert.AreEqual("abc", cf.ToLower("ABC")); }
public override void SetupCombo() { CheckDisposed(); base.SetupCombo(); // Any time we pop this up, the text in the box is the text form of the current // analysis, as a starting point. ITsStrBldr builder = TsStrBldrClass.Create(); int cmorphs = MorphCount; Debug.Assert(cmorphs != 0); // we're supposed to be building on one of them! var wordform = m_sandbox.GetWordformOfAnalysis(); IWfiAnalysis wa = m_sandbox.GetWfiAnalysisInUse(); // Find the actual original form of the current wordform ITsString tssForm = m_sandbox.FindAFullWordForm(wordform); string form = StrFromTss(tssForm); bool fBaseWordIsPhrase = SandboxBase.IsPhrase(form); // First, store the current morph breakdown if we have one, // Otherwise, if the user has deleted all the morphemes on the morpheme line // (per LT-1621) simply use the original wordform. // NOTE: Normally we would use Sandbox.IsMorphFormLineEmpty for this condition // but since we're already using the variable(s) needed for this check, // here we'll use those variables for economy/performance instead. string currentBreakdown = m_sandbox.SandboxEditMonitor.BuildCurrentMorphsString(); if (currentBreakdown != string.Empty) { ComboList.Text = currentBreakdown; // The above and every other distinct morpheme breakdown from owned // WfiAnalyses are possible choices. ITsString tssText = TsStrFactoryClass.Create(). MakeString(currentBreakdown, m_wsVern); ComboList.Items.Add(tssText); } else { ComboList.Text = form; ComboList.Items.Add(tssForm); } // if we added the fullWordform (or the current breakdown is somehow empty although we may have an analysis), then add the // wordform HVO; otherwise, add the analysis HVO. if (currentBreakdown == string.Empty || (wa == null && tssForm != null && tssForm.Equals(ComboList.Items[0] as ITsString))) m_items.Add(wordform != null ? wordform.Hvo : 0); else m_items.Add(wa != null ? wa.Hvo : 0); // [wfi] hvoAnalysis may equal '0' (for annotations that are instances of Wordform). Debug.Assert(m_items.Count == ComboList.Items.Count, "combo list (m_comboList) should contain the same count as the m_items list (hvos)"); AddAnalysesOf(wordform, fBaseWordIsPhrase); // Add the original wordform, if not already present. AddIfNotPresent(tssForm, wordform); ComboList.SelectedIndex = this.IndexOfCurrentItem; // Add any relevant 'other case' forms. int wsVern = m_sandbox.RawWordformWs; string locale = m_caches.MainCache.ServiceLocator.WritingSystemManager.Get(wsVern).IcuLocale; CaseFunctions cf = new CaseFunctions(locale); switch (m_sandbox.CaseStatus) { case StringCaseStatus.allLower: break; // no more to add case StringCaseStatus.title: AddOtherCase(cf.SwitchTitleAndLower(form)); break; case StringCaseStatus.mixed: switch (cf.StringCase(form)) { case StringCaseStatus.allLower: AddOtherCase(cf.ToTitle(form)); AddOtherCase(m_sandbox.RawWordform.Text); break; case StringCaseStatus.title: AddOtherCase(cf.ToLower(form)); AddOtherCase(m_sandbox.RawWordform.Text); break; case StringCaseStatus.mixed: AddOtherCase(cf.ToLower(form)); AddOtherCase(cf.ToTitle(form)); break; } break; } Debug.Assert(m_items.Count == ComboList.Items.Count, "combo list (m_comboList) should contain the same count as the m_items list (hvos)"); ComboList.Items.Add(ITextStrings.ksEditMorphBreaks_); }
virtual public IWfiWordform SetAlternateCase(int iSegment, int iSegForm, StringCaseStatus targetState, out string alternateCaseForm) { // Get actual segment form. var analysisActual = GetAnalysis(iSegment, iSegForm); int hvoActualInstanceOf; IWfiWordform actualWordform; GetRealWordformInfo(analysisActual, out hvoActualInstanceOf, out actualWordform); ITsString tssWordformBaseline = GetBaselineText(iSegment, iSegForm); // Add any relevant 'other case' forms. int nvar; int ws = tssWordformBaseline.get_Properties(0).GetIntPropValues((int)FwTextPropType.ktptWs, out nvar); string locale = m_cache.ServiceLocator.WritingSystemManager.Get(ws).IcuLocale; var cf = new CaseFunctions(locale); switch (targetState) { case StringCaseStatus.allLower: alternateCaseForm = cf.ToLower(actualWordform.Form.get_String(ws).Text); break; default: throw new ArgumentException("target StringCaseStatus(" + targetState + ") not yet supported."); } // Find or create the new wordform. IWfiWordform wfAlternateCase = WfiWordformServices.FindOrCreateWordform(m_cache, TsStringUtils.MakeTss(alternateCaseForm, ws)); // Set the annotation to this wordform. SetAnalysis(iSegment, iSegForm, wfAlternateCase); return wfAlternateCase; }
/// <summary> /// Verify that the text actually in the paragraph for the indicated segment and form /// is what is expected. /// </summary> /// <param name="tapb"></param> /// <param name="iSegment"></param> /// <param name="iSegForm"></param> internal static void ValidateCbaWordToBaselineWord(ParagraphAnnotatorForParagraphBuilder tapb, int iSegment, int iSegForm) { int ws; ITsString tssStringValue = GetTssStringValue(tapb, iSegment, iSegForm, out ws); IAnalysis analysis = tapb.GetAnalysis(iSegment, iSegForm); IWfiWordform wfInstanceOf = analysis.Wordform; ITsString tssWf = wfInstanceOf.Form.get_String(ws); string locale = wfInstanceOf.Services.WritingSystemManager.Get(ws).IcuLocale; var cf = new CaseFunctions(locale); string context = String.Format("[{0}]", tssStringValue); const string msg = "{0} cba mismatch in {1}."; Assert.AreEqual(cf.ToLower(tssStringValue.Text), cf.ToLower(tssWf.Text), String.Format(msg, "underlying wordform for InstanceOf", context)); }