/usr/lib/lazarus/0.9.30.4/ideintf/texttools.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | {
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Author: Mattias Gaertner
Abstract:
Interface to various IDE tools manipulating text.
}
unit TextTools;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms;
{ Sorting }
type
TSortDirection = (sdAscending, sdDescending);
TSortDomain = (sdWords, sdLines, sdParagraphs);
TShowSortSelectionDialogFunc = function(const TheText: string;
Highlighter: TObject; var SortedText: string): TModalResult;
TSortTextFunc = function(const TheText: string; Direction: TSortDirection;
Domain: TSortDomain; CaseSensitive, IgnoreSpace: boolean): string;
var
ShowSortSelectionDialogFunc: TShowSortSelectionDialogFunc;
SortTextFunc: TSortTextFunc;
{ Regular expressions
This is a simple interface to regular expressions. The syntax is similar
to Perl regular expressions. An illegal pattern will raise an Exception.
Important: These functions are not thread safe!
REMatches - function to test a regular expression.
REVar - function to read the bracket values, found in the last call
of REMatches.
The ModifierStr sets the default values of r.e.syntax modifiers. Modifiers
in r.e. (?ismx-ismx) will replace this default values.
If you try to set unsupported modifier, Error will be called
Modifier /i - caseinsensitive, initialized from RegExprModifierI
Modifier /s - '.' works as any char (else as [^\n]),
Modifier /g - Turns all operators to non-greedy. e.g. '*' works as '*?',
all '+' as '+?' and so on.
Modifier /m - Treat string as multiple lines. That is, change `^' and `$'
from matching at only the very start or end of the string to
the start or end of any line anywhere within the string.
Examples:
if REMatches('Lazarus','aza') then ...
if REMatches('Lazarus','a(.)a') then
s:=REVar(1); // this will be the 'z'
}
var
REException: ExceptClass; // initialized by the IDE
function REMatches(const TheText, RegExpr: string;
const ModifierStr: string = ''; StartPos: integer = 1): boolean;
function REVar(Index: Integer): string; // 1 is the first
procedure REVarPos(Index: Integer; out MatchStart, MatchLength: integer);
function REVarCount: Integer;
function REReplace(const TheText, FindRegExpr, ReplaceRegExpr: string;
UseSubstutition: boolean;
const ModifierStr: string = ''): string;
function RESplit(const TheText, SeparatorRegExpr: string;
const ModifierStr: string = ''): TStrings;
procedure RESplit(const TheText, SeparatorRegExpr: string; Pieces: TStrings;
const ModifierStr: string = '');
// xml paths
function GetPathElement(const Path: string; StartPos: integer;
Stopper: char): string;
//------------------------------------------------------------------------------
// Internal stuff.
type
TREMatchesFunction = function(const TheText, RegExpr, ModifierStr: string;
StartPos: integer): boolean;
TREVarFunction = function(Index: Integer): string;
TREVarPosProcedure = procedure(Index: Integer;
out MatchStart, MatchLength: integer);
TREVarCountFunction = function: Integer;
TREReplaceProcedure = function(const TheText, FindRegExpr,
ReplaceRegExpr: string; UseSubstutition: boolean;
const ModifierStr: string): string;
TRESplitFunction = procedure(const TheText, SeparatorRegExpr: string;
Pieces: TStrings; const ModifierStr: string);
var
REMatchesFunction: TREMatchesFunction = nil; // initialized by the IDE ...
REVarFunction: TREVarFunction = nil;
REVarPosProcedure: TREVarPosProcedure = nil;
REVarCountFunction: TREVarCountFunction = nil;
REReplaceProcedure: TREReplaceProcedure = nil;
RESplitFunction: TRESplitFunction = nil;
implementation
function REMatches(const TheText, RegExpr: string;
const ModifierStr: string; StartPos: integer): boolean;
begin
Result:=REMatchesFunction(TheText,RegExpr,ModifierStr,StartPos);
end;
function REVar(Index: Integer): string;
begin
Result:=REVarFunction(Index);
end;
procedure REVarPos(Index: Integer; out MatchStart, MatchLength: integer);
begin
REVarPosProcedure(Index,MatchStart,MatchLength);
end;
function REVarCount: Integer;
begin
Result:=REVarCountFunction();
end;
function REReplace(const TheText, FindRegExpr, ReplaceRegExpr: string;
UseSubstutition: boolean; const ModifierStr: string): string;
begin
Result:=REReplaceProcedure(TheText,FindRegExpr,ReplaceRegExpr,UseSubstutition,
ModifierStr);
end;
procedure RESplit(const TheText, SeparatorRegExpr: string; Pieces: TStrings;
const ModifierStr: string);
begin
RESplitFunction(TheText,SeparatorRegExpr,Pieces,ModifierStr);
end;
function RESplit(const TheText, SeparatorRegExpr: string;
const ModifierStr: string): TStrings;
begin
Result:=TStringList.Create;
RESplit(TheText,SeparatorRegExpr,Result,ModifierStr);
end;
function GetPathElement(const Path: string; StartPos: integer;
Stopper: char): string;
var
p: LongInt;
begin
p:=StartPos;
while (p<=length(Path)) and (Path[p]<>Stopper) do inc(p);
Result:=copy(Path,StartPos,p-StartPos);
end;
end.
|