OpenPetra
Free Administration Software for Non-Profits
Ict.Common.IO.TTextFile Class Reference

Static Public Member Functions

static void RecurseFilesAndDirectories (string APath, string AExt, ProcessFileType func)
 todo: exclude directory names, e.g. CSV, see BuildTools\ProgressConverter\AnalyseProgressFiles.cs More...
 
static void Dos2Unix (String filename)
 remove carriage return More...
 
static void Unix2Dos (String filename)
 add carriage return More...
 
static void ConvertToUnicode (String AFilename, String AEncodingCodePage)
 convert a text file from a given code page to Unicode More...
 
static bool SameContent (String filename1, String filename2, bool AIgnoreNewLine=true, SortedList< string, string >AToReplace=null, bool AWithLogging=false)
 check if the two text files have the same content if AIgnoreNewLine is true: if there are multiple percentage characters in the first file, then ignore the text in that position More...
 
static string Diff (String TextA, String TextB)
 very simple function to show the difference of two texts More...
 
static bool UpdateFile (String AOrigFilename, bool AIgnoreNewLine=false)
 this will compare the original file with the file that has the same name but an extension .new additionally at the end if the files have identical content, the new file is dropped otherwise new file is renamed to the original file name. there is no backup. More...
 
static Encoding GetFileEncoding (String AFilename, Encoding ADefaultEncoding=null)
 
static bool AutoDetectTextEncodingAndOpenFile (string AFilename, out String AText, out Encoding AEncoding, out bool AHasBOM, out bool AIsAmbiguousUTF, out byte[] ARawBytes, int ATestByteCount=0)
 Function to detect the encoding for UTF-7, UTF-8/16/32 (bom, no bom, little or big endian), and local default codepage More...
 

Detailed Description

Some useful functions for dealing with text files; only used for BuildTools at the moment

Member Function Documentation

◆ AutoDetectTextEncodingAndOpenFile()

static bool Ict.Common.IO.TTextFile.AutoDetectTextEncodingAndOpenFile ( string  AFilename,
out String  AText,
out Encoding  AEncoding,
out bool  AHasBOM,
out bool  AIsAmbiguousUTF,
out byte[]  ARawBytes,
int  ATestByteCount = 0 
)
inlinestatic

Function to detect the encoding for UTF-7, UTF-8/16/32 (bom, no bom, little or big endian), and local default codepage

Parameters
AFilenameFilename to open
ATextThe content of the file using the discovered encoding.
AEncodingThe discovered encoding. One of the six UTF options or the user's default ANSI code page.
AHasBOMWill be set to true if the file has a BOM header
AIsAmbiguousUTFWill be set to true if the text that the method outputs is ambiguous. This will be true if the determination of the UTF format was statistically not significant
ARawBytesThe raw bytes read from the file. This can be used to display alternative text for ambiguous options
ATestByteCountNumber of bytes to check of the file (to save processing). Higher value is slower, but more reliable (especially UTF-8 with special characters later on may appear to be ASCII initially). If ATestByteCount = 0, then ATestByteCount becomes the length of the file (for maximum reliability).
Returns
True if the file was opened and read successfully. False if the file could not be opened or if the file is empty.

◆ ConvertToUnicode()

static void Ict.Common.IO.TTextFile.ConvertToUnicode ( String  AFilename,
String  AEncodingCodePage 
)
inlinestatic

convert a text file from a given code page to Unicode

Parameters
AFilename
AEncodingCodePage

◆ Diff()

static string Ict.Common.IO.TTextFile.Diff ( String  TextA,
String  TextB 
)
inlinestatic

very simple function to show the difference of two texts

◆ Dos2Unix()

static void Ict.Common.IO.TTextFile.Dos2Unix ( String  filename)
inlinestatic

remove carriage return

◆ GetFileEncoding()

static Encoding Ict.Common.IO.TTextFile.GetFileEncoding ( String  AFilename,
Encoding  ADefaultEncoding = null 
)
inlinestatic

StreamReader DetectEncodingFromByteOrderMarks does not work for ANSI? therefore we have to detect the encoding by comparing the first bytes of the file

◆ RecurseFilesAndDirectories()

static void Ict.Common.IO.TTextFile.RecurseFilesAndDirectories ( string  APath,
string  AExt,
ProcessFileType  func 
)
inlinestatic

todo: exclude directory names, e.g. CSV, see BuildTools\ProgressConverter\AnalyseProgressFiles.cs

◆ SameContent()

static bool Ict.Common.IO.TTextFile.SameContent ( String  filename1,
String  filename2,
bool  AIgnoreNewLine = true,
SortedList< string, string >  AToReplace = null,
bool  AWithLogging = false 
)
inlinestatic

check if the two text files have the same content if AIgnoreNewLine is true: if there are multiple percentage characters in the first file, then ignore the text in that position

◆ Unix2Dos()

static void Ict.Common.IO.TTextFile.Unix2Dos ( String  filename)
inlinestatic

add carriage return

◆ UpdateFile()

static bool Ict.Common.IO.TTextFile.UpdateFile ( String  AOrigFilename,
bool  AIgnoreNewLine = false 
)
inlinestatic

this will compare the original file with the file that has the same name but an extension .new additionally at the end if the files have identical content, the new file is dropped otherwise new file is renamed to the original file name. there is no backup.

the intention is to generate code, but not to touch it for VCS if not necessary

Parameters
AOrigFilenamethe original name of the file
AIgnoreNewLineshould ignore line break character differences
Returns

The documentation for this class was generated from the following file: