/// <summary> /// Applies a given attribute to this string. /// </summary> /// <param name="attribute">The attribute that will be applied to this string.</param> /// <param name="value">The value of the attribute that will be applied to this string.</param> /// <exception cref="ArgumentException">If the length of this attributed string is 0.</exception> /// <exception cref="ArgumentNullException">if <paramref name="attribute"/> is <c>null</c>.</exception> public void AddAttribute(AttributedCharacterIteratorAttribute attribute, object value) { if (null == attribute) { throw new ArgumentNullException(nameof(attribute)); } if (text.Length == 0) { throw new ArgumentException(); } IList <Range> ranges; //= attributeMap.get(attribute); attributeMap.TryGetValue(attribute, out ranges); if (ranges == null) { ranges = new List <Range>(1); attributeMap[attribute] = ranges; } else { ranges.Clear(); } ranges.Add(new Range(0, text.Length, value)); }
public override int GetRunStart(AttributedCharacterIteratorAttribute attribute) { if (attributesAllowed != null && !attributesAllowed.Contains(attribute)) { return(begin); } IList <Range> ranges; // = (ArrayList<Range>)attrString.attributeMap.get(attribute); attrString.attributeMap.TryGetValue(attribute, out ranges); if (ranges == null) { return(begin); } return(RunStart(ranges)); }
public override object GetAttribute( AttributedCharacterIteratorAttribute attribute) { if (attributesAllowed != null && !attributesAllowed.Contains(attribute)) { return(null); } IList <Range> ranges; // = (IList<Range>)attrString.attributeMap.get(attribute); attrString.attributeMap.TryGetValue(attribute, out ranges); if (ranges == null) { return(null); } return(CurrentValue(ranges)); }
/// <summary> /// Applies a given attribute to the given range of this string. /// </summary> /// <param name="attribute">The attribute that will be applied to this string.</param> /// <param name="value">The value of the attribute that will be applied to this string.</param> /// <param name="start">The start of the range where the attribute will be applied.</param> /// <param name="end">The end of the range where the attribute will be applied.</param> /// <exception cref="ArgumentException">If <c>start < 0</c>, <paramref name="end"/> is greater than the length /// of this string, or if <c>start >= end</c>.</exception> /// <exception cref="ArgumentNullException">if <paramref name="attribute"/> is <c>null</c>.</exception> public void AddAttribute(AttributedCharacterIteratorAttribute attribute, object value, int start, int end) { throw new NotImplementedException(); // ICU4N TODO: //if (null == attribute) //{ // throw new ArgumentNullException(nameof(attribute)); //} //if (start < 0 || end > text.Length || start >= end) //{ // throw new ArgumentException(); //} //if (value == null) //{ // return; //} //lock (syncLock) //{ // IList<Range> ranges; // = attributeMap.get(attribute); // attributeMap.TryGetValue(attribute, out ranges); // if (ranges == null) // { // ranges = new List<Range>(1); // ranges.Add(new Range(start, end, value)); // attributeMap[attribute] = ranges; // return; // } // //ListIterator<Range> it = ranges.listIterator(); // //while (it.hasNext()) // //{ // // Range range = it.next(); // var toRemove = new List<Range>(); // var toAdd = new Dictionary<Range, int>(); // int position = 0; // for (int i = 0; i < ranges.Count; i++) // { // position = i; // Range range = ranges[i]; // if (end <= range.start) // { // //it.previous(); // position--; // break; // } // else if (start < range.end // || (start == range.end && value.Equals(range.value))) // { // Range r1 = null, r3; // //it.remove(); // toRemove.Add(range); // r1 = new Range(range.start, start, range.value); // r3 = new Range(end, range.end, range.value); // while (end > range.end && i < ranges.Count /*it.hasNext()*/) // { // //range = it.next(); // i++; // position = i; // range = ranges[i]; // if (end <= range.end) // { // if (end > range.start // || (end == range.start && value.Equals(range.value))) // { // //it.remove(); // toRemove.Add(range); // r3 = new Range(end, range.end, range.value); // break; // } // } // else // { // //it.remove(); // toRemove.Add(range); // } // } // if (value.Equals(r1.value)) // { // if (value.Equals(r3.value)) // { // it.add(new Range(r1.start < start ? r1.start : start, // r3.end > end ? r3.end : end, r1.value)); // } // else // { // it.add(new Range(r1.start < start ? r1.start : start, // end, r1.value)); // if (r3.start < r3.end) // { // it.add(r3); // } // } // } // else // { // if (value.Equals(r3.value)) // { // if (r1.start < r1.end) // { // it.add(r1); // } // it.add(new Range(start, r3.end > end ? r3.end : end, // r3.value)); // } // else // { // if (r1.start < r1.end) // { // it.add(r1); // } // it.add(new Range(start, end, value)); // if (r3.start < r3.end) // { // it.add(r3); // } // } // } // return; // } // } // it.add(new Range(start, end, value)); //} //ListIterator<Range> it = ranges.listIterator(); //while (it.hasNext()) //{ // Range range = it.next(); // if (end <= range.start) // { // it.previous(); // break; // } // else if (start < range.end // || (start == range.end && value.Equals(range.value))) // { // Range r1 = null, r3; // it.remove(); // r1 = new Range(range.start, start, range.value); // r3 = new Range(end, range.end, range.value); // while (end > range.end && it.hasNext()) // { // range = it.next(); // if (end <= range.end) // { // if (end > range.start // || (end == range.start && value.Equals(range.value))) // { // it.remove(); // r3 = new Range(end, range.end, range.value); // break; // } // } // else // { // it.remove(); // } // } // if (value.Equals(r1.value)) // { // if (value.Equals(r3.value)) // { // it.add(new Range(r1.start < start ? r1.start : start, // r3.end > end ? r3.end : end, r1.value)); // } // else // { // it.add(new Range(r1.start < start ? r1.start : start, // end, r1.value)); // if (r3.start < r3.end) // { // it.add(r3); // } // } // } // else // { // if (value.Equals(r3.value)) // { // if (r1.start < r1.end) // { // it.add(r1); // } // it.add(new Range(start, r3.end > end ? r3.end : end, // r3.value)); // } // else // { // if (r1.start < r1.end) // { // it.add(r1); // } // it.add(new Range(start, end, value)); // if (r3.start < r3.end) // { // it.add(r3); // } // } // } // return; // } //} //it.add(new Range(start, end, value)); }
/// <summary> /// Returns the index of the first character in the run that has the same /// attribute value for the given attribute as the current character. /// </summary> /// <param name="attribute">The attribute which the run is based on.</param> /// <returns>The index of the last character of the current run.</returns> public abstract int GetRunStart(AttributedCharacterIteratorAttribute attribute);
/// <summary> /// Returns the value stored in the attribute for the current character. If /// the attribute was not defined then <c>null</c> is returned. /// </summary> /// <param name="attribute">The attribute for which the value should be returned.</param> /// <returns>the value of the requested attribute for the current character or <c>null</c> /// if it was not defined.</returns> public abstract object GetAttribute(AttributedCharacterIteratorAttribute attribute);