Sign in Join

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

Mailing lists / fpc-pascal / 2009-09

Problem with string manager

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Joao Morais

Hello list.

The following cgi script shows "??" in the browser if cwstring is declared, and works as expected if the declaration is removed. Is there something I can change in order to work with widestrings, cwstring and special chars? fixes_2_4 with linux.

Thanks.

Joao Morais

============================

{$mode objfpc}{$H+}
uses
  Classes, SysUtils, httpDefs, custcgi, cwstring;
type
  TCGIApp = class(TCustomCGIApplication)
  public
    procedure HandleRequest(ARequest: TRequest; AResponse: TResponse); override;
  end;
procedure TCGIApp.HandleRequest(ARequest: TRequest; AResponse: TResponse);
var
  ac: widestring;
begin
  ac := 'é';
  AResponse.Contents.Add(ac);
end;
begin
  with TCGIApp.Create(nil) do
    try
      Initialize;
      Run;
    finally
      Free;
    end;
end.

Reply by email

Jonas Maebe
to Joao Morais
Joao Morais wrote
The following cgi script shows "??" in the browser if cwstring is declared, and works as expected if the declaration is removed. Is there something I can change in order to work with widestrings, cwstring and special chars? fixes_2_4 with linux.

a) bug: you are not specifying to the compiler in what code page the strings in your source code are encoded. As a result, the compiler will assume it's the default (8859-1), unless their is an UTF-8 BOM (in which case the compiler parses it as UTF-8)
b) when you use cwstring, the RTL will convert any widestring you write to the current locale. Under *nix this is defined by the "LANG" environment variable (which in turn controls the various LC_* environment variables). If the current locale does not support the character you try to write, you will get question marks.

I guess what's happening if you don't use cwstring and don't specify a code page, that the compiler dumps the character as it appears in the source code straight into the widestring without any conversion, and that the rtl later on extracts it (when "converting" from widestring to ansistring) also without any conversion. So it only happens to work because the code page in which you wrote the source code happens to be the same as the code page that the browser at the other side uses as default.

Jonas

Reply by email

Joao Morais
to Jonas Maebe
Jonas Maebe wrote 25 lines
On 09 Sep 2009, at 21:10, Joao Morais wrote: > The following cgi script shows "??" in the browser if cwstring is > declared, and works as expected if the declaration is removed. Is > there something I can change in order to work with widestrings, > cwstring and special chars? fixes_2_4 with linux. a) bug: you are not specifying to the compiler in what code page the strings in your source code are encoded. As a result, the compiler will assume it's the default (8859-1), unless their is an UTF-8 BOM (in which case the compiler parses it as UTF-8) b) when you use cwstring, the RTL will convert any widestring you write to the current locale. Under *nix this is defined by the "LANG" environment variable (which in turn controls the various LC_* environment variables). If the current locale does not support the character you try to write, you will get question marks. I guess what's happening if you don't use cwstring and don't specify a code page, that the compiler dumps the character as it appears in the source code straight into the widestring without any conversion, and that the rtl later on extracts it (when "converting" from widestring to ansistring) also without any conversion. So it only happens to work because the code page in which you wrote the source code happens to be the same as the code page that the browser at the other side uses as default.

Thanks Jonas for your valuable comments.

Please, have a look at http://lpweb.com.br/dl/enc.html

I prepared this table in order to choose which configuration I should use. The best option is UTF-8 source without cwstring, but sometimes I need to link with libraries that uses this unit. What I am missing or which configuration I can change?

Joao Morais

Reply by email