#1 2016-03-14 18:50:10

Avatarx
Member
Registered: 2016-03-14
Posts: 6

Delphi SynMustache

I am new to Delphi SynMustache and I want to use it in some very important projects. So I've tryed to play a little bit more with templates and it seems that there is a problem with parsing from templates with non englisch texts. I mean special symbols from german language for example, like "ä", "ß", "ö" ...
To be more specific:

procedure TForm2.RenderTemplate;
var
  mustache: TSynMustache;
  jsonUFT16: string;
  templateUTF16: string;
  jsonUTF8: RawUTF8;
  templateUTF8: RawUTF8;
  jsonRBS: RawByteString;
  templateRBS: RawByteString;
  htmlOutput: string;
begin
  memOutput.Lines.Clear;

  // don't work for us
  memOutput.Lines.Add('Output using RawUTF8');
  templateUTF8 := memTemplate.Text;
  mustache := TSynMustache.Parse(templateUTF8);
  jsonUTF8 := memJSON.Text;
  htmlOutput := mustache.RenderJSON(jsonUTF8);
  memOutput.Lines.Add(htmlOutput);

  memOutput.Lines.Add('');

  // work for us
  memOutput.Lines.Add('Output using RawByteString');
  templateRBS := memTemplate.Text;
  mustache := TSynMustache.Parse(templateRBS);
  jsonRBS := memJSON.Text;
  htmlOutput := mustache.RenderJSON(jsonRBS);
  memOutput.Lines.Add(htmlOutput);
end;

So if I use RawByteString everything seems to be ok, but I'm not sure if that is the right way to go. Property "Template" is ok after parsing, but Tags doesn't recognise code page correctly and at end the result is not as awaited to be.

Is this possible bug or I'm doing something wrong?  sad

Offline

#2 2016-03-14 21:46:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: Delphi SynMustache

Use stringtoutf8 and utf8tostring functions from SynCommons.pas.
See also the documentation about RawUtf8.

Offline

#3 2016-03-15 07:41:37

Avatarx
Member
Registered: 2016-03-14
Posts: 6

Re: Delphi SynMustache

ok! Now it works with stringtoUTF8 and UTF8tostring. Just fine! Thank you!

Why don't you mention it in documentation for SynMustache?  smile

Offline

Board footer

Powered by FluxBB