Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-10

WrapText length limit?

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antônio

Is there any length limit to WrapText function? I have used it to a 3 paragraphs text and have got an error. The final part of the text was not wrapped.

Ant?nio

Reply by email

Maxim Ganetsky
to Antônio

06.10.2010 16:09, Ant?nio ?????:

Is there any length limit to WrapText function? I have used it to a 3 paragraphs text and have got an error. The final part of the text was not wrapped.

Please make a bug report and attach test project to it.

Best regards, Maxim Ganetsky mailto:

Reply by email

Antônio
to Felipe Monteiro de Carvalho

Lazarus 0.9.29 r24105 FPC 2.4.0 i386-win32-win32/win64 Windows XP

Ant?nio

2010/10/7 Felipe Monteiro de Carvalho :

Show quoted text 18 lines
On Wed, Oct 6, 2010 at 2:09 PM, Ant?nio wrote: > Is there any length limit to WrapText function? No there shouldn't be. Also, please always say which fpc, lazarus and operating systems versions you are using in posts about problems. thanks, -- Felipe Monteiro de Carvalho -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Felipe Monteiro de Carvalho
to Antônio

You could try updating to the latest rev. We are already at rev27595

If it doesn't work, then I recommend Maxim's instructions. A bug report + test project

For me wordwrap always worked.

Felipe Monteiro de Carvalho

Reply by email

Antônio
to Felipe Monteiro de Carvalho

I have found the Delphi function, which does not work fine also. It is:

function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet;
  MaxCol: Integer): string;
const
  QuoteChars = ['''', '"'];
var
  Col, Pos: Integer;
  LinePos, LineLen: Integer;
  BreakLen, BreakPos: Integer;
  QuoteChar, CurChar: Char;
  ExistingBreak: Boolean;
  L: Integer;
begin
  Col := 1;
  Pos := 1;
  LinePos := 1;
  BreakPos := 0;
  QuoteChar := #0;
  ExistingBreak := False;
  LineLen := Length(Line);
  BreakLen := Length(BreakStr);
  Result := '';
  while Pos <= LineLen do
  begin
    CurChar := Line[Pos];
    if CurChar in LeadBytes then
    begin
      L := CharLength(Line, Pos) - 1;
      Inc(Pos, L);
      Inc(Col, L);
    end
    else
    begin
      if CurChar in QuoteChars then
        if QuoteChar = #0 then
          QuoteChar := CurChar
        else if CurChar = QuoteChar then
          QuoteChar := #0;
      if QuoteChar = #0 then
      begin
        if CurChar = BreakStr[1] then
        begin
          ExistingBreak := StrLComp(Pointer(BreakStr),
Pointer(@Line[Pos]), BreakLen) = 0;
          if ExistingBreak then
          begin
            Inc(Pos, BreakLen-1);
            BreakPos := Pos;
          end;
        end;
        if not ExistingBreak then
          if CurChar in BreakChars then
            BreakPos := Pos;
      end;
    end;
    Inc(Pos);
    Inc(Col);
    if not (QuoteChar in QuoteChars) and (ExistingBreak or
      ((Col > MaxCol) and (BreakPos > LinePos))) then
    begin
      Col := 1;
      Result := Result + Copy(Line, LinePos, BreakPos - LinePos + 1);
      if not (CurChar in QuoteChars) then
      begin
        while Pos <= LineLen do
        begin
          if Line[Pos] in BreakChars then
          begin
            Inc(Pos);
            ExistingBreak := False;
          end
          else
          begin
            ExistingBreak := StrLComp(Pointer(@Line[Pos]), sLineBreak,
Length(sLineBreak)) = 0;
            if ExistingBreak then
              Inc(Pos, Length(sLineBreak))
            else
              Break;
          end;
        end;
      end;
      if (Pos <= LineLen) and not ExistingBreak then
        Result := Result + BreakStr;
      Inc(BreakPos);
      LinePos := BreakPos;
      Pos := LinePos;
      ExistingBreak := False;
    end;
  end;
  Result := Result + Copy(Line, LinePos, MaxInt);
end;
function WrapText(const Line: string; MaxCol: Integer): string;
begin
  Result := WrapText(Line, sLineBreak, [' ', '-', #9], MaxCol); { do
not localize }
end;

Ant?nio

Reply by email

Antônio
to Antônio
function CharLength(const S: string; Index: Integer): Integer;
begin
  Result := 1;
  assert((Index > 0) and (Index <= Length(S)));
  if SysLocale.FarEast and (S[Index] in LeadBytes) then
    Result := StrCharLength(PChar(S) + Index - 1);
end;

Reply by email

Antônio
to Bart

Delphi / Kylix Cross-Platform Runtime Library } { System Unit } { } { Copyright (c) 1988-2002 Borland Software Corporation } { } { This file may be distributed and/or modified under the terms of the } { GNU General Public License version 2 as published by the Free Software } { Foundation and appearing at http://www.borland.com/kylix/gpl.html.

Ant?nio

2010/10/7 Bart :

Show quoted text 26 lines
Please do not post copyrighted code here. Bart On 10/7/10, Ant?nio wrote: > function CharLength(const S: string; Index: Integer): Integer; > begin > ? Result := 1; > ? assert((Index > 0) and (Index <= Length(S))); > ? if SysLocale.FarEast and (S[Index] in LeadBytes) then > ? ? Result := StrCharLength(PChar(S) + Index - 1); > end; > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Michael Van Canneyt
to Antônio: Delphi / Kylix Cross-Platform Runtime Library } { System Unit …

That may be so, but then we would have to put the Borland copyright notice in all source files that use this. This is not possible/allowed.

Michael.

Ant?nio wrote 45 lines
Delphi / Kylix Cross-Platform Runtime Library } { System Unit } { } { Copyright (c) 1988-2002 Borland Software Corporation } { } { This file may be distributed and/or modified under the terms of the } { GNU General Public License version 2 as published by the Free Software } { Foundation and appearing at http://www.borland.com/kylix/gpl.html. Ant?nio 2010/10/7 Bart : > Please do not post copyrighted code here. > > Bart > > On 10/7/10, Ant?nio wrote: >> function CharLength(const S: string; Index: Integer): Integer; >> begin >> ? Result := 1; >> ? assert((Index > 0) and (Index <= Length(S))); >> ? if SysLocale.FarEast and (S[Index] in LeadBytes) then >> ? ? Result := StrCharLength(PChar(S) + Index - 1); >> end; >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Bart
to Antônio: Delphi / Kylix Cross-Platform Runtime Library } { System Unit …
Ant?nio wrote 11 lines
Delphi / Kylix Cross-Platform Runtime Library } { System Unit } { } { Copyright (c) 1988-2002 Borland Software Corporation } { } { This file may be distributed and/or modified under the terms of the } { GNU General Public License version 2 as published by the Free Software } { Foundation and appearing at http://www.borland.com/kylix/gpl.html. Ant?nio

My bad. Please forgive.

Bart

Reply by email