mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-07 20:58:18 +02:00
IDE: paste text in pascal source: convert unicode spaces to ascii spaces
This commit is contained in:
parent
7b487f5ead
commit
34b3b9a49a
@ -199,6 +199,7 @@ function ChompDottedIdentifier(const Identifier: string): string;
|
|||||||
function TrimCodeSpace(const ACode: string): string;
|
function TrimCodeSpace(const ACode: string): string;
|
||||||
function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean;
|
function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean;
|
||||||
function StringToPascalConst(const s: string): string;
|
function StringToPascalConst(const s: string): string;
|
||||||
|
function UnicodeSpacesToASCII(const s: string): string;
|
||||||
|
|
||||||
// string constants
|
// string constants
|
||||||
function SplitStringConstant(const StringConstant: string;
|
function SplitStringConstant(const StringConstant: string;
|
||||||
@ -5408,6 +5409,76 @@ begin
|
|||||||
Convert(Result);
|
Convert(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function UnicodeSpacesToASCII(const s: string): string;
|
||||||
|
var
|
||||||
|
p, StartP: PChar;
|
||||||
|
|
||||||
|
procedure Replace(Count: integer; const Insertion: string);
|
||||||
|
var
|
||||||
|
StartPos: integer;
|
||||||
|
begin
|
||||||
|
StartPos:=p-StartP;
|
||||||
|
LazStringUtils.ReplaceSubstring(Result,StartPos+1,Count,Insertion);
|
||||||
|
StartP:=PChar(Result);
|
||||||
|
p:=StartP+StartPos+length(Insertion);
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
c: Char;
|
||||||
|
CodepointLen: integer;
|
||||||
|
u: Cardinal;
|
||||||
|
begin
|
||||||
|
Result:=s;
|
||||||
|
if s='' then exit;
|
||||||
|
StartP:=PChar(Result);
|
||||||
|
p:=StartP;
|
||||||
|
repeat
|
||||||
|
c:=p^;
|
||||||
|
case c of
|
||||||
|
#0:
|
||||||
|
if (p-StartP=length(Result)) then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
inc(p);
|
||||||
|
#1..#191:
|
||||||
|
inc(p);
|
||||||
|
else
|
||||||
|
u:=UTF8CodepointToUnicode(p,CodepointLen);
|
||||||
|
if CodepointLen<=0 then
|
||||||
|
inc(p,1)
|
||||||
|
else begin
|
||||||
|
case u of
|
||||||
|
$200A, // hair space
|
||||||
|
$200B, // zero width space
|
||||||
|
$200C, // zero width non-joiner
|
||||||
|
$200D, // zero width joiner
|
||||||
|
$2060, // zero width word joiner
|
||||||
|
$FEFF // zero width no-break space
|
||||||
|
: Replace(CodepointLen,'');
|
||||||
|
$0020, // space
|
||||||
|
$00A0, // non breakable space
|
||||||
|
$2000, // en quad, half wide space
|
||||||
|
$2002, // en space, half wide space
|
||||||
|
$2004, // three-per-em space, 1/3 wide space
|
||||||
|
$2005, // four-per-em space, 1/4 wide space
|
||||||
|
$2006, // six-per-em space, 1/6 wide space
|
||||||
|
$2007, // figure space
|
||||||
|
$2008, // punctuation space
|
||||||
|
$2009, // thin space
|
||||||
|
$202F, // narrow non breakable space
|
||||||
|
$205F, // medium mathamtical space
|
||||||
|
$3000 // ideographic space
|
||||||
|
: Replace(CodepointLen,' ');
|
||||||
|
$2001, // em quad, wide space
|
||||||
|
$2003 // em space, wide space
|
||||||
|
: Replace(CodepointLen,' ');
|
||||||
|
end;
|
||||||
|
inc(p,CodepointLen);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
|
||||||
function SplitStringConstant(const StringConstant: string;
|
function SplitStringConstant(const StringConstant: string;
|
||||||
FirstLineLength, OtherLineLengths, Indent: integer;
|
FirstLineLength, OtherLineLengths, Indent: integer;
|
||||||
const aLineBreak: string): string;
|
const aLineBreak: string): string;
|
||||||
|
@ -5650,6 +5650,9 @@ var
|
|||||||
SemMode: TSemSelectionMode;
|
SemMode: TSemSelectionMode;
|
||||||
SemAction: TSemCopyPasteAction;
|
SemAction: TSemCopyPasteAction;
|
||||||
begin
|
begin
|
||||||
|
if (SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then
|
||||||
|
AText:=UnicodeSpacesToASCII(AText);
|
||||||
|
|
||||||
if Assigned(Manager) then begin
|
if Assigned(Manager) then begin
|
||||||
// call handlers
|
// call handlers
|
||||||
i:=Manager.FHandlers[semhtCopyPaste].Count;
|
i:=Manager.FHandlers[semhtCopyPaste].Count;
|
||||||
@ -5669,6 +5672,7 @@ begin
|
|||||||
if not CodeToolsOpts.IndentOnPaste then exit;
|
if not CodeToolsOpts.IndentOnPaste then exit;
|
||||||
if not (SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then
|
if not (SyntaxHighlighterType in [lshFreePascal, lshDelphi]) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
{$IFDEF VerboseIndenter}
|
{$IFDEF VerboseIndenter}
|
||||||
debugln(['TSourceEditor.EditorPaste LogCaret=',dbgs(ALogStartPos)]);
|
debugln(['TSourceEditor.EditorPaste LogCaret=',dbgs(ALogStartPos)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
Loading…
Reference in New Issue
Block a user