C# Class SIL.FieldWorks.UnicodeCharEditor.PUAInstaller

Mostra file Open project: sillsdev/FieldWorks Class Usage Examples

Private Properties

Property Type Description
AddTempFile void
AddToLists void
AddUndoFileFrame void
CheckForIcuLocked bool
CreateXxFile string
GetField string
GetIcuExecutable string
HasBidiData bool
IncrementCount void
InsertCharacters void
LogCodepoint void
MakeDebugBidifiles void
ModifyUCDFile void
ParseCustomCharsFile void
ReadToEndOfSection string
RemoveTempFiles void
RunProcess void
SubHex int
UpdateUCDFile void
WriteBidiCodepointBlock void
WriteBidiRange void
WriteCodepointBlock void
WriteRange void
WriteUnicodeDataLine void

Public Methods

Method Description
AddHex ( string hex, int num ) : string

Adds a number to a hex string

AddUCDLine ( TextWriter writer, IUcdCharacter ucdCharacter, bool add ) : void

Adds/"deletes" a given puaCharacter to the given TextWriter Will write a DerivedBidiClass.txt style line.

BackupOrig ( string inputFilespec ) : string

Create the "original" (backup) copy of the file to be modified, if it doesn't already exist.

ChangeFileExtension ( string inputFilespec, string newExtension ) : string

Replace the file extension with 'newExtension'.

CreateBackupFile ( string inputFilespec ) : string

This method will create the backup of the original input file.

CreateNewFileName ( string inputFilespec, string nameSplice ) : string

This method appends 'nameSplice' to a file 'inputFilespec'.

CreateTempFile ( string inputFilespec ) : string

This method will create the temporary work file copy of the original input file.

DeleteFile ( string file ) : bool

FileCopyWithLogging ( string inName, string outName, bool overwrite ) : void

GetProperty ( string line ) : string

Reads the Property value from the given line of a UCD text file. (For example, if the text file is DerivedBidiClass.txt, this reads the bidi class value from the given line of a DerivedBidiClass.txt file.)

InstallPUACharacters ( string filename ) : void

Installs the PUA characters (PUADefinitions) from the given xml file We do this by: 1. Maps the XML file to a list of PUACharacter objects 2. Sorts the PUA characters 3. Opens UnicodeDataOverrides.txt for reading and writing 4. Inserts the PUA characters via their codepoints 5. Regenerate nfc.txt and nfkc.txt, the input files for gennorm2, which generates the ICU custom normalization files. 6. Run "gennorm2" to create the actual binary files used by the ICU normalization functions.

MakeOrigFileName ( string inputFilespec ) : string

Given a regular file name, this method returns the file name that is used for storing the 'origional' version of the file.

RemoveBackupFiles ( ) : void

Remove the backup files that were created to restore original files if there were a problem. If this method is called, there was no problem. We're just removing the backup file - much like a temp file at this point.

RestoreFiles ( ) : void

Copies the backup files over the source files and then deletes the backup files.

RestoreOrigFiles ( string directoryName, string extension, bool removeOrig ) : int

RunICUTools ( string unidataDir, string nfcOverridesFileName, string nfkcOverridesFileName ) : void

This runs genprops and gennames in order to use UnicodeData.txt, DerivedBidiClass.txt, as well as other *.txt files in unidata to create icuprefix/uprops.icu and other binary data files.

SafeDeleteFile ( string file ) : bool

SafeFileCopyWithLogging ( string inName, string outName, bool overwrite ) : void

StillInRange ( int codeIndex, List ucdCharacters, string currentBidiClass ) : bool

Checks to make sure the given codeIndex is within the current bidi section. Performs bounds checking as well.

UndoCreateNewFileName ( string savedName, string backupPortion ) : string

Private Methods

Method Description
AddTempFile ( string strFile ) : void

Add a file to the list of temporary files.

AddToLists ( string line, IPuaCharacter puaDefinition, List addToBidi, List removeFromBidi, List addToNorm, List removeFromNorm ) : void

Checks whether the IPuaCharacter needs to be added to the lists, and adds if necessary.

AddUndoFileFrame ( string srcFile, string backupFile ) : void

Create a copy of the backup and source file names for future use.

CheckForIcuLocked ( string inputLocale, bool runSilent, CallingID caller ) : bool

Check for locked ICU files and return

CreateXxFile ( string inputFilespec, string suffix ) : string

This method will create the temporary work file copy of the original input file.

GetField ( string line, int field ) : string

Retrieves the given field from the given UnicodeData.txt line

GetIcuExecutable ( string exeName ) : string
HasBidiData ( string line ) : bool

