public void SetAlternative(string writingSystemId, string form) { Debug.Assert(!string.IsNullOrEmpty(writingSystemId), "The writing system id was empty."); Debug.Assert(writingSystemId.Trim() == writingSystemId, "The writing system id had leading or trailing whitespace"); //enhance: check to see if there has actually been a change LanguageForm alt = Find(writingSystemId); if (string.IsNullOrEmpty(form)) // we don't use space to store empty strings. { if (alt != null && !alt.IsStarred) { RemoveLanguageForm(alt); } } else { if (alt != null) { alt.Form = form; } else { AddLanguageForm(new LanguageForm(writingSystemId, form, this)); } } NotifyPropertyChanged(writingSystemId); }
public void SetAnnotationOfAlternativeIsStarred(string id, bool isStarred) { LanguageForm alt = Find(id); if (isStarred) { if (alt == null) { AddLanguageForm(new LanguageForm(id, String.Empty, this)); alt = Find(id); Debug.Assert(alt != null); } alt.IsStarred = true; } else { if (alt != null) { if (alt.Form == String.Empty) //non-starred and empty? Nuke it. { RemoveLanguageForm(alt); } else { alt.IsStarred = false; } } else { //nothing to do. Missing altertive == not starred. } } NotifyPropertyChanged(id); }
/// <summary> /// Get a string out /// </summary> /// <returns>the string of the requested id if it exists, /// else the 'first'(?) one that does exist + the suffix, /// else the given suffix </returns> private string GetAlternative(string writingSystemId, bool doShowSomethingElseIfMissing, string notFirstChoiceSuffix) { LanguageForm alt = Find(writingSystemId); if (null == alt) { if (doShowSomethingElseIfMissing) { return(GetFirstAlternative() + notFirstChoiceSuffix); } else { return(string.Empty); } } string form = alt.Form; if (form == null || (form.Trim().Length == 0)) { if (doShowSomethingElseIfMissing) { return(GetFirstAlternative() + notFirstChoiceSuffix); } else { return(string.Empty); } } else { return(form); } }
public bool GetAnnotationOfAlternativeIsStarred(string id) { LanguageForm alt = Find(id); if (alt == null) { return(false); } return(alt.IsStarred); }
public string GetBestAlternativeString(IEnumerable <string> orderedListOfWritingSystemIds) { LanguageForm form = GetBestAlternative(orderedListOfWritingSystemIds); if (form == null) { return(string.Empty); } return(form.Form); }
public bool ContainsEqualForm(LanguageForm other) { foreach (LanguageForm form in Forms) { if (other.Equals(form)) { return(true); } } return(false); }
protected void AddLanguageForm(LanguageForm languageForm) { LanguageForm[] forms = new LanguageForm[Forms.Length + 1]; for (int i = 0; i < Forms.Length; i++) { forms[i] = Forms[i]; } //actually copy the contents, as we must now be the parent forms[Forms.Length] = new LanguageForm(languageForm, this); Array.Sort(forms); _forms = forms; }
/// <summary> /// Gets the Spans for the exact alternative or null. /// </summary> public List <LanguageForm.FormatSpan> GetExactAlternativeSpans(string writingSystemId) { LanguageForm alt = Find(writingSystemId); if (null == alt) { return(null); } else { return(alt.Spans); } }
public LanguageForm[] GetOrderedAndFilteredForms(IEnumerable <string> writingSystemIdsInOrder) { List <LanguageForm> forms = new List <LanguageForm>(); foreach (string id in writingSystemIdsInOrder) { LanguageForm form = Find(id); if (form != null) { forms.Add(form); } } return(forms.ToArray()); }
public void RemoveLanguageForm(LanguageForm languageForm) { Debug.Assert(Forms.Length > 0); LanguageForm[] forms = new LanguageForm[Forms.Length - 1]; for (int i = 0, j = 0; i < forms.Length; i++, j++) { if (Forms[j] == languageForm) { j++; } forms[i] = Forms[j]; } _forms = forms; }
public void MergeIn(MultiTextBase incoming) { foreach (LanguageForm form in incoming) { LanguageForm f = Find(form.WritingSystemId); if (f != null) { f.Form = form.Form; } else { AddLanguageForm(form); //this actually copies the meat of the form } } }
protected static void CopyForms(Dictionary <string, string> forms, MultiTextBase m) { if (forms != null && forms.Keys != null) { foreach (string key in forms.Keys) { LanguageForm f = m.Find(key); if (f != null) { f.Form = forms[key]; } else { m.SetAlternative(key, forms[key]); } } } }
/// <summary> /// Try to get an alternative according to the ws's given(e.g. the enabled writing systems for a field) /// </summary> /// <param name="orderedListOfWritingSystemIds"></param> /// <returns>May return null!</returns> public LanguageForm GetBestAlternative(IEnumerable <string> orderedListOfWritingSystemIds) { foreach (string id in orderedListOfWritingSystemIds) { LanguageForm alt = Find(id); if (null != alt) { return(alt); } } // //just send back an empty // foreach (string id in orderedListOfWritingSystemIds) // { // return new LanguageForm(id, string.Empty ); // } return(null); }