summaryrefslogtreecommitdiff
path: root/src/corelib/fpg_utils.pas
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2009-06-08 16:51:45 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2009-06-08 16:51:45 +0200
commit435bac31bc0bea6c05fc16883c7937c724d8eec2 (patch)
tree49e385b958e0f4e716da48f96f30938cabba1b2f /src/corelib/fpg_utils.pas
parentb0e1a5fffbf05c6e2b4c91d9d87d318cae86138e (diff)
downloadfpGUI-435bac31bc0bea6c05fc16883c7937c724d8eec2.tar.xz
DebugLn() improvements
* Moved DebugLn() implementations from fpg_pofiles to fpg_main * DebugLn() should now work even on Windows GUI applications without throwing IO errors. * Implemented 3 new UTF-8 file methods in fpg_utils.
Diffstat (limited to 'src/corelib/fpg_utils.pas')
-rw-r--r--src/corelib/fpg_utils.pas99
1 files changed, 69 insertions, 30 deletions
diff --git a/src/corelib/fpg_utils.pas b/src/corelib/fpg_utils.pas
index 603ecca9..011319e9 100644
--- a/src/corelib/fpg_utils.pas
+++ b/src/corelib/fpg_utils.pas
@@ -1,7 +1,7 @@
{
fpGUI - Free Pascal GUI Library
- Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this
+ Copyright (C) 2006 - 2009 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
@@ -12,7 +12,7 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Description:
- Abstracted OS specific function to work in a cross-platfrom manner.
+ Abstracted OS specific function to work in a cross-platform manner.
}
unit fpg_utils;
@@ -22,74 +22,77 @@ unit fpg_utils;
interface
uses
- Classes, SysUtils, fpg_base;
+ Classes,
+ SysUtils,
+ fpg_base;
// *** Platform specific functions ***
-function fpgToOSEncoding(aString: TfpgString): string;
-function fpgFromOSEncoding(aString: string): TfpgString;
+function fpgToOSEncoding(aString: TfpgString): string;
+function fpgFromOSEncoding(aString: string): TfpgString;
procedure fpgOpenURL(const aURL: TfpgString);
// *** Common functions for all platforms ***
-function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: boolean = true): TfpgString;
-function fpgAppendPathDelim(const Path: TfpgString): TfpgString;
-function fpgHasSubDirs(const Dir: TfpgString; AShowHidden: Boolean): Boolean;
-function fpgAllFilesMask: TfpgString;
+function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: Boolean = True): TfpgString;
+function fpgAppendPathDelim(const Path: TfpgString): TfpgString;
+function fpgHasSubDirs(const Dir: TfpgString; AShowHidden: Boolean): Boolean;
+function fpgAllFilesMask: TfpgString;
+function fpgConvertLineEndings(const s: TfpgString): TfpgString;
-// RTL wrapper filesystem functions with platform independant encoding
-// These functions are common for all platforms and rely on fpgXXXPlatformEncoding
+ // RTL wrapper filesystem functions with platform independant encoding
+ // These functions are common for all platforms and rely on fpgXXXPlatformEncoding
-function fpgFindFirst(const Path: TfpgString; Attr: Longint; out Rslt: TSearchRec): Longint;
-function fpgFindNext(var Rslt: TSearchRec): Longint;
-function fpgGetCurrentDir: TfpgString;
-function fpgSetCurrentDir(const NewDir: TfpgString): Boolean;
-function fpgExpandFileName(const FileName: TfpgString): TfpgString;
-function fpgFileExists(const FileName: TfpgString): Boolean;
+function fpgFindFirst(const Path: TfpgString; Attr: longint; out Rslt: TSearchRec): longint;
+function fpgFindNext(var Rslt: TSearchRec): longint;
+function fpgGetCurrentDir: TfpgString;
+function fpgSetCurrentDir(const NewDir: TfpgString): Boolean;
+function fpgExpandFileName(const FileName: TfpgString): TfpgString;
+function fpgFileExists(const FileName: TfpgString): Boolean;
+function fpgDirectoryExists(const ADirectory: TfpgString): Boolean;
+function fpgExtractFileDir(const FileName: TfpgString): TfpgString;
implementation
-{ No USES clause is allowed here! Add it to the include file shown below. }
+ { No USES clause is allowed here! Add it to the include file shown below. }
-// Platform specific encoding handling functions
+ // Platform specific encoding handling functions
{$I fpg_utils_impl.inc}
-
-function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: boolean = true): TfpgString;
+function fpgAddTrailingValue(const ALine, AValue: TfpgString; ADuplicates: Boolean = True): TfpgString;
begin
if ALine = '' then
begin
- result := ALine;
+ Result := ALine;
Exit; //==>
end;
if ADuplicates then
begin
- result := ALine + AValue;
+ Result := ALine + AValue;
Exit; //==>
end;
if (not SameText(Copy(ALine, Length(ALine) - Length(AValue) + 1, Length(AValue)), AValue)) then
- result := ALine + AValue
+ Result := ALine + AValue
else
- result := ALine;
+ Result := ALine;
end;
-function fpgFindFirst(const Path: TfpgString; Attr: Longint; out
- Rslt: TSearchRec): Longint;
+function fpgFindFirst(const Path: TfpgString; Attr: longint; out Rslt: TSearchRec): longint;
begin
- Result := FindFirst(fpgToOSEncoding(Path), Attr, Rslt);
+ Result := FindFirst(fpgToOSEncoding(Path), Attr, Rslt);
Rslt.Name := fpgFromOSEncoding(Rslt.Name);
end;
-function fpgFindNext(var Rslt: TSearchRec): Longint;
+function fpgFindNext(var Rslt: TSearchRec): longint;
begin
- Result := FindNext(Rslt);
+ Result := FindNext(Rslt);
Rslt.Name := fpgFromOSEncoding(Rslt.Name);
end;
@@ -113,6 +116,16 @@ begin
Result := FileExists(fpgToOSEncoding(FileName));
end;
+function fpgDirectoryExists(const ADirectory: TfpgString): Boolean;
+begin
+ Result := DirectoryExists(fpgToOSEncoding(ADirectory));
+end;
+
+function fpgExtractFileDir(const FileName: TfpgString): TfpgString;
+begin
+ Result := ExtractFileDir(fpgToOSEncoding(FileName));
+end;
+
function fpgAppendPathDelim(const Path: TfpgString): TfpgString;
begin
if (Path <> '') and (Path[length(Path)] <> PathDelim) then
@@ -169,5 +182,31 @@ begin
{$ENDIF}
end;
+function fpgConvertLineEndings(const s: TfpgString): TfpgString;
+var
+ i: integer;
+ EndingStart: longint;
+begin
+ Result := s;
+ i := 1;
+ while (i <= length(Result)) do
+ if Result[i] in [#10, #13] then
+ begin
+ EndingStart := i;
+ Inc(i);
+ if (i <= length(Result)) and (Result[i] in [#10, #13]) and (Result[i] <> Result[i - 1]) then
+ Inc(i);
+ if (length(LineEnding) <> i - EndingStart) or (LineEnding <> copy(Result, EndingStart, length(LineEnding))) then
+ begin
+ // line end differs => replace with current LineEnding
+ Result := copy(Result, 1, EndingStart - 1) + LineEnding + copy(Result, i, length(Result));
+ i := EndingStart + length(LineEnding);
+ end;
+ end
+ else
+ Inc(i);
+end;
+
+
end.