[JEDI.NET-commits] main/run Jedi.Collections.InlineEditable.pas,NONE,1.1 Jedi.Drawing.Colors.pas,NON
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-12-05 13:20:08
|
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8541/main/run Added Files: Jedi.Collections.InlineEditable.pas Jedi.Drawing.Colors.pas Jedi.IO.Paths.pas Jedi.System.Attributes.pas Jedi.System.Strings.pas Removed Files: Jedi.Collections.pas Jedi.Drawing.pas Jedi.IO.pas Jedi.Strings.pas Jedi.System.pas Log Message: Converted to Delphi 2005. Delphi 8 will no longer be supported. --- NEW FILE: Jedi.Collections.InlineEditable.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Collections.pas, released on 2004-06-13. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet [...1260 lines suppressed...] end; function InlineDictionaryBase.GetItemDescription(key: System.Object): string; begin Result := ''; end; function InlineDictionaryBase.GetItemEmptyValue(key: System.Object): System.Object; begin Result := nil; end; function InlineDictionaryBase.GetItemProperty(key, value: System.Object): PropertyDescriptor; begin Result := InlineCollectionUtils.CreateItemProperty(value.GetType, AttributeArray.Create(), Self, key.ToString, GetItemDescription(key), key, GetItemEmptyValue(key)); end; {$ENDREGION} end. --- Jedi.System.pas DELETED --- --- Jedi.Strings.pas DELETED --- --- Jedi.Collections.pas DELETED --- --- NEW FILE: Jedi.IO.Paths.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.IO.pas, released on 2004-11-24. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.IO.Paths.pas,v 1.1 2004/12/05 13:19:48 jedi_mbe Exp $ unit Jedi.IO.Paths; interface {$REGION 'Path manipulations'} type CharArray = array of Char; Path = class {$REGION 'PathConfig'} public type PathConfig = class strict private FDirSep: Char; FAltDirSep: Char; FVolSep: Char; FInvalidPathChars: array of Char; public constructor Create; overload; constructor Create(directorySeparator, altDirectorySeparator, volumeSeparator: Char; invalidPathChars: array of Char); overload; function AltDirectorySeparator: Char; function DirectorySeparator: Char; function InvalidPathChars: CharArray; function VolumeSeparator: Char; end; {$ENDREGION} strict private class constructor Create; strict protected constructor Create; strict protected class var SysConfig: PathConfig; public class function Combine(paths: array of string): string; overload; static; class function Combine(paths: array of string; config: PathConfig): string; overload; static; class function Combine(path1, path2: string): string; overload; static; class function Combine(path1, path2: string; config: PathConfig): string; overload; static; class function EnsureEndingDirectorySeparator(path: string): string; overload; static; class function EnsureEndingDirectorySeparator(path: string; config: PathConfig): string; overload; static; class function IsPathRooted(path: string): Boolean; overload; static; class function IsPathRooted(path: string; config: PathConfig): Boolean; overload; static; class function IsValid(path: string): Boolean; overload; static; class function IsValid(path: string; config: PathConfig): Boolean; overload; static; class function IsValid(path: string; allowWildcards: Boolean): Boolean; overload; static; class function IsValid(path: string; allowWildcards: Boolean; config: PathConfig): Boolean; overload; static; class function IsVolumePath(path: string): Boolean; overload; static; class function IsVolumePath(path: string; config: PathConfig): Boolean; overload; static; class function Normalize(path: string): string; overload; static; class function Normalize(path: string; config: PathConfig): string; overload; static; class function SystemConfig: PathConfig; static; end; PathException = class (SystemException) end; {$ENDREGION} implementation {$REGION 'implementation uses'} uses System.Collections, System.IO, System.Text, Jedi.System; {$ENDREGION} {$AUTOBOX ON} {$REGION 'Path'} class constructor Path.Create; begin SysConfig := Path.PathConfig.Create; end; constructor Path.Create; begin inherited Create; end; class function Path.Combine(paths: array of string): string; begin Result := Combine(paths, SysConfig); end; class function Path.Combine(paths: array of string; config: PathConfig): string; var i: Integer; lastRoot: Integer; al: ArrayList; level: Integer; sb: StringBuilder; begin if not Assigned(paths) then raise ArgumentNullException.Create('paths'); i := &Array(paths).Length - 1; lastRoot := -1; while (i >= 0) and not IsVolumePath(paths[i], config) do begin if (lastRoot = -1) and IsPathRooted(paths[i], config) then lastRoot := i; Dec(i); end; al := ArrayList.Create; if i = -1 then i := lastRoot else if i < lastRoot then begin al.Add(StringUtils.Before(paths[i], config.VolumeSeparator) + config.VolumeSeparator); i := lastRoot; end; if i = -1 then i := 0; while i < &Array(paths).Length do begin al.AddRange(&Array(StringUtils.RemoveDuplicateChars(paths[i].Trim([config.DirectorySeparator, config.AltDirectorySeparator]), [config.DirectorySeparator, config.AltDirectorySeparator]).Split( [config.DirectorySeparator, config.AltDirectorySeparator]))); Inc(i); end; i := 0; while (i < al.Count) and (System.String.Create('.', string(al[i]).Length).Equals(string(al[i]))) do Inc(i); while (i < al.Count) do begin if string(al[i]).Equals(System.String.Create('.', string(al[i]).Length)) then begin level := string(al[i]).Length - 1; if level > i then raise PathException.Create('Level traversal is too deep.'); al.RemoveRange(i - level, level + 1); Dec(i, level); end else Inc(i); end; sb := StringBuilder.Create(256); for i := 0 to al.Count - 1 do sb.Append(string(al[i]) + config.DirectorySeparator); if al.Count > 0 then sb.Remove(sb.Length - 1, 1); Result := Normalize(sb.ToString, config); if (lastRoot <> -1) and not IsVolumePath(Result, config) then Result := Result.Insert(0, config.DirectorySeparator); end; class function Path.Combine(path1, path2: string): string; begin Result := Combine([path1, path2], SysConfig); end; class function Path.Combine(path1, path2: string; config: PathConfig): string; begin Result := Combine([path1, path2], config); end; class function Path.EnsureEndingDirectorySeparator(path: string): string; begin Result := EnsureEndingDirectorySeparator(path, SysConfig); end; class function Path.EnsureEndingDirectorySeparator(path: string; config: PathConfig): string; begin if not path.EndsWith(config.DirectorySeparator) then Result := path + config.DirectorySeparator else Result := path; end; class function Path.IsPathRooted(path: string): Boolean; begin Result := IsPathRooted(path, SysConfig); end; class function Path.IsPathRooted(path: string; config: PathConfig): Boolean; begin Result := IsVolumePath(path, config) or path.StartsWith(config.DirectorySeparator) or path.StartsWith(config.AltDirectorySeparator); end; class function Path.IsValid(path: string): Boolean; begin Result := IsValid(path, False, SysConfig); end; class function Path.IsValid(path: string; config: PathConfig): Boolean; begin Result := IsValid(path, False, config); end; class function Path.IsValid(path: string; allowWildcards: Boolean): Boolean; begin Result := IsValid(path, allowWildcards, SysConfig); end; class function Path.IsValid(path: string; allowWildcards: Boolean; config: PathConfig): Boolean; var i: Integer; begin Result := ((path.IndexOf(config.VolumeSeparator) = -1) or IsVolumePath(path, config)) and (path.IndexOfAny(config.InvalidPathChars) = -1) and (allowWildcards or (path.IndexOfAny('*?'.ToCharArray) = -1)); i := 0; while Result and (i < path.Length) do begin if (i = 0) or (config.DirectorySeparator = path.Chars[i]) or (config.AltDirectorySeparator = path.Chars[i]) then begin if i > 0 then Inc(i); if (i < path.Length - 1) and (path.Chars[i] = '.') and (path.Chars[i + 1] = '.') then begin while Result and (i < path.Length) and ((config.DirectorySeparator + config.AltDirectorySeparator).IndexOf(path.Chars[i]) = -1) do begin Result := path.Chars[i] = '.'; Inc(i); end; end else Inc(i); end else Inc(i); end; end; class function Path.IsVolumePath(path: string): Boolean; begin Result := IsVolumePath(path, SysConfig); end; class function Path.IsVolumePath(path: string; config: PathConfig): Boolean; var idx1: Integer; idx2: Integer; begin idx1 := path.IndexOf(config.VolumeSeparator); if idx1 > -1 then begin idx2 := path.IndexOfAny([config.DirectorySeparator, config.AltDirectorySeparator]); Result := (idx2 = -1) or (idx2 > idx1) and (path.IndexOf(config.VolumeSeparator, idx1 + 1) = -1); end else Result := False; end; class function Path.Normalize(path: string): string; begin Result := Normalize(path, SysConfig); end; class function Path.Normalize(path: string; config: PathConfig): string; var i: Integer; lastSet: Integer; begin Result := path.Replace(config.AltDirectorySeparator, config.DirectorySeparator).Replace( config.DirectorySeparator + '.' + config.DirectorySeparator, ''); while Result.StartsWith('.' + config.DirectorySeparator) do Result := Result.Remove(0, 2); i := Result.Length - 1; while (i >= 1) and (Result.Chars[i] = config.DirectorySeparator) and (Result.Chars[i - 1] <> config.VolumeSeparator) do Dec(i); Result := Result.Substring(0, i + 1); lastSet := -1; repeat lastSet := Result.IndexOf('...', lastSet + 1); if lastSet > -1 then begin i := lastSet + 3; while (i < Result.Length) and (Result.Chars[i] = '.') do Inc(i); Result := Result.Remove(lastSet, i - lastSet).Insert(lastSet, StringUtils.Repeat( '..' + config.DirectorySeparator, i - lastSet - 1)); lastSet := lastSet + 3 * (i - lastSet - 1); end; until lastSet = -1; Result := StringUtils.RemoveDuplicateChars(Result, config.DirectorySeparator); i := Result.IndexOf(config.VolumeSeparator); if (i > -1) and (i < Result.Length - 1) and (Result.Chars[i + 1] <> config.DirectorySeparator) then Result := Result.Insert(i + 1, config.DirectorySeparator); end; class function Path.SystemConfig: PathConfig; begin Result := SysConfig; end; {$ENDREGION} {$REGION 'Path.PathConfig'} constructor Path.PathConfig.Create; begin Create(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.VolumeSeparatorChar, System.IO.Path.InvalidPathChars); end; constructor Path.PathConfig.Create(directorySeparator, altDirectorySeparator, volumeSeparator: Char; invalidPathChars: array of Char); begin inherited Create; FDirSep := directorySeparator; FAltDirSep := altDirectorySeparator; FVolSep := volumeSeparator; FInvalidPathChars := invalidPathChars; end; function Path.PathConfig.AltDirectorySeparator: Char; begin Result := FAltDirSep; end; function Path.PathConfig.DirectorySeparator: Char; begin Result := FDirSep; end; function Path.PathConfig.InvalidPathChars: CharArray; begin Result := FInvalidPathChars; end; function Path.PathConfig.VolumeSeparator: Char; begin Result := FVolSep; end; {$ENDREGION} end. --- NEW FILE: Jedi.System.Attributes.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.System.pas, released on 2004-06-13. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.System.Attributes.pas,v 1.1 2004/12/05 13:19:48 jedi_mbe Exp $ unit Jedi.System.Attributes; interface {$REGION 'interface uses'} uses System.Collections, System.ComponentModel; {$ENDREGION} {$REGION 'Attributes'} type AttributeArray = array of Attribute; AttributeCombineOperation = (Add, Replace, Delete, AddAndReplace); type AttributeUtils = class (System.Object) strict protected constructor Create; class function CombineAttributes(attributes1, attributes2: ArrayList; operation: AttributeCombineOperation): ArrayList; overload; static; class function IndexOf(attrList: ArrayList; attr: System.Object): Integer; static; class function ToArrayList(attrs: array of Attribute): ArrayList; overload; static; class function ToArrayList(attrs: AttributeCollection): ArrayList; overload; static; public class function CombineAttributes(attributes1, attributes2: array of Attribute): AttributeArray; overload; static; class function CombineAttributes(attributes1, attributes2: array of Attribute; operation: AttributeCombineOperation): AttributeArray; overload; static; class function CombineAttributes(attributes1, attributes2: AttributeCollection): AttributeCollection; overload; static; class function CombineAttributes(attributes1, attributes2: AttributeCollection; operation: AttributeCombineOperation): AttributeCollection; overload; static; class function CombineAttributes(attributes1: array of Attribute; attributes2: AttributeCollection): AttributeArray; overload; static; class function CombineAttributes(attributes1: array of Attribute; attributes2: AttributeCollection; operation: AttributeCombineOperation): AttributeArray; overload; static; class function CombineAttributes(attributes1: AttributeCollection; attributes2: array of Attribute): AttributeCollection; overload; static; class function CombineAttributes(attributes1: AttributeCollection; attributes2: array of Attribute; operation: AttributeCombineOperation): AttributeCollection; overload; static; class function GetAttribute(attributes: array of Attribute; attr: Attribute): Attribute; overload; static; class function GetAttribute(attributes: array of Attribute; attrType: System.Type): Attribute; overload; static; class function GetAttribute(attributes: AttributeCollection; attr: Attribute): Attribute; overload; static; class function GetAttribute(attributes: AttributeCollection; attrType: System.Type): Attribute; overload; static; end; {$ENDREGION} implementation {$REGION 'AttributeUtils'} constructor AttributeUtils.Create; begin inherited Create; end; class function AttributeUtils.IndexOf(attrList: ArrayList; attr: System.Object): Integer; var attrType: System.Type; endLoop: Boolean; begin if attr is System.Type then attrType := System.Type(attr) else attrType := attr.GetType; Result := 0; endLoop := False; while (Result < attrList.Count) and not endLoop do begin endLoop := attrType = attrList[Result].GetType; if endLoop and not &Object.ReferenceEquals(attr, attrType) then endLoop := attr.Equals(attrList[Result]); if not endLoop then Inc(Result); end; if Result >= attrList.Count then Result := -1; end; class function AttributeUtils.ToArrayList(attrs: array of Attribute): ArrayList; begin if Assigned(attrs) then Result := ArrayList.Create(&Array(attrs)) else Result := ArrayList.Create; end; class function AttributeUtils.ToArrayList(attrs: AttributeCollection): ArrayList; begin if Assigned(attrs) then Result := ArrayList.Create(attrs) else Result := ArrayList.Create; end; class function AttributeUtils.CombineAttributes(attributes1, attributes2: ArrayList; operation: AttributeCombineOperation): ArrayList; var index: Integer; attrIndex: Integer; begin Result := attributes1; for index := 0 to attributes2.Count - 1 do begin attrIndex := IndexOf(Result, attributes2[index].GetType); if attrIndex > -1 then begin case operation of AddAndReplace, Replace: Result[attrIndex] := attributes2[index]; Delete: Result.RemoveAt(attrIndex); end; end else if (operation = Add) or (operation = AddAndReplace) then Result.Add(attributes2[index]); end; end; class function AttributeUtils.CombineAttributes(attributes1, attributes2: array of Attribute): AttributeArray; begin Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); end; class function AttributeUtils.CombineAttributes(attributes1, attributes2: array of Attribute; operation: AttributeCombineOperation): AttributeArray; begin Result := AttributeArray(CombineAttributes(ToArrayList(attributes1), ToArrayList(attributes2), operation).ToArray(TypeOf(Attribute))); end; class function AttributeUtils.CombineAttributes(attributes1, attributes2: AttributeCollection): AttributeCollection; begin Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); end; class function AttributeUtils.CombineAttributes(attributes1, attributes2: AttributeCollection; operation: AttributeCombineOperation): AttributeCollection; begin Result := AttributeCollection.Create(AttributeArray(CombineAttributes(ToArrayList(attributes1), ToArrayList(attributes2), operation).ToArray(TypeOf(Attribute)))); end; class function AttributeUtils.CombineAttributes(attributes1: array of Attribute; attributes2: AttributeCollection): AttributeArray; begin Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); end; class function AttributeUtils.CombineAttributes(attributes1: array of Attribute; attributes2: AttributeCollection; operation: AttributeCombineOperation): AttributeArray; begin Result := AttributeArray(CombineAttributes(ToArrayList(attributes1), ToArrayList(attributes2), operation).ToArray(TypeOf(Attribute))); end; class function AttributeUtils.CombineAttributes(attributes1: AttributeCollection; attributes2: array of Attribute): AttributeCollection; begin Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); end; class function AttributeUtils.CombineAttributes(attributes1: AttributeCollection; attributes2: array of Attribute; operation: AttributeCombineOperation): AttributeCollection; begin Result := AttributeCollection.Create(AttributeArray(CombineAttributes(ToArrayList(attributes1), ToArrayList(attributes2), operation).ToArray(TypeOf(Attribute)))); end; class function AttributeUtils.GetAttribute(attributes: array of Attribute; attr: Attribute): Attribute; var idx: Integer; begin idx := IndexOf(ToArrayList(attributes), attr); if idx > -1 then Result := attributes[idx] else Result := nil; end; class function AttributeUtils.GetAttribute(attributes: array of Attribute; attrType: System.Type): Attribute; var idx: Integer; begin idx := IndexOf(ToArrayList(attributes), attrType); if idx > -1 then Result := attributes[idx] else Result := nil; end; class function AttributeUtils.GetAttribute(attributes: AttributeCollection; attr: Attribute): Attribute; var idx: Integer; begin idx := IndexOf(ToArrayList(attributes), attr); if idx > -1 then Result := attributes[idx] else Result := nil; end; class function AttributeUtils.GetAttribute(attributes: AttributeCollection; attrType: System.Type): Attribute; var idx: Integer; begin idx := IndexOf(ToArrayList(attributes), attrType); if idx > -1 then Result := attributes[idx] else Result := nil; end; {$ENDREGION} end. --- NEW FILE: Jedi.Drawing.Colors.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Drawing.pas, released on 2004-05-16. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.Drawing.Colors.pas,v 1.1 2004/12/05 13:19:48 jedi_mbe Exp $ unit Jedi.Drawing.Colors; interface {$REGION 'interface uses'} uses System.Drawing; {$ENDREGION} {$REGION 'Color related'} type ColorUtils = class sealed (System.Object) public { Blends two colors. The resulting color will be a mix of the two colors. The percentage parameter determines how much of the second color will be present. } class function Blend(firstColor, secondColor: Color; percentage: Integer): Color; static; { Brightens a color. The resulting color will be a mix of the base color and pure white. The percentage parameter determines how much white will be present. } class function Brighten(baseColor: Color; percentage: Integer): Color; static; { Darkens a color. The resulting color will be a mix of the base color and pure black. The percentage parameter determines how much black will be present. } class function Darken(baseColor: Color; percentage: Integer): Color; static; end; {$ENDREGION} implementation {$REGION 'ColorUtils'} class function ColorUtils.Blend(firstColor, secondColor: Color; percentage: Integer): Color; begin Result := Color.FromArgb( firstColor.R + (secondColor.R - firstColor.R) * percentage div 100, firstColor.G + (secondColor.G - firstColor.G) * percentage div 100, firstColor.B + (secondColor.B - firstColor.B) * percentage div 100 ); end; class function ColorUtils.Brighten(baseColor: Color; percentage: Integer): Color; begin Result := ColorUtils.Blend(baseColor, Color.White, percentage); end; class function ColorUtils.Darken(baseColor: Color; percentage: Integer): Color; begin Result := ColorUtils.Blend(baseColor, Color.Black, percentage); end; {$ENDREGION} end. --- Jedi.Drawing.pas DELETED --- --- NEW FILE: Jedi.System.Strings.pas --- {--------------------------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Strings.pas, released on 2004-11-24. The Initial Developer of the Original Code is Marcel Bestebroer Portions created by Marcel Bestebroer are Copyright (C) 2004 Marcel Bestebroer All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} // $Id: Jedi.System.Strings.pas,v 1.1 2004/12/05 13:19:48 jedi_mbe Exp $ unit Jedi.System.Strings; interface {$REGION 'interface uses'} uses System.Collections, System.Text; {$ENDREGION} {$REGION 'String utilities'} type [Flags] ExtractQuotedStringFlags = (Default = 0, IgnoreGarbage = 1, EndQuoteMandetory = 2); StringUtils = class {$REGION 'TabSet class'} public type TabSet = class (&Object, ICloneable) strict private FTabs: ArrayList; FDefaultWidth: Integer; FUpdateCount: Integer; strict protected function IsAutoWidth: Boolean; function IsUpdating: Boolean; procedure RecalcDefaultWidth; public constructor Create; overload; constructor Create(defaultWidth: Integer); overload; constructor Create(tabs: array of Integer); overload; constructor Create(tabs: array of Integer; defaultWidth: Integer); overload; procedure Add(tabPosition: Integer); procedure BeginUpdate; procedure Clear; function Clone: &Object; virtual; procedure EndUpdate; function Equals(obj: &Object): Boolean; override; function RealDefaultWidth: Integer; procedure Remove(tabPosition: Integer; includeFollowing: Boolean = False); procedure RemoveAt(index: Integer; includeFollowing: Boolean = False); function TabFrom(pos: Integer): Integer; function get_Count: Integer; function get_DefaultWidth: Integer; function get_Tabs(index: Integer): Integer; procedure set_Tabs(index: Integer; value: Integer); procedure set_DefaultWidth(value: Integer); function ToString: string; override; property Count: Integer read get_Count; property DefaultWidth: Integer read get_DefaultWidth write set_DefaultWidth; property Tabs[index: Integer]: Integer read get_Tabs write set_Tabs; default; end; {$ENDREGION} strict protected constructor Create; public class function After(s: string; delimiter: System.Char): string; static; class function AfterAnyOf(s: string; delimiters: array of System.Char): string; static; class function AfterLast(s: string; delimiter: System.Char): string; static; class function AfterLastAnyOf(s: string; delimiters: array of System.Char): string; static; class function Before(s: string; delimiter: System.Char): string; static; class function BeforeAnyOf(s: string; delimiters: array of System.Char): string; static; class function BeforeLast(s: string; delimiter: System.Char): string; static; class function BeforeLastAnyOf(s: string; delimiters: array of System.Char): string; static; class function ExpandTabs(s: string; tabs: array of Int32): string; overload; static; class function ExpandTabs(s: string; tabs: array of Int32; additionalTabsWidth: Int32): string; overload; static; class function ExpandTabs(s: string; tabSet: TabSet): string; overload; static; class function ExtractQuotedString(s: string): string; overload; static; class function ExtractQuotedString(s: string; flags: ExtractQuotedStringFlags): string; overload; static; class function ExtractQuotedString(s: string; out lastUsedChar: Integer): string; overload; static; class function Left(s: string; length: Integer): string; static; class function Mid(s: string; from, &to: Integer): string; static; class function RemoveDuplicateChars(s: string; char: System.Char): string; overload; static; class function RemoveDuplicateChars(s: string; chars: array of System.Char): string; overload; static; class function &Repeat(s: string; count: Integer): string; static; class function Right(s: string; length: Integer): string; static; class function QuoteString(s: string): string; overload; static; class function QuoteString(s: string; quoteChar: Char): string; overload; static; end; {$ENDREGION} implementation {$AUTOBOX ON} {$REGION 'StringUtils'} constructor StringUtils.Create; begin inherited Create; end; class function StringUtils.After(s: string; delimiter: System.Char): string; var idx: Integer; begin idx := s.IndexOf(delimiter); if idx = -1 then Result := '' else Result := s.Substring(idx + 1); end; class function StringUtils.AfterAnyOf(s: string; delimiters: array of System.Char): string; var idx: Integer; begin idx := s.IndexOfAny(delimiters); if idx = -1 then Result := '' else Result := s.Substring(idx + 1); end; class function StringUtils.AfterLast(s: string; delimiter: System.Char): string; var idx: Integer; begin idx := s.LastIndexOf(delimiter); if idx = -1 then Result := '' else Result := s.Substring(idx + 1); end; class function StringUtils.AfterLastAnyOf(s: string; delimiters: array of System.Char): string; var idx: Integer; begin idx := s.LastIndexOfAny(delimiters); if idx = -1 then Result := '' else Result := s.Substring(idx + 1); end; class function StringUtils.Before(s: string; delimiter: System.Char): string; var idx: Integer; begin idx := s.IndexOf(delimiter); if idx = -1 then Result := s else Result := s.Substring(0, idx); end; class function StringUtils.BeforeAnyOf(s: string; delimiters: array of System.Char): string; var idx: Integer; begin idx := s.IndexOfAny(delimiters); if idx = -1 then Result := s else Result := s.Substring(0, idx); end; class function StringUtils.BeforeLast(s: string; delimiter: System.Char): string; var idx: Integer; begin idx := s.LastIndexOf(delimiter); if idx = -1 then Result := s else Result := s.Substring(0, idx); end; class function StringUtils.BeforeLastAnyOf(s: string; delimiters: array of System.Char): string; var idx: Integer; begin idx := s.LastIndexOfAny(delimiters); if idx = -1 then Result := s else Result := s.Substring(0, idx); end; class function StringUtils.ExpandTabs(s: string; tabs: array of Integer): string; begin Result := ExpandTabs(s, TabSet.Create(tabs)); end; class function StringUtils.ExpandTabs(s: string; tabs: array of Integer; additionalTabsWidth: Integer): string; begin Result := ExpandTabs(s, TabSet.Create(tabs, additionalTabsWidth)); end; class function StringUtils.ExpandTabs(s: string; tabSet: TabSet): string; var sb: StringBuilder; startIndex: Integer; idx: Integer; begin sb := StringBuilder.Create; startIndex := 0; repeat idx := s.IndexOf(#9, startIndex); if idx > -1 then begin if idx > startIndex then sb.Append(s.Substring(startIndex, idx - startIndex)); Inc(idx); startIndex := idx; idx := tabSet.TabFrom(sb.Length); sb.Append(' ', idx - sb.Length) end else sb.Append(s.Substring(startIndex)); until idx = -1; Result := sb.ToString; end; class function StringUtils.ExtractQuotedString(s: string): string; begin Result := ExtractQuotedString(s, ExtractQuotedStringFlags.EndQuoteMandetory); end; class function StringUtils.ExtractQuotedString(s: string; flags: ExtractQuotedStringFlags): string; var i: Integer; begin if s = '' then Result := '' else begin Result := ExtractQuotedString(s, i); if ((flags and ExtractQuotedStringFlags.IgnoreGarbage) <> ExtractQuotedStringFlags.IgnoreGarbage) and (i > 0) and (i <> (s.Length - 1)) then raise FormatException.Create('String ends in garbage.'); if ((flags and ExtractQuotedStringFlags.EndQuoteMandetory) = ExtractQuotedStringFlags.EndQuoteMandetory) and (not i = s.Length) then raise FormatException.Create('End quote missing.'); end; end; class function StringUtils.ExtractQuotedString(s: string; out lastUsedChar: Integer): string; var qteChar: Char; sb: StringBuilder; i: Integer; begin Result := ''; lastUsedChar := 0; if s.Length > 0 then begin qteChar := s.Chars[0]; if (qteChar = '''') or (qteChar = '"') then begin sb := StringBuilder.Create; repeat i := s.IndexOf(qteChar, lastUsedChar + 1); if i >= 0 then begin if i <> (lastUsedChar + 1) then sb.Append(s.Substring(lastUsedChar + 1, i - lastUsedChar - 1)); lastUsedChar := i; Inc(i); if (i < s.Length) and (s.Chars[i] = qteChar) then begin sb.Append(qteChar); Inc(lastUsedChar); end else i := -1; end else begin sb.Append(s.Substring(lastUsedChar + 1)); lastUsedChar := not s.Length; end; until i < 0; Result := sb.ToString; end else begin Result := s; lastUsedChar := s.Length - 1; end; end; end; class function StringUtils.Left(s: string; length: Integer): string; begin Result := s.Substring(0, length); end; class function StringUtils.Mid(s: string; from, &to: Integer): string; begin Result := s.Substring(from, &to - from + 1); end; class function StringUtils.RemoveDuplicateChars(s: string; char: System.Char): string; var lastFound: Integer; sb: StringBuilder; newFound: Integer; foundCh: System.Char; begin lastFound := 0; sb := StringBuilder.Create; repeat newFound := s.IndexOf(char, lastFound); if newFound > -1 then begin sb.Append(Mid(s, lastFound, newFound)); foundCh := s.Chars[newFound]; while (newFound < s.Length) and (s.Chars[newFound] = foundCh) do Inc(newFound); lastFound := newFound; end else sb.Append(s.Substring(lastFound)); until (newFound = -1) or (newFound >= s.Length); Result := sb.ToString; end; class function StringUtils.RemoveDuplicateChars(s: string; chars: array of System.Char): string; var lastFound: Integer; sb: StringBuilder; newFound: Integer; foundCh: System.Char; begin lastFound := 0; sb := StringBuilder.Create; repeat newFound := s.IndexOfAny(chars, lastFound); if newFound > -1 then begin sb.Append(Mid(s, lastFound, newFound)); foundCh := s.Chars[newFound]; while (newFound < s.Length) and (s.Chars[newFound] = foundCh) do Inc(newFound); lastFound := newFound; end else sb.Append(s.Substring(lastFound)); until (newFound = -1) or (newFound >= s.Length); Result := sb.ToString; end; class function StringUtils.&Repeat(s: string; count: Integer): string; var sb: StringBuilder; begin if count < 0 then raise ArgumentOutOfRangeException.Create('param', count, 'The count parameter must be zero or positive.'); sb := StringBuilder.Create(s.Length * count); while count > 0 do begin sb.Append(s); Dec(count); end; Result := sb.ToString; end; class function StringUtils.Right(s: string; length: Integer): string; begin Result := s.Substring(s.length - length, length); end; class function StringUtils.QuoteString(s: string): string; begin Result := QuoteString(s, ''''); end; class function StringUtils.QuoteString(s: string; quoteChar: Char): string; var sb: StringBuilder; lastQtePos: Integer; thisQtePos: Integer; begin sb := StringBuilder.Create(quoteChar, s.Length * 11 div 10); lastQtePos := 0; thisQtePos := s.IndexOf(quoteChar); while thisQtePos > -1 do begin sb.Append(s.Substring(lastQtePos, thisQtePos - lastQtePos)); sb.Append(quoteChar, 2); lastQtePos := thisQtePos + 1; thisQtePos := s.IndexOf(quoteChar, lastQtePos); end; sb.Append(s.Substring(lastQtePos)); sb.Append(quoteChar); Result := sb.ToString; end; {$ENDREGION} {$REGION 'StringUtils.TabSet'} constructor StringUtils.TabSet.Create; begin Create([], 0); end; constructor StringUtils.TabSet.Create(defaultWidth: Integer); begin Create([], defaultWidth); end; constructor StringUtils.TabSet.Create(tabs: array of Integer); begin Create(tabs, 0); end; constructor StringUtils.TabSet.Create(tabs: array of Integer; defaultWidth: Integer); var idx: Integer; begin if defaultWidth < 0 then raise ArgumentOutOfRangeException.Create('defaultWidth', defaultWidth, 'DefaultWidth must be zero or positive.'); inherited Create; if not Assigned(tabs) then FTabs := ArrayList.Create else FTabs := ArrayList.Create(&Array(tabs).Length); FDefaultWidth := defaultWidth; if Assigned(tabs) then begin BeginUpdate; try for idx := 0 to High(tabs) do Add(tabs[idx]); finally EndUpdate; end; end; end; procedure StringUtils.TabSet.Add(tabPosition: Integer); var idx: Integer; begin idx := FTabs.BinarySearch(tabPosition); if idx < 0 then begin FTabs.Insert(not idx, tabPosition); if IsAutoWidth and not IsUpdating then RecalcDefaultWidth; end else raise InvalidOperationException.Create('Duplicate positions are not allowed.'); end; procedure StringUtils.TabSet.BeginUpdate; begin Inc(FUpdateCount); end; procedure StringUtils.TabSet.Clear; begin FTabs.Clear; if IsAutoWidth and not IsUpdating then RecalcDefaultWidth; end; function StringUtils.TabSet.Clone: &Object; type IntArray = array of Integer; begin Result := StringUtils.TabSet.Create(IntArray(FTabs.ToArray(TypeOf(Integer))), DefaultWidth); end; procedure StringUtils.TabSet.EndUpdate; begin if IsUpdating then begin Dec(FUpdateCount); if not IsUpdating and IsAutoWidth then RecalcDefaultWidth; end; end; function StringUtils.TabSet.Equals(obj: &Object): Boolean; var firstSet: StringUtils.TabSet; secondSet: StringUtils.TabSet; tabPos: Integer; i: Integer; begin Result := &Object.ReferenceEquals(Self, obj); if not Result and (TypeOf(StringUtils.TabSet).IsInstanceOfType(obj)) then begin firstSet := StringUtils.TabSet(obj); if IsAutoWidth and IsUpdating then RecalcDefaultWidth; if firstSet.IsAutoWidth and firstSet.IsUpdating then firstSet.RecalcDefaultWidth; Result := RealDefaultWidth = firstSet.RealDefaultWidth; if firstSet.Count > Count then begin secondSet := firstSet; firstSet := Self; end else secondSet := Self; if Result and (firstSet.Count < secondSet.Count) then begin if firstSet.Count > 0 then begin tabPos := firstSet.Tabs[firstSet.Count - 1]; i := firstSet.Count; end else begin tabPos := 0; i := 0; end; while Result and (i < secondSet.Count) do begin Inc(tabPos, firstSet.RealDefaultWidth); Result := tabPos = secondSet.Tabs[i]; Inc(i); end; end; i := firstSet.Count - 1; while Result and (i >= 0) do begin Result := firstSet.Tabs[i] = secondSet.Tabs[i]; Dec(i); end; end; end; function StringUtils.TabSet.get_Count: Integer; begin Result := FTabs.Count; end; function StringUtils.TabSet.get_DefaultWidth: Integer; begin if IsAutoWidth then Result := 0 else Result := FDefaultWidth; end; function StringUtils.TabSet.get_Tabs(index: Integer): Integer; begin Result := Integer(FTabs[index]); end; function StringUtils.TabSet.IsAutoWidth: Boolean; begin Result := FDefaultWidth <= 0; end; function StringUtils.TabSet.IsUpdating: Boolean; begin Result := FUpdateCount > 0; end; function StringUtils.TabSet.RealDefaultWidth: Integer; begin if IsAutoWidth then Result := not FDefaultWidth else Result := FDefaultWidth; end; procedure StringUtils.TabSet.RecalcDefaultWidth; begin if FTabs.Count > 1 then FDefaultWidth := not (Tabs[FTabs.Count - 1] - Tabs[FTabs.Count - 2]) else if FTabs.Count = 1 then FDefaultWidth := not Tabs[0] else FDefaultWidth := not 2; end; procedure StringUtils.TabSet.Remove(tabPosition: Integer; includeFollowing: Boolean); var idx: Integer; begin idx := FTabs.BinarySearch(tabPosition); if (idx < 0) and includeFollowing then idx := not idx; if (idx >= 0) and (idx < FTabs.Count) then RemoveAt(idx, includeFollowing); end; procedure StringUtils.TabSet.RemoveAt(index: Integer; includeFollowing: Boolean); begin if (index < 0) or (index >= FTabs.Count) then raise ArgumentOutOfRangeException.Create('index', index, 'Index must be within {0} and {1}.'); if includeFollowing then FTabs.RemoveRange(index, FTabs.Count - index) else FTabs.RemoveAt(index); if IsAutoWidth and not IsUpdating then RecalcDefaultWidth; end; procedure StringUtils.TabSet.set_DefaultWidth(value: Integer); begin if value < 0 then raise ArgumentOutOfRangeException.Create('value', value, 'DefaultWidth must be zero or positive.'); if (value > 0) and (value <> FDefaultWidth) then FDefaultWidth := value else if (value = 0) and not IsAutoWidth then RecalcDefaultWidth; end; procedure StringUtils.TabSet.set_Tabs(index: Integer; value: Integer); var newIdx: Integer; begin if (index < FTabs.Count) and (Integer(FTabs[index]) <> value) or (index = FTabs.Count) then begin newIdx := FTabs.BinarySearch(value); if newIdx >= 0 then raise InvalidOperationException.Create('Duplicate positions are not allowed.'); newIdx := not newIdx; FTabs.RemoveAt(index); if newIdx >= index then Dec(newIdx); FTabs.Insert(newIdx, value); if IsAutoWidth and not IsUpdating then RecalcDefaultWidth; end; end; function StringUtils.TabSet.TabFrom(pos: Integer): Integer; var idx: Integer; begin idx := FTabs.BinarySearch(pos + 1); if idx < 0 then idx := not idx; if idx < FTabs.Count then Result := Integer(FTabs[idx]) else begin if FTabs.Count > 0 then Result := Integer(FTabs[idx - 1]) else Result := 0; while Result <= pos do Inc(Result, RealDefaultWidth); end; end; function StringUtils.TabSet.ToString: string; var sb: StringBuilder; enum: IEnumerator; begin sb := StringBuilder.Create; sb.Append('['); enum := FTabs.GetEnumerator; if FTabs.Count > 0 then begin while enum.MoveNext do begin sb.Append(Integer(enum.Current)); sb.Append(','); end; sb.Remove(sb.Length - 1, 1); end; sb.Append(']+'); sb.Append(RealDefaultWidth); if RealDefaultWidth <> DefaultWidth then sb.Append(' (automatic)'); Result := sb.ToString; end; {$ENDREGION} end. --- Jedi.IO.pas DELETED --- |