Sign in Join

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

Mailing lists / lazarus / 2008-06

I cannot use System.Length() to calculate visible width of string, now !

10 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

Андрей Гусев

Because Length() returns bytes count.
Have lazarus conventional function to calculate chars count in string, that do it independently from its binary representation ? "Length() div 2" is not conventional nor portable.

Reply by email

Graeme Geldenhuys
to Андрей Гусев

You mean like the UTF8Length() function in LCLProc unit?

Graeme.

?????? ????? wrote 10 lines
Because Length() returns bytes count. Have lazarus conventional function to calculate chars count in string, that do it independently from its binary representation ? "Length() div 2" is not conventional nor portable. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Vincent Snijders
to Graeme Geldenhuys
Graeme Geldenhuys wrote
You mean like the UTF8Length() function in LCLProc unit?

He mean that, but that is not independently from its binary representation: it assume UTF8 binary representation.

OTOH, I don't think you can make a function Length without telling it (implicitly or explicitly by using a parameter) the used encoding.

Show quoted text 6 lines
On 19/06/2008, ?????? ????? wrote: > Because Length() returns bytes count. > Have lazarus conventional function to calculate chars count in string, > that do it independently from its binary representation ? > "Length() div 2" is not conventional nor portable.

Vincent

Reply by email

Андрей Гусев
to Graeme Geldenhuys: You mean like the UTF8Length() function in LCLProc unit? Graeme. - Graeme -…

Yes. But UTF8Length() is portable between string encodings? Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport to choice between UTF8Length()/Length(). But maybe it already implemented as universal and conventional solution.

And, that adjanced questuion:
Lazarus, guessed, have a tool to recognize encoding by binary representation of string
(because Lazarus automatically recognize encodings in LFM files), so, how i can use it ?

Graeme Geldenhuys ?????:

Show quoted text 22 lines
You mean like the UTF8Length() function in LCLProc unit? Graeme. On 19/06/2008, ?????? ????? wrote: > Because Length() returns bytes count. > Have lazarus conventional function to calculate chars count in string, > that do it independently from its binary representation ? > "Length() div 2" is not conventional nor portable. > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > >

Reply by email

Felipe Monteiro de Carvalho
to Андрей Гусев
?????? ????? wrote
Yes. But UTF8Length() is portable between string encodings?

It only works in utf-8 strings

Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport to choice between UTF8Length()/Length(). But maybe it already implemented as universal and conventional solution.

Why do you want to support disabled WindowsUnicodeSupport?

Felipe Monteiro de Carvalho

Reply by email

Andrey Gu
to Felipe Monteiro de Carvalho

Felipe Monteiro de Carvalho ?????:

Show quoted text 8 lines
> Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport to > choice between UTF8Length()/Length(). But maybe it already > implemented as universal and conventional solution. > Why do you want to support disabled WindowsUnicodeSupport?

Caption strings in some forms of my project must be defined dynamically. Unit code, responsible to these strings definition and visible elemsnts dosposal, is universal and low-level.
I wouldn't like make assumtions about strings encoding in that code. That is my problem.
Have Lasarus way to solve it ?

Reply by email

Mattias Gaertner
to Andrey Gu
Show quoted text 11 lines
Felipe Monteiro de Carvalho ?????: >> Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport >> to choice between UTF8Length()/Length(). But maybe it already >> implemented as universal and conventional solution. >> > > Why do you want to support disabled WindowsUnicodeSupport? > > Caption strings in some forms of my project must be defined dynamically.

Do you mean like this:
http://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localizations_for_programs#Translating_Forms.2C_Datamodules_and_Frames

Show quoted text 5 lines
Unit code, responsible to these strings definition and visible elemsnts dosposal, is universal and low-level. I wouldn't like make assumtions about strings encoding in that code. That is my problem. Have Lasarus way to solve it ?

Why not use only UTF-8 like the IDE?

Mattias

Reply by email

Mattias Gaertner
to Андрей Гусев: Yes. But UTF8Length() is portable between string encodings? Solution is clean: i must use…
Show quoted text 10 lines
Yes. But UTF8Length() is portable between string encodings? Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport to choice between UTF8Length()/Length(). But maybe it already implemented as universal and conventional solution. And, that adjanced questuion: Lazarus, guessed, have a tool to recognize encoding by binary representation of string (because Lazarus automatically recognize encodings in LFM files), so, how i can use it ?

There is a simple heuristic.
The function is in lcl/lconvencoding.pas function GuessEncoding.

Mattias

Reply by email

Андрей Гусев Andrey Gusev
to Mattias Gaertner: On Fri, 20 Jun 2008 13:23:04 +0400 Do you mean like this:…

Mattias Gaertner ?????:

Show quoted text 23 lines
On Fri, 20 Jun 2008 13:23:04 +0400 "?????? ????? (Andrey Gusev)" wrote: > Felipe Monteiro de Carvalho ?????: > >>> Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport >>> to choice between UTF8Length()/Length(). But maybe it already >>> implemented as universal and conventional solution. >>> >>> >> Why do you want to support disabled WindowsUnicodeSupport? >> >> >> > Caption strings in some forms of my project must be defined > dynamically. > Do you mean like this: http://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localizations_for_programs#Translating_Forms.2C_Datamodules_and_Frames

Not.
I alreary rework my code generation scripts to get UTF8-sources.

Show quoted text 11 lines
> Unit code, responsible to these strings definition and > visible elemsnts dosposal, is universal and low-level. > I wouldn't like make assumtions about strings encoding in that > code. That is my problem. > Have Lasarus way to solve it ? > Why not use only UTF-8 like the IDE?

I wish to save maxumum compatibility level to (probably) backporting to Delphi.
Yes, yes, i must use {$ifdefs}.

Reply by email

Андрей Гусев Andrey Gusev
to Mattias Gaertner: On Thu, 19 Jun 2008 17:19:59 +0400 There is a simple heuristic. The function is in…

Mattias Gaertner ?????:

Show quoted text 20 lines
On Thu, 19 Jun 2008 17:19:59 +0400 ?????? ????? wrote: > Yes. But UTF8Length() is portable between string encodings? > Solution is clean: i must use check ifdef'ed WindowsUnicodeSupport to > choice between UTF8Length()/Length(). But maybe it already > implemented as universal and conventional solution. > > And, that adjanced questuion: > Lazarus, guessed, have a tool to recognize encoding by binary > representation of string > (because Lazarus automatically recognize encodings in LFM files), so, > how i can use it ? > There is a simple heuristic. The function is in lcl/lconvencoding.pas function GuessEncoding.

Thanks.

Reply by email