Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WrapText for WideString in Delphi

Delphi has a WrapText function:

function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet; MaxCol: Integer): string;
function WrapText(const Line: string; MaxCol: Integer): string;

Now i need a version that handles WideStrings:

function WrapTextW(const Line: WideString; MaxCol: Integer): WideString;

Is any such function written somewhere already?

WARNING: Not every wide string character is 2-bytes

Which is why i'm afraid to write it

Update: Example of a character that takes more than 2-bytes to represent:

Capital Latin W with ring and cedilla

  • Bytes: 57 00 66 03 27 03
  • Rendered in Chrome 17: enter image description here
  • Rendered in Internet Explorer 9: enter image description here
  • Rendered in Notepad using Segoe UI: enter image description here
  • Rendered in Notepad using Consolas: enter image description here
  • Rendered in your browser in sans-serif font: W̧̊
  • Rendered in your browser in monospaced font: W̧̊
like image 315
Ian Boyd Avatar asked Mar 14 '12 14:03

Ian Boyd


1 Answers

As mentioned by kobik, TNT UnicodeControls has a unit TntSysUtils which includes following function :

function WideWrapText(const Line, BreakStr: WideString; const BreakChars: TSysCharSet;
  MaxCol: Integer): WideString; overload;
function WideWrapText(const Line: WideString; MaxCol: Integer): WideString; overload;

Alternate download site is here.

like image 81
LU RD Avatar answered Oct 17 '22 01:10

LU RD