returns true if the line is not just a comment i.e if it is of either of the following forms ------- ; ------ # ------ ------- ; ------- NOT ----- # ----- ; ------

IncrementCount ( int &currentCount, string line ) : void

Given a line containing a valid code or code range, increments the count to include the code or code range. Uses XXXX..YYYY style range.

InsertCharacters ( IPuaCharacter puaDefinitions, string originalOverrides, string customOverrides ) : void

Inserts the given PUADefinitions (any Unicode character) into the UnicodeData.txt file. This accounts for all the cases of inserting into the "first/last" blocks. That is, it will split the blocks into two or move the first and last tags to allow a codepoint to be inserted correctly. Also, this accounts for Hexadecimal strings that are within the unicode range, not just four digit unicode files. Assumptions made about the format The codepoints are in order There first last block will always have no space between the word first and the following ">" No other data entries contain the word first followed by a ">" There will always be a "last" on the line directly after a "first".

Pseudocode for inserting lines: if the unicodePoint is a first tag Get first and last uncodePoint range Stick into array all the xmlPoints that fit within the uncodePoint range Look at the next xmlPoint if there are any call WriteCodepointBlock subroutine else if the unicodePoint is greater than the last point but less than or equal to "the xmlPoint" insert the missing line or replace the line look at the next xmlPoint else do nothing except write the line

LogCodepoint ( string code ) : void

Prints a message to the console when storing a Unicode character.

MakeDebugBidifiles ( StringWriter stringWriter, IEnumerable addToBidi, IEnumerable removeFromBidi ) : void

Makes three debug files for the DerivedBidiClass.txt: A: Saves the "in-between" state (after deleting, before adding) B: Saves a list of what we are adding and deleting. C: Saves an actual file that doesn't add or delete anything. This will update the numbers, but won't do anything else

ModifyUCDFile ( TextReader tr, TextWriter tw, List ucdCharacters, bool add ) : void

This function will add or remove the given PUA characters from the given DerivedBidiClass.txt file by either inserting or not inserting them as necessary as it reads through the file in a single pass from tr to tw.

Assumptions The like Bidi values are grouped together Non Assumptions: That comments add any information to the file. We don't use comments for parsing. That "blank" lines appear only between different bidi value sections. That the comments should be in the format: # field2 [length of range] Name_of_First_Character..Name_of_Last_Charachter (If it is not, we'll just ignore.

ParseCustomCharsFile ( string filename ) : void
ReadToEndOfSection ( TextReader reader, TextWriter writer, string lastProperty, int currentCount, IUcdCharacter ucdCharacter ) : string

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.

RemoveTempFiles ( ) : void

Delete all files in the list of temporary files.

RunProcess ( string executable, string args ) : void
SubHex ( string hex, string hex2 ) : int

Subtracts two hex numbers and returns an integer value of their difference. i.e. returns an int representing hex-hex2

UpdateUCDFile ( List addToUCD, List removeFromUCD ) : void

Updates a UCD style file as necessary. so that the entries match the ones we just inserted into UnicodeData.txt.

A UCD file is a "Unicode Character Database" text file. The specific documentation can be found at: http://www.unicode.org/Public/UNIDATA/UCD.html#UCD_File_Format

WriteBidiCodepointBlock ( TextWriter writer, string originalBeginningCode, string originalEndCode, List codepointsWithinRange, string generalCategory, string firstName, string lastName, bool add ) : void

Write a codepoint block, inserting the necessary codepoints properly.

WriteBidiRange ( TextWriter writer, string beginning, string end, string generalCategory, string firstName, string lastName, string bidiValue ) : void

Writes a block representing a range given first and last. If first is not before last, it will do the appropriate printing.

WriteCodepointBlock ( StreamWriter writer, string blockName, string beginning, string end, IEnumerable puaCharacters, string data, List addToBidi, List removeFromBidi, List addToNorm, List removeFromNorm ) : void

Write a codepoint block, inserting the necessary codepoints properly.

WriteRange ( StreamWriter writer, string beginning, string end, string name, string data ) : void

Writes a block representing a range given first and last. If first is not before last, it will do the appropriate printing.

WriteUnicodeDataLine ( IPuaCharacter puaChar, TextWriter tw ) : void

Writes a UnicodeData.txt style line including comments.

Method Details

AddHex() public static method

Adds a number to a hex string
public static AddHex ( string hex, int num ) : string
hex string The hex string you want to add
num int The number you want to add to the string
return string

AddUCDLine() public method

