Forum > LCL

[CLOSED] Improvement of TApplication.IsRTLLang

(1/1)

lagprogramming:
lcl/include/application.inc has

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TApplication.IsRTLLang(const ALang: String): Boolean;var lng : String; p   : word;   function sep_pos : word; inline;  begin    Result := Pos('-', lng);    if Result = 0 then      Result := Pos('_', lng);  end; begin  lng    := LowerCase(ALang);  p      := sep_pos;  if p > 0 then     lng := copy(lng, 1, p-1);   Result := (lng = 'ar') or // Arabic            (lng = 'he') or // Hebrew            (lng = 'yi') or // Yiddish             // The languages bellow usually use arabic as the language name            (lng = 'dv') or            (lng = 'ps') or            (lng = 'az') or            (lng = 'fa') or            (lng = 'ks') or            (lng = 'ku') or            (lng = 'pa') or            (lng = 'sd') or            (lng = 'tk') or            (lng = 'ug') or            (lng = 'ur') { or               Not sure about the following languages ...               They do not have 2 letters ISO standard are they in use ?            (lng = 'jpr') or            (lng = 'syr') or            (lng = 'nqo') or            (lng = 'jrb')            }            ;end;
In order to match the result of the "Pos" function and the parameter of the "copy" function, variable "p" and nested function "sep_pos" have been changed from word to sizeint.
After that, the line "lng := copy(lng, 1, p-1);" has been replaced with "SetLength(lng, p-1);".
The modified function looks like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TApplication.IsRTLLang(const ALang: String): Boolean;var lng : String; p   : SizeInt;   function sep_pos : SizeInt; inline;  begin    Result := Pos('-', lng);    if Result = 0 then      Result := Pos('_', lng);  end; begin  lng    := LowerCase(ALang);  p      := sep_pos;  if p > 0 then     SetLength(lng, p-1);   Result := (lng = 'ar') or // Arabic            (lng = 'he') or // Hebrew            (lng = 'yi') or // Yiddish             // The languages bellow usually use arabic as the language name            (lng = 'dv') or            (lng = 'ps') or            (lng = 'az') or            (lng = 'fa') or            (lng = 'ks') or            (lng = 'ku') or            (lng = 'pa') or            (lng = 'sd') or            (lng = 'tk') or            (lng = 'ug') or            (lng = 'ur') { or               Not sure about the following languages ...               They do not have 2 letters ISO standard are they in use ?            (lng = 'jpr') or            (lng = 'syr') or            (lng = 'nqo') or            (lng = 'jrb')            }            ;end;
Here is the patch.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---diff --git a/lcl/include/application.inc b/lcl/include/application.incindex 10abe008b0..4f3cfcfc9f 100644--- a/lcl/include/application.inc+++ b/lcl/include/application.inc@@ -2464,9 +2464,9 @@ end; function TApplication.IsRTLLang(const ALang: String): Boolean; var  lng : String;- p   : word;+ p   : SizeInt; -  function sep_pos : word; inline;+  function sep_pos : SizeInt; inline;   begin     Result := Pos('-', lng);     if Result = 0 then@@ -2477,7 +2477,7 @@ begin   lng    := LowerCase(ALang);   p      := sep_pos;   if p > 0 then -    lng := copy(lng, 1, p-1);+    SetLength(lng, p-1);    Result := (lng = 'ar') or // Arabic             (lng = 'he') or // Hebrew

AlexTP:
Posted to https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40469

Navigation

[0] Message Index

Go to full version