众所周知,String是不可变的.String不可变的原因是什么,StringBuilder类的引入是可变的?
我正在尝试调试仅在我的大型应用程序 - 在XE3中正常工作 - 在使用XE4编译后运行时才出现的行为.该问题似乎导致一些引用的字符串(例如"MyString")即使在由Web.HTTPProd中的TPageProducer"解除引用"之后仍保留其引号.例如,考虑以下代码,该代码是来自此Delphi源单元Web.HTTPApp的小提取:
procedure ExtractHeaderFields(Separators, _WhiteSpace: TSysCharSet; Content: PChar;
Strings: TStrings; Decode: Boolean; StripQuotes: Boolean = False);
{$ENDIF NEXTGEN}
var
Head, Tail: PChar;
EOS, InQuote, LeadQuote: Boolean;
QuoteChar: Char;
ExtractedField: string;
{$IFNDEF NEXTGEN}
WhiteSpaceWithCRLF: TSysCharSet;
SeparatorsWithCRLF: TSysCharSet;
{$ENDIF !NEXTGEN}
function DoStripQuotes(const S: string): string;
var
I: Integer;
InStripQuote: Boolean;
StripQuoteChar: Char;
begin
Result := S;
InStripQuote := False;
StripQuoteChar := #0;
if StripQuotes then
begin
for I := Result.Length - 1 downto 0 do
if Result.Chars[I].IsInArray(['''', '"']) then …Run Code Online (Sandbox Code Playgroud)