diff options
Diffstat (limited to 'prototypes/miglayout/gui_mig_constraintparser.pas')
-rw-r--r-- | prototypes/miglayout/gui_mig_constraintparser.pas | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/prototypes/miglayout/gui_mig_constraintparser.pas b/prototypes/miglayout/gui_mig_constraintparser.pas new file mode 100644 index 00000000..5f91c135 --- /dev/null +++ b/prototypes/miglayout/gui_mig_constraintparser.pas @@ -0,0 +1,78 @@ +unit gui_mig_constraintparser; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, gui_mig_lc; + +type + TConstraintParser = class(TObject) + public + function ParseLayoutConstraint(const s: string): TLC; + end; + +implementation + +uses + gfx_tokenlibrary; + +{ TConstraintParser } + +function TConstraintParser.ParseLayoutConstraint(const s: string): TLC; +var + tokenizer: TTokens; + parts: TStringList; + part: string; + i: integer; + len: integer; +begin + result := TLC.Create; + + if s = '' then + Exit; + + tokenizer := TTokens.Create(s, ',', '"', '"', '\', tsSingleSeparatorBetweenTokens); + parts := TStringList.Create; + for i := 1 to tokenizer.TokenCount do + parts.Add(trim(tokenizer.Token(i))); + tokenizer.Free; + + // First check for "ltr" or "rtl" since that will affect the interpretation + // of the other constraints. + for i := 0 to parts.Count-1 do + begin + part := parts[i]; + if part = '' then + continue; + + len := Length(part); + if (len = 3) or (len = 11) then // optimization + begin + if (part = 'ltr') or (part = 'rtl') or (part = 'lefttoright') or (part = 'righttoleft') then + begin + result.LeftToRight := part[1] = 'l'; + parts[i] := ''; // so we don't process it again + end; + if (part = 'ttb') or (part = 'btt') or (part = 'toptobottom') or (part = 'bottomtotop') then + begin + result.TopToBottom := part[1] = 't'; + parts[i] := ''; // so we don't process it again + end; + end; + end; + + for i := 0 to parts.Count-1 do + begin + part := parts[i]; + if part = '' then + continue; + + end; + + parts.Free; +end; + +end. + |