From 7135772aa02acd551cca85fc6a6676336c68f22a Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 10 Nov 2006 23:46:30 +0000 Subject: [PATCH] + ansistring overload of maybequoted git-svn-id: trunk@5324 - --- compiler/cutils.pas | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/compiler/cutils.pas b/compiler/cutils.pas index d632843cf3..3e8b9e03e5 100644 --- a/compiler/cutils.pas +++ b/compiler/cutils.pas @@ -87,6 +87,7 @@ interface function backspace_quote(const s:string;const qchars:Tcharset):string; function octal_quote(const s:string;const qchars:Tcharset):string; function maybequoted(const s:string):string; + function maybequoted(const s:ansistring):ansistring; {# If the string is quoted, in accordance with pascal, it is dequoted and returned in s, and the function returns true. @@ -782,6 +783,50 @@ implementation end; end; + function maybequoted(const s:ansistring):ansistring; + const + {$IFDEF MSWINDOWS} + FORBIDDEN_CHARS = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', + '{', '}', '''', '`', '~']; + {$ELSE} + FORBIDDEN_CHARS = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', + '{', '}', '''', ':', '\', '`', '~']; + {$ENDIF} + var + s1 : ansistring; + i : integer; + quoted : boolean; + begin + quoted:=false; + s1:='"'; + for i:=1 to length(s) do + begin + case s[i] of + '"' : + begin + quoted:=true; + s1:=s1+'\"'; + end; + ' ', + #128..#255 : + begin + quoted:=true; + s1:=s1+s[i]; + end; + else begin + if s[i] in FORBIDDEN_CHARS then + quoted:=True; + s1:=s1+s[i]; + end; + end; + end; + if quoted then + maybequoted:=s1+'"' + else + maybequoted:=s; + end; + + function maybequoted(const s:string):string; const {$IFDEF MSWINDOWS}