/** * return a character representation of the fields of this record * * * @return String of output for biffviewer etc. * */ public String GetDebugInfo() { StringBuilder buffer = new StringBuilder(); buffer.Append("[UNICODESTRING]\n"); buffer.Append(" .charcount = ") .Append(StringUtil.ToHexString(CharCount)).Append("\n"); buffer.Append(" .optionflags = ") .Append(StringUtil.ToHexString(OptionFlags)).Append("\n"); buffer.Append(" .string = ").Append(String).Append("\n"); if (field_4_format_Runs != null) { for (int i = 0; i < field_4_format_Runs.Count; i++) { FormatRun r = field_4_format_Runs[(i)]; buffer.Append(" .format_Run" + i + " = ").Append(r.ToString()).Append("\n"); } } if (field_5_ext_rst != null) { buffer.Append(" .field_5_ext_rst = ").Append("\n"); buffer.Append(field_5_ext_rst.ToString()).Append("\n"); } buffer.Append("[/UNICODESTRING]\n"); return(buffer.ToString()); }
/** * Our handling of Equals is inconsistent with CompareTo. The trouble is because we don't truely understand * rich text fields yet it's difficult to make a sound comparison. * * @param o The object to Compare. * @return true if the object is actually Equal. */ public override bool Equals(Object o) { if (!(o is UnicodeString)) { return(false); } UnicodeString other = (UnicodeString)o; //OK lets do this in stages to return a quickly, first check the actual string if (field_1_charCount != other.field_1_charCount || field_2_optionflags != other.field_2_optionflags || !field_3_string.Equals(other.field_3_string)) { return(false); } //OK string appears to be equal but now lets compare formatting Runs if (field_4_format_runs == null) { // Strings are equal, and there are not formatting runs. return(other.field_4_format_runs == null); } else if (other.field_4_format_runs == null) { // Strings are equal, but one or the other has formatting runs return(false); } //Strings are Equal, so now compare formatting Runs. int size = field_4_format_runs.Count; if (size != other.field_4_format_runs.Count) { return(false); } for (int i = 0; i < size; i++) { FormatRun Run1 = field_4_format_runs[(i)]; FormatRun run2 = other.field_4_format_runs[(i)]; if (!Run1.Equals(run2)) { return(false); } } // Well the format Runs are equal as well!, better check the ExtRst data if (field_5_ext_rst == null) { return(other.field_5_ext_rst == null); } else if (other.field_5_ext_rst == null) { return(false); } return(field_5_ext_rst.Equals(other.field_5_ext_rst)); }
public int CompareTo(UnicodeString str) { //int result = String.CompareTo(str.String); int result = string.Compare(String, str.String, StringComparison.CurrentCulture); //As per the Equals method lets do this in stages if (result != 0) { return(result); } //OK string appears to be equal but now lets compare formatting Runs if (field_4_format_runs == null) { //Strings are equal, and there are no formatting runs. -> 0 //Strings are equal, but one or the other has formatting runs -> 1 return((str.field_4_format_runs == null) ? 0 : 1); } else if (str.field_4_format_runs == null) { //Strings are equal, but one or the other has formatting runs return(-1); } //Strings are Equal, so now compare formatting Runs. int size = field_4_format_runs.Count; if (size != str.field_4_format_runs.Count) { return(size - str.field_4_format_runs.Count); } for (int i = 0; i < size; i++) { FormatRun Run1 = field_4_format_runs[(i)]; FormatRun run2 = str.field_4_format_runs[(i)]; result = Run1.CompareTo(run2); if (result != 0) { return(result); } } //Well the format Runs are equal as well!, better check the ExtRst data if (field_5_ext_rst == null) { return((str.field_5_ext_rst == null) ? 0 : 1); } else if (str.field_5_ext_rst == null) { return(-1); } else { return(field_5_ext_rst.CompareTo(str.field_5_ext_rst)); } }
public void RemoveFormatRun(FormatRun r) { field_4_format_Runs.Remove(r); if (field_4_format_Runs.Count == 0) { field_4_format_Runs = null; field_2_optionflags = richText.ClearByte(field_2_optionflags); } }
public void Serialize(ContinuableRecordOutput out1) { int numberOfRichTextRuns = 0; int extendedDataSize = 0; if (IsRichText && field_4_format_Runs != null) { numberOfRichTextRuns = field_4_format_Runs.Count; } if (IsExtendedText && field_5_ext_rst != null) { extendedDataSize = field_5_ext_rst.Length; } out1.WriteString(field_3_string, numberOfRichTextRuns, extendedDataSize); if (numberOfRichTextRuns > 0) { //This will ensure that a run does not split a continue for (int i = 0; i < numberOfRichTextRuns; i++) { if (out1.AvailableSpace < 4) { out1.WriteContinue(); } FormatRun r = field_4_format_Runs[i]; r.Serialize(out1); } } if (extendedDataSize > 0) { // OK ExtRst is actually not documented, so i am going to hope // that we can actually continue on byte boundaries int extPos = 0; while (true) { int nBytesToWrite = Math.Min(extendedDataSize - extPos, out1.AvailableSpace); out1.Write(field_5_ext_rst, extPos, nBytesToWrite); extPos += nBytesToWrite; if (extPos >= extendedDataSize) { break; } out1.WriteContinue(); } } }
private int FindFormatRunAt(int characterPos) { int size = field_4_format_Runs.Count; for (int i = 0; i < size; i++) { FormatRun r = field_4_format_Runs[i]; if (r._character == characterPos) { return(i); } else if (r._character > characterPos) { return(-1); } } return(-1); }
/** Adds a font run to the formatted string. * * If a font run exists at the current charcter location, then it is * Replaced with the font run to be Added. */ public void AddFormatRun(FormatRun r) { if (field_4_format_Runs == null) { field_4_format_Runs = new List <FormatRun>(); } int index = FindFormatRunAt(r._character); if (index != -1) { field_4_format_Runs.RemoveAt(index); } field_4_format_Runs.Add(r); //Need to sort the font Runs to ensure that the font Runs appear in //character order field_4_format_Runs.Sort(); //Make sure that we now say that we are a rich string field_2_optionflags = richText.SetByte(field_2_optionflags); }
/** * Serialises out the String. There are special rules * about where we can and can't split onto * Continue records. */ public void Serialize(ContinuableRecordOutput out1) { int numberOfRichTextRuns = 0; int extendedDataSize = 0; if (IsRichText && field_4_format_Runs != null) { numberOfRichTextRuns = field_4_format_Runs.Count; } if (IsExtendedText && field_5_ext_rst != null) { extendedDataSize = 4 + field_5_ext_rst.DataSize; } // Serialise the bulk of the String // The WriteString handles tricky continue stuff for us out1.WriteString(field_3_string, numberOfRichTextRuns, extendedDataSize); if (numberOfRichTextRuns > 0) { //This will ensure that a run does not split a continue for (int i = 0; i < numberOfRichTextRuns; i++) { if (out1.AvailableSpace < 4) { out1.WriteContinue(); } FormatRun r = field_4_format_Runs[(i)]; r.Serialize(out1); } } if (extendedDataSize > 0) { field_5_ext_rst.Serialize(out1); } }
public int CompareTo(object obj) { UnicodeString str = (UnicodeString)obj; int result = this.String.CompareTo(str.String); //As per the equals method lets do this in stages if (result != 0) { return(result); } //OK string appears to be equal but now lets compare formatting Runs if ((field_4_format_Runs == null) && (str.field_4_format_Runs == null)) { //Strings are equal, and there are no formatting Runs. return(0); } if ((field_4_format_Runs == null) && (str.field_4_format_Runs != null)) { //Strings are equal, but one or the other has formatting Runs return(1); } if ((field_4_format_Runs != null) && (str.field_4_format_Runs == null)) { //Strings are equal, but one or the other has formatting Runs return(-1); } //Strings are equal, so now compare formatting Runs. int size = field_4_format_Runs.Count; if (size != str.field_4_format_Runs.Count) { return(size - str.field_4_format_Runs.Count); } for (int i = 0; i < size; i++) { FormatRun Run1 = field_4_format_Runs[i]; FormatRun Run2 = str.field_4_format_Runs[i]; result = Run1.CompareTo(Run2); if (result != 0) { return(result); } } //Well the format Runs are equal as well!, better check the ExtRst data //Which by the way we don't know how to decode! if ((field_5_ext_rst == null) && (str.field_5_ext_rst == null)) { return(0); } if ((field_5_ext_rst == null) && (str.field_5_ext_rst != null)) { return(1); } if ((field_5_ext_rst != null) && (str.field_5_ext_rst == null)) { return(-1); } size = field_5_ext_rst.Length; if (size != field_5_ext_rst.Length) { return(size - field_5_ext_rst.Length); } //Check individual bytes! for (int i = 0; i < size; i++) { if (field_5_ext_rst[i] != str.field_5_ext_rst[i]) { return(field_5_ext_rst[i] - str.field_5_ext_rst[i]); } } //Phew!! After all of that we have finally worked out that the strings //are identical. return(0); }
/** * Our handling of equals is inconsistent with CompareTo. The trouble is because we don't truely understand * rich text fields yet it's difficult to make a sound comparison. * * @param o The object to Compare. * @return true if the object is actually equal. */ public override bool Equals(Object o) { if (!(o is UnicodeString)) { return(false); } UnicodeString other = (UnicodeString)o; //OK lets do this in stages to return a quickly, first check the actual string bool eq = ((field_1_charCount == other.field_1_charCount) && (field_2_optionflags == other.field_2_optionflags) && field_3_string.Equals(other.field_3_string)); if (!eq) { return(false); } //OK string appears to be equal but now lets compare formatting Runs if ((field_4_format_Runs == null) && (other.field_4_format_Runs == null)) { //Strings are equal, and there are not formatting Runs. return(true); } if (((field_4_format_Runs == null) && (other.field_4_format_Runs != null)) || (field_4_format_Runs != null) && (other.field_4_format_Runs == null)) { //Strings are equal, but one or the other has formatting Runs return(false); } //Strings are equal, so now compare formatting Runs. int size = field_4_format_Runs.Count; if (size != other.field_4_format_Runs.Count) { return(false); } for (int i = 0; i < size; i++) { FormatRun Run1 = field_4_format_Runs[i]; FormatRun Run2 = other.field_4_format_Runs[i]; if (!Run1.Equals(Run2)) { return(false); } } //Well the format Runs are equal as well!, better check the ExtRst data //Which by the way we dont know how to decode! if ((field_5_ext_rst == null) && (other.field_5_ext_rst == null)) { return(true); } if (((field_5_ext_rst == null) && (other.field_5_ext_rst != null)) || ((field_5_ext_rst != null) && (other.field_5_ext_rst == null))) { return(false); } size = field_5_ext_rst.Length; if (size != field_5_ext_rst.Length) { return(false); } //Check individual bytes! for (int i = 0; i < size; i++) { if (field_5_ext_rst[i] != other.field_5_ext_rst[i]) { return(false); } } //Phew!! After all of that we have finally worked out that the strings //are identical. return(true); }
public int CompareTo(UnicodeString str) { //int result = String.CompareTo(str.String); int result = string.Compare(String, str.String, StringComparison.CurrentCulture); //As per the Equals method lets do this in stages if (result != 0) { return(result); } //OK string appears to be equal but now lets compare formatting Runs if ((field_4_format_Runs == null) && (str.field_4_format_Runs == null)) { //Strings are Equal, and there are no formatting Runs. return(0); } if ((field_4_format_Runs == null) && (str.field_4_format_Runs != null)) { //Strings are Equal, but one or the other has formatting Runs return(1); } if ((field_4_format_Runs != null) && (str.field_4_format_Runs == null)) { //Strings are Equal, but one or the other has formatting Runs return(-1); } //Strings are Equal, so now compare formatting Runs. int size = field_4_format_Runs.Count; if (size != str.field_4_format_Runs.Count) { return(size - str.field_4_format_Runs.Count); } for (int i = 0; i < size; i++) { FormatRun Run1 = field_4_format_Runs[(i)]; FormatRun run2 = str.field_4_format_Runs[(i)]; result = Run1.CompareTo(run2); if (result != 0) { return(result); } } //Well the format Runs are equal as well!, better check the ExtRst data if ((field_5_ext_rst == null) && (str.field_5_ext_rst == null)) { return(0); } if ((field_5_ext_rst == null) && (str.field_5_ext_rst != null)) { return(1); } if ((field_5_ext_rst != null) && (str.field_5_ext_rst == null)) { return(-1); } result = field_5_ext_rst.CompareTo(str.field_5_ext_rst); if (result != 0) { return(result); } //Phew!! After all of that we have finally worked out that the strings //are identical. return(0); }
/** * Our handling of Equals is inconsistent with CompareTo. The trouble is because we don't truely understand * rich text fields yet it's difficult to make a sound comparison. * * @param o The object to Compare. * @return true if the object is actually Equal. */ public override bool Equals(Object o) { if (!(o is UnicodeString)) { return(false); } UnicodeString other = (UnicodeString)o; //OK lets do this in stages to return a quickly, first check the actual string bool eq = ((field_1_charCount == other.field_1_charCount) && (field_2_optionflags == other.field_2_optionflags) && field_3_string.Equals(other.field_3_string)); if (!eq) { return(false); } //OK string appears to be equal but now lets compare formatting Runs if ((field_4_format_Runs == null) && (other.field_4_format_Runs == null)) { //Strings are Equal, and there are not formatting Runs. return(true); } if (((field_4_format_Runs == null) && (other.field_4_format_Runs != null)) || (field_4_format_Runs != null) && (other.field_4_format_Runs == null)) { //Strings are Equal, but one or the other has formatting Runs return(false); } //Strings are Equal, so now compare formatting Runs. int size = field_4_format_Runs.Count; if (size != other.field_4_format_Runs.Count) { return(false); } for (int i = 0; i < size; i++) { FormatRun Run1 = field_4_format_Runs[(i)]; FormatRun run2 = other.field_4_format_Runs[(i)]; if (!Run1.Equals(run2)) { return(false); } } // Well the format Runs are equal as well!, better check the ExtRst data if (field_5_ext_rst == null && other.field_5_ext_rst == null) { // Good } else if (field_5_ext_rst != null && other.field_5_ext_rst != null) { int extCmp = field_5_ext_rst.CompareTo(other.field_5_ext_rst); if (extCmp == 0) { // Good } else { return(false); } } else { return(false); } //Phew!! After all of that we have finally worked out that the strings //are identical. return(true); }
public void RemoveFormatRun(FormatRun r) { field_4_format_runs.Remove(r); if (field_4_format_runs.Count == 0) { field_4_format_runs = null; field_2_optionflags = richText.ClearByte(field_2_optionflags); } }
/** Adds a font run to the formatted string. * * If a font run exIsts at the current charcter location, then it Is * Replaced with the font run to be Added. */ public void AddFormatRun(FormatRun r) { if (field_4_format_runs == null) field_4_format_runs = new ArrayList(); int index = FindFormatRunAt(r.Char); if (index != -1) field_4_format_runs.Remove(index); field_4_format_runs.Add(r); //Need to sort the font runs to Ensure that the font runs appear in //Char order field_4_format_runs.Sort(); //Make sure that we now say that we are a rich string field_2_optionflags = richText.SetByte(field_2_optionflags); }