Adds/"deletes" a given puaCharacter to the given TextWriter Will write a DerivedBidiClass.txt style line.
public AddUCDLine ( TextWriter writer, IUcdCharacter ucdCharacter, bool add ) : void
writer System.IO.TextWriter
ucdCharacter IUcdCharacter The character to add or delete
add bool
return void

BackupOrig() public static method

Create the "original" (backup) copy of the file to be modified, if it doesn't already exist.
public static BackupOrig ( string inputFilespec ) : string
inputFilespec string This is the file to make a copy of.
return string

ChangeFileExtension() public static method

Replace the file extension with 'newExtension'.
public static ChangeFileExtension ( string inputFilespec, string newExtension ) : string
inputFilespec string Input file name to modify.
newExtension string The new file Extension.
return string

CreateBackupFile() public static method

This method will create the backup of the original input file.
public static CreateBackupFile ( string inputFilespec ) : string
inputFilespec string This is the file to make a backup of.
return string

CreateNewFileName() public static method

This method appends 'nameSplice' to a file 'inputFilespec'.
public static CreateNewFileName ( string inputFilespec, string nameSplice ) : string
inputFilespec string Input file name to modify.
nameSplice string The 'text' to append to the file name before the /// extension.
return string

CreateTempFile() public static method

This method will create the temporary work file copy of the original input file.
public static CreateTempFile ( string inputFilespec ) : string
inputFilespec string This is the file to make a copy of.
return string

DeleteFile() public static method

public static DeleteFile ( string file ) : bool
file string
return bool

FileCopyWithLogging() public static method

public static FileCopyWithLogging ( string inName, string outName, bool overwrite ) : void
inName string
outName string
overwrite bool
return void

GetProperty() public static method

Reads the Property value from the given line of a UCD text file. (For example, if the text file is DerivedBidiClass.txt, this reads the bidi class value from the given line of a DerivedBidiClass.txt file.)
public static GetProperty ( string line ) : string
line string A line from a UCD file in the following format: /// code;Property[; other] [ # other]
return string

InstallPUACharacters() public method

Installs the PUA characters (PUADefinitions) from the given xml file We do this by: 1. Maps the XML file to a list of PUACharacter objects 2. Sorts the PUA characters 3. Opens UnicodeDataOverrides.txt for reading and writing 4. Inserts the PUA characters via their codepoints 5. Regenerate nfc.txt and nfkc.txt, the input files for gennorm2, which generates the ICU custom normalization files. 6. Run "gennorm2" to create the actual binary files used by the ICU normalization functions.
public InstallPUACharacters ( string filename ) : void
filename string Our XML file containing our PUA Defintions
return void

MakeOrigFileName() public static method

Given a regular file name, this method returns the file name that is used for storing the 'origional' version of the file.
public static MakeOrigFileName ( string inputFilespec ) : string
inputFilespec string
return string

RemoveBackupFiles() public method

Remove the backup files that were created to restore original files if there were a problem. If this method is called, there was no problem. We're just removing the backup file - much like a temp file at this point.
public RemoveBackupFiles ( ) : void
return void

RestoreFiles() public method

Copies the backup files over the source files and then deletes the backup files.
public RestoreFiles ( ) : void
return void

RestoreOrigFiles() public static method

public static RestoreOrigFiles ( string directoryName, string extension, bool removeOrig ) : int
directoryName string
extension string
removeOrig bool
return int

RunICUTools() public method

This runs genprops and gennames in order to use UnicodeData.txt, DerivedBidiClass.txt, as well as other *.txt files in unidata to create icuprefix/uprops.icu and other binary data files.
public RunICUTools ( string unidataDir, string nfcOverridesFileName, string nfkcOverridesFileName ) : void
unidataDir string
nfcOverridesFileName string
nfkcOverridesFileName string
return void

SafeDeleteFile() public static method

public static SafeDeleteFile ( string file ) : bool
file string
return bool

SafeFileCopyWithLogging() public static method

public static SafeFileCopyWithLogging ( string inName, string outName, bool overwrite ) : void
inName string
outName string
overwrite bool
return void

StillInRange() public method

Checks to make sure the given codeIndex is within the current bidi section. Performs bounds checking as well.
public StillInRange ( int codeIndex, List ucdCharacters, string currentBidiClass ) : bool
codeIndex int The index of a PUA character in puaCharacters
ucdCharacters List The list of PUA characters
currentBidiClass string The current bidi class value. If puaCharacters[codeIndex] doesn't match this we aren't in range.
return bool

UndoCreateNewFileName() public static method

public static UndoCreateNewFileName ( string savedName, string backupPortion ) : string
savedName string
backupPortion string
return string