/// <summary> /// Read to the end of a given section of matching bidi class values. /// Passes everything read through to the writer. /// If this finds a section count comment, it will replace it with the current count. /// </summary> /// <param name="reader">The reader to read through.</param> ///<param name="writer"></param> ///<param name="lastProperty">The section we need to reed to the end of.</param> /// <param name="currentCount">The count of characters found before reading to the end of the section.</param> /// <param name="ucdCharacter">UCD Character used to know what kind of UCD file we are parsing. /// The actual contencts of the UCD Character are ignored.</param> /// <returns>The first line of the next section.</returns> private static string ReadToEndOfSection(TextReader reader, TextWriter writer, string lastProperty, int currentCount, IUcdCharacter ucdCharacter) { string line; while ((line = reader.ReadLine()) != null) { // if there is a bidi class value to read if (HasBidiData(line)) { // increments the current count of codepoints found so far. IncrementCount(ref currentCount, line); // read the bidi value from the line var currentProperty = GetProperty(line); // if it isn't in the current section we are done with section. if (!ucdCharacter.SameRegion(currentProperty, lastProperty)) break; } // if its a comment, find the total count comment and replace it with the current count. else if (line.ToLowerInvariant().IndexOf("total code points") != -1) { line = "# Total code points: " + currentCount; currentCount = 0; } // Write through all lines except the first line of the next section writer.WriteLine(line); } // Return the last line that we read // This is the first line of the next section, so someone will probably want to parse it. return line; }
/// <summary> /// Adds/"deletes" a given puaCharacter to the given TextWriter /// Will write a DerivedBidiClass.txt style line. /// </summary> /// <param name="writer"></param> /// <param name="ucdCharacter">The character to add or delete</param> /// <param name="add"></param> public void AddUCDLine(TextWriter writer, IUcdCharacter ucdCharacter, bool add) { if (add) writer.WriteLine(ucdCharacter + " " + m_comment); // Uncomment this line to replace lines with a comment indicating that the line was removed. // else // writer.WriteLine("# DELETED LINE: {0}",puaCharacter.ToBidiString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares two UCDCharacters. /// If the two are in the same "region" sorted as though they are identical, they will "match". /// For most files this will just be as simple "equals" comparing the strings. /// However, for the DerivedNormalizationProps.txt file, /// both NFC_NO and NFC_MAYBE are the in the same region. /// </summary> /// <param name="ucd">The ucd.</param> /// <returns> /// True if the properties are in the same "region" sorted as though they are identical in a file. /// </returns> /// ------------------------------------------------------------------------------------ public bool SameRegion(IUcdCharacter ucd) { return SameRegion(ucd.Property); }