mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Pull more classes into baselib
This commit is contained in:
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlAtr implements GfmlItm {
|
||||
public int ObjType() {return GfmlObj_.Type_atr;}
|
||||
public GfmlTkn KeyTkn() {return keyTkn;} GfmlTkn keyTkn; public String Key() {return keyTkn.Val();}
|
||||
@@ -21,10 +22,10 @@ public class GfmlAtr implements GfmlItm {
|
||||
public GfmlType Type() {return type;} GfmlType type;
|
||||
public boolean KeyedSubObj() {return true;}
|
||||
public int SubObjs_Count() {return subObjs.Len();}
|
||||
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.Get_at(i);} GfmlObjList subObjs = GfmlObjList.new_(); // PERF?: make capacity 3 instead of 8
|
||||
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.GetAt(i);} GfmlObjList subObjs = GfmlObjList.new_(); // PERF?: make capacity 3 instead of 8
|
||||
public void SubObjs_Add(GfmlObj o) {subObjs.Add(o);}
|
||||
public String To_str() {return String_.Concat(this.Key(), "=", this.DatTkn().Val());}
|
||||
@gplx.Internal protected void Key_set(String v) {keyTkn = GfmlTkn_.val_(v);} // used for 1 test
|
||||
public String ToStr() {return StringUtl.Concat(this.Key(), "=", this.DatTkn().Val());}
|
||||
public void Key_set(String v) {keyTkn = GfmlTkn_.val_(v);} // used for 1 test
|
||||
|
||||
public static GfmlAtr as_(Object obj) {return obj instanceof GfmlAtr ? (GfmlAtr)obj : null;}
|
||||
public static GfmlAtr string_(GfmlTkn keyTkn, GfmlTkn datTkn) {return new_(keyTkn, datTkn, GfmlType_.String);}
|
||||
@@ -48,7 +49,7 @@ public class GfmlAtr implements GfmlItm {
|
||||
}
|
||||
int GetTknIdx(GfmlTkn t) {
|
||||
for (int i = 0; i < subObjs.Len(); i++) {
|
||||
GfmlObj obj = (GfmlObj)subObjs.Get_at(i);
|
||||
GfmlObj obj = (GfmlObj)subObjs.GetAt(i);
|
||||
if (obj == t) return i;
|
||||
}
|
||||
return -1;
|
||||
@@ -58,15 +59,15 @@ public class GfmlAtr implements GfmlItm {
|
||||
if (oldTkn.SubTkns().length > 0) {
|
||||
GfmlTkn bgn = oldTkn.SubTkns()[0];
|
||||
GfmlTkn end = oldTkn.SubTkns()[oldTkn.SubTkns().length - 1];
|
||||
newStr = String_.Replace(newStr, bgn.Raw(), bgn.Raw() + bgn.Raw());
|
||||
newStr = StringUtl.Replace(newStr, bgn.Raw(), bgn.Raw() + bgn.Raw());
|
||||
if (bgn.Raw() != end.Raw())
|
||||
newStr = String_.Replace(newStr, end.Raw(), end.Raw() + end.Raw());
|
||||
newStr = StringUtl.Replace(newStr, end.Raw(), end.Raw() + end.Raw());
|
||||
return GfmlTkn_.composite_(oldTkn.TknType(), GfmlTknAry_.ary_(bgn, GfmlTkn_.raw_(newStr), end));
|
||||
}
|
||||
else {
|
||||
boolean hasQuote = String_.Has(newStr, "'");
|
||||
boolean hasQuote = StringUtl.Has(newStr, "'");
|
||||
if (hasQuote)
|
||||
return GfmlTkn_.composite_("composite", GfmlTknAry_.ary_(GfmlTkn_.new_("'", ""), GfmlTkn_.raw_(String_.Replace(newStr, "'", "''")), GfmlTkn_.new_("'", "")));
|
||||
return GfmlTkn_.composite_("composite", GfmlTknAry_.ary_(GfmlTkn_.new_("'", ""), GfmlTkn_.raw_(StringUtl.Replace(newStr, "'", "''")), GfmlTkn_.new_("'", "")));
|
||||
else
|
||||
return GfmlTkn_.raw_(newStr);
|
||||
}
|
||||
|
||||
@@ -13,21 +13,23 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
public class GfmlDoc {
|
||||
public GfmlNde RootNde() {return rootNde;} GfmlNde rootNde;
|
||||
@gplx.Internal protected List_adp UsrMsgs() {return usrMsgs;} List_adp usrMsgs = List_adp_.New();
|
||||
@gplx.Internal protected GfmlLxrRegy LxrRegy() {return lxrRegy;} GfmlLxrRegy lxrRegy = new GfmlLxrRegy();
|
||||
@gplx.Internal protected GfmlBldrCmdRegy CmdRegy() {return cmdRegy;} GfmlBldrCmdRegy cmdRegy = GfmlBldrCmdRegy.new_();
|
||||
@gplx.Internal protected GfmlPragmaMgr PragmaMgr() {return pragmaMgr;} GfmlPragmaMgr pragmaMgr = GfmlPragmaMgr.new_();
|
||||
@gplx.Internal protected GfmlLxr RootLxr() {return rootLxr;} GfmlLxr rootLxr;
|
||||
@gplx.Internal protected void RootLxr_set(GfmlLxr v) {rootLxr = v;}
|
||||
@gplx.Internal protected void Clear() {
|
||||
public List_adp UsrMsgs() {return usrMsgs;} List_adp usrMsgs = List_adp_.New();
|
||||
public GfmlLxrRegy LxrRegy() {return lxrRegy;} GfmlLxrRegy lxrRegy = new GfmlLxrRegy();
|
||||
public GfmlBldrCmdRegy CmdRegy() {return cmdRegy;} GfmlBldrCmdRegy cmdRegy = GfmlBldrCmdRegy.new_();
|
||||
public GfmlPragmaMgr PragmaMgr() {return pragmaMgr;} GfmlPragmaMgr pragmaMgr = GfmlPragmaMgr.new_();
|
||||
public GfmlLxr RootLxr() {return rootLxr;} GfmlLxr rootLxr;
|
||||
public void RootLxr_set(GfmlLxr v) {rootLxr = v;}
|
||||
public void Clear() {
|
||||
usrMsgs.Clear();
|
||||
rootNde = GfmlNde.named_(GfmlTkn_.cmd_("tkn.gfml.root_tkn", GfmlBldrCmd_pendingTkns_add.Instance), GfmlType_.Null);
|
||||
rootNde.DocPos_(GfmlDocPos_.Root);
|
||||
}
|
||||
@gplx.Internal protected static GfmlDoc new_() {
|
||||
public static GfmlDoc new_() {
|
||||
GfmlDoc rv = new GfmlDoc();
|
||||
rv.Clear();
|
||||
return rv;
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
class GfmlDocLxrs {
|
||||
@gplx.Internal protected static void Default_lxr(GfmlLxrRegy regy, GfmlLxr rootLxr) {
|
||||
public static void Default_lxr(GfmlLxrRegy regy, GfmlLxr rootLxr) {
|
||||
GfmlLxr[] ary = new GfmlLxr[] { GfmlDocLxrs.Whitespace_lxr()
|
||||
, GfmlDocLxrs.Quote0_Eval0_lxr()
|
||||
, GfmlDocLxrs.Quote1_lxr()
|
||||
@@ -44,10 +45,10 @@ class GfmlDocLxrs {
|
||||
}
|
||||
public static GfmlLxr Whitespace_lxr() {
|
||||
GfmlTkn tkn = GfmlTkn_.cmd_("key:gfml.whitespace_0", GfmlBldrCmd_whitespace.Instance);
|
||||
GfmlLxr rv = GfmlLxr_.range_("lxr:gfml.whitespace_0", String_.Ary(" ", String_.Tab, String_.CrLf, String_.Lf), tkn, false);
|
||||
GfmlLxr rv = GfmlLxr_.range_("lxr:gfml.whitespace_0", StringUtl.Ary(" ", StringUtl.Tab, StringUtl.CrLf, StringUtl.Nl), tkn, false);
|
||||
return rv;
|
||||
}
|
||||
public static GfmlLxr Comment0_lxr() {return GfmlLxr_.frame_("gfml.comment_0", GfmlFrame_.comment_(), "//", String_.Lf);}
|
||||
public static GfmlLxr Comment0_lxr() {return GfmlLxr_.frame_("gfml.comment_0", GfmlFrame_.comment_(), "//", StringUtl.Nl);}
|
||||
// public static GfmlLxr Comment0a_lxr() {return GfmlLxr_.frame_("gfml.comment_0b", GfmlFrame_.comment_(), "//", "\n");}
|
||||
public static GfmlLxr Comment1_lxr() {
|
||||
GfmlLxr rv = GfmlLxr_.frame_("gfml.comment_1", GfmlFrame_.comment_(), "/*", "*/");
|
||||
@@ -102,7 +103,7 @@ class GfmlDocLxrs {
|
||||
GfmlLxr rv = GfmlLxr_.frame_("gfml.quote_fold_0", GfmlFrame_.quote_(), "^'", "'^");
|
||||
|
||||
GfmlTkn tkn = GfmlTkn_.valConst_("key:gfml.quote_fold_0_whitespace", GfmlTkn_.NullVal, GfmlBldrCmd_whitespace.Instance);
|
||||
GfmlLxr whitespace = GfmlLxr_.range_("lxr:gfml.quote_fold_0_whitespace", String_.Ary(String_.Tab, String_.CrLf, String_.Lf), tkn, false);
|
||||
GfmlLxr whitespace = GfmlLxr_.range_("lxr:gfml.quote_fold_0_whitespace", StringUtl.Ary(StringUtl.Tab, StringUtl.CrLf, StringUtl.Nl), tkn, false);
|
||||
GfmlLxr escapeBgn = lxr_escape_("gfml.quote_fold_0_escape_bgn", "^'^'", "^'");
|
||||
GfmlLxr escapeEnd = lxr_escape_("gfml.quote_fold_0_escape_end", "'^'^", "'^");
|
||||
rv.SubLxr_Add(whitespace, escapeBgn, escapeEnd, rv); // NOTE: adding rv makes it recursive
|
||||
|
||||
@@ -13,10 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
package gplx.gfml;
|
||||
import gplx.types.commons.lists.CompareAble;
|
||||
import gplx.types.commons.lists.CompareAbleUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.commons.String_bldr;
|
||||
import gplx.types.commons.String_bldr_;
|
||||
public class GfmlDocPos implements CompareAble {
|
||||
public String Path() {if (path == null) MakePath(); return path;} private String path;
|
||||
public int compareTo(Object obj) {
|
||||
@@ -33,7 +35,7 @@ public class GfmlDocPos implements CompareAble {
|
||||
else if (origVal > compVal) return CompareAbleUtl.More;
|
||||
}
|
||||
if (ary.length < comp.ary.length) return CompareAbleUtl.Less; // less ary than comp, and whatever ary they share are equal; must be less
|
||||
return Int_.Compare(idx, comp.idx); // compare idx
|
||||
return IntUtl.Compare(idx, comp.idx); // compare idx
|
||||
}
|
||||
public GfmlDocPos NewClone() {return new GfmlDocPos(ary, idx);}
|
||||
public GfmlDocPos NewDown(int newIdx) {
|
||||
@@ -60,10 +62,10 @@ public class GfmlDocPos implements CompareAble {
|
||||
sb.Add("_");
|
||||
}
|
||||
sb.Add(idx);
|
||||
path = sb.To_str();
|
||||
path = sb.ToStr();
|
||||
}
|
||||
int[] ary; int idx;
|
||||
@gplx.Internal protected GfmlDocPos(int[] ary, int idx) {this.ary = ary; this.idx = idx;}
|
||||
public GfmlDocPos(int[] ary, int idx) {this.ary = ary; this.idx = idx;}
|
||||
}
|
||||
class GfmlDocPos_ {
|
||||
public static final GfmlDocPos Null = new GfmlDocPos(new int[0], -1);
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml;
|
||||
import gplx.types.commons.String_bldr;
|
||||
import gplx.types.commons.String_bldr_;
|
||||
public class GfmlDocWtr_ {
|
||||
public String To_str_and_clear() {return sb.To_str_and_clear();}
|
||||
public String To_str_and_clear() {return sb.ToStrAndClear();}
|
||||
public void BuildAttrib(GfmlAtr atr) {Build(atr);}
|
||||
public void BuildNode(GfmlNde nde) {Build(nde);}
|
||||
void Build(GfmlItm owner) {
|
||||
|
||||
@@ -13,9 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.errs.Err;
|
||||
import gplx.libs.dlgs.UsrMsg;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.utls.IntUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlDoc_ {
|
||||
public static GfmlDoc parse_any_eol_(String raw) {return parse(String_.Replace(raw, String_.CrLf, String_.Lf));}
|
||||
public static GfmlDoc parse_any_eol_(String raw) {return parse(StringUtl.Replace(raw, StringUtl.CrLf, StringUtl.Nl));}
|
||||
public static GfmlDoc parse(String raw) {
|
||||
GfmlBldr bldr = GfmlBldr_.default_();
|
||||
return bldr.XtoGfmlDoc(raw);
|
||||
@@ -31,13 +36,13 @@ class GfmlUsrMsgs {
|
||||
GfmlStringHighlighter sh = GfmlStringHighlighter.new_();
|
||||
sh.Raw_(raw).Mark_(bldr.StreamPos(), '*', "failed");
|
||||
um.Add("errorPos", bldr.StreamPos());
|
||||
um.Add("errorHighlight", String_.CrLf + String_.Concat_lines_crlf(sh.Gen()));
|
||||
um.Add("errorHighlight", StringUtl.CrLf + StringUtl.ConcatLinesCrlf(sh.Gen()));
|
||||
}
|
||||
public static Err gfmlParseError(GfmlBldr bldr) {
|
||||
Err rv = Err_.new_wo_type("gfml parse error");
|
||||
Err rv = ErrUtl.NewArgs("gfml parse error");
|
||||
for (int i = 0; i < bldr.Doc().UsrMsgs().Len(); i++) {
|
||||
UsrMsg um = (UsrMsg)bldr.Doc().UsrMsgs().Get_at(i);
|
||||
rv.Args_add("err" + Int_.To_str(i), um.To_str());
|
||||
UsrMsg um = (UsrMsg)bldr.Doc().UsrMsgs().GetAt(i);
|
||||
rv.ArgsAdd("err" + IntUtl.ToStr(i), um.To_str());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -13,15 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
public interface GfmlItm extends GfmlObj, To_str_able {
|
||||
GfmlTkn KeyTkn(); String Key(); // Key() is alternative to Key().Val()
|
||||
GfmlType Type();
|
||||
boolean KeyedSubObj();
|
||||
int SubObjs_Count();
|
||||
GfmlObj SubObjs_GetAt(int i);
|
||||
void SubObjs_Add(GfmlObj obj);
|
||||
}
|
||||
package gplx.gfml;
|
||||
import gplx.frameworks.objects.ToStrAble;
|
||||
public interface GfmlItm extends GfmlObj, ToStrAble {
|
||||
GfmlTkn KeyTkn(); String Key(); // Key() is alternative to Key().Val()
|
||||
GfmlType Type();
|
||||
boolean KeyedSubObj();
|
||||
int SubObjs_Count();
|
||||
GfmlObj SubObjs_GetAt(int i);
|
||||
void SubObjs_Add(GfmlObj obj);
|
||||
}
|
||||
class GfmlItm_ {
|
||||
public static GfmlItm as_(Object obj) {return obj instanceof GfmlItm ? (GfmlItm)obj : null;}
|
||||
}
|
||||
public static GfmlItm as_(Object obj) {return obj instanceof GfmlItm ? (GfmlItm)obj : null;}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
public class GfmlItmHnds {
|
||||
public int Count() {return list.Len();} List_adp list = List_adp_.New();
|
||||
public GfmlNde Get_at(int idx) {return (GfmlNde)list.Get_at(idx);}
|
||||
public GfmlNde Get_at(int idx) {return (GfmlNde)list.GetAt(idx);}
|
||||
public void Add(GfmlNde nde) {list.Add(nde);}
|
||||
public static GfmlItmHnds new_() {return new GfmlItmHnds();} GfmlItmHnds() {}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlItmKeys {
|
||||
public int Count() {return list.Len();}
|
||||
public boolean Has(String key) {return hash.Has(key);}
|
||||
public GfmlItm Get_at(int i) {return (GfmlItm)list.Get_at(i);}
|
||||
public GfmlItm Get_at(int i) {return (GfmlItm)list.GetAt(i);}
|
||||
public GfmlItm Get_by(String key) {return (GfmlItm)hash.GetByOrNull(key);}
|
||||
public String FetchDataOr(String key, String or) {
|
||||
GfmlAtr atr = FetchAtr(key);
|
||||
@@ -25,7 +31,7 @@ public class GfmlItmKeys {
|
||||
}
|
||||
public String FetchDataOrNull(String key) {return FetchDataOr(key, null);}
|
||||
public String FetchDataOrFail(String key) {
|
||||
GfmlAtr atr = FetchAtr(key); if (atr == null) throw Err_.new_missing_key(key);
|
||||
GfmlAtr atr = FetchAtr(key); if (atr == null) throw ErrUtl.NewMissingKey(key);
|
||||
return atr.DatTkn().Val();
|
||||
}
|
||||
public GfmlTkn FetchDataTknOrNull(String key) {
|
||||
@@ -36,10 +42,10 @@ public class GfmlItmKeys {
|
||||
String key = itm.Key();
|
||||
if (hash.Has(key)) DelDefault(itm); // default attribs are added automatically; drop default when adding newElm
|
||||
list.Add(itm);
|
||||
if (!String_.Eq(key, GfmlItmKeys.NullKey))
|
||||
if (!StringUtl.Eq(key, GfmlItmKeys.NullKey))
|
||||
RegisterKey(key, itm);
|
||||
}
|
||||
@gplx.Internal protected void RegisterKey(String key, GfmlItm itm) {
|
||||
public void RegisterKey(String key, GfmlItm itm) {
|
||||
if (hash.Has(key)) hash.Del(key); // replace default
|
||||
hash.Add(key, itm);
|
||||
}
|
||||
@@ -47,13 +53,13 @@ public class GfmlItmKeys {
|
||||
GfmlItm toDel = null;
|
||||
for (Object subObj : list) {
|
||||
GfmlItm sub = (GfmlItm)subObj;
|
||||
if (String_.Eq(sub.Key(), elm.Key()))
|
||||
if (StringUtl.Eq(sub.Key(), elm.Key()))
|
||||
toDel = sub;
|
||||
}
|
||||
if (toDel != null) list.Del(toDel);
|
||||
}
|
||||
GfmlAtr FetchAtr(String key) {return GfmlAtr.as_(hash.GetByOrNull(key));}
|
||||
List_adp list = List_adp_.New(); Hash_adp hash = Hash_adp_.New();
|
||||
List_adp list = List_adp_.New(); Hash_adp hash = Hash_adp_.New();
|
||||
public static GfmlItmKeys new_() {return new GfmlItmKeys();} GfmlItmKeys() {}
|
||||
@gplx.Internal protected static final String NullKey = "";
|
||||
public static final String NullKey = "";
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlNde implements GfmlItm {
|
||||
public static final int OBJ_TYPE = GfmlObj_.Type_nde;
|
||||
public int ObjType() {return objType;} int objType = GfmlObj_.Type_nde;
|
||||
@@ -22,7 +23,7 @@ public class GfmlNde implements GfmlItm {
|
||||
public boolean KeyedSubObj() {return keyedSubObj;} public GfmlNde KeyedSubObj_(boolean v) {keyedSubObj = v; return this;} private boolean keyedSubObj;
|
||||
public int ChainId() {return chainId;} public GfmlNde ChainId_(int v) {chainId = v; return this;} int chainId; // can use boolean chainHead, but this is easier for debugging
|
||||
public int SubObjs_Count() {return subObjs.Len();} GfmlObjList subObjs = GfmlObjList.new_();
|
||||
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.Get_at(i);}
|
||||
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.GetAt(i);}
|
||||
public void SubObjs_Add(GfmlObj gobj) {
|
||||
subObjs.Add(gobj);
|
||||
GfmlItm subItm = GfmlItm_.as_(gobj);
|
||||
@@ -38,11 +39,11 @@ public class GfmlNde implements GfmlItm {
|
||||
public GfmlDocPos DocPos() {return docPos;} GfmlDocPos docPos = GfmlDocPos_.Null;
|
||||
public GfmlItmKeys SubKeys() {return subKeys;} GfmlItmKeys subKeys = GfmlItmKeys.new_();
|
||||
public GfmlItmHnds SubHnds() {return subHnds;} GfmlItmHnds subHnds = GfmlItmHnds.new_();
|
||||
public String To_str() {return GfmlDocWtr_.xtoStr_(this);}
|
||||
public String ToStr() {return GfmlDocWtr_.xtoStr_(this);}
|
||||
public void UpdateNde(String hnd) {
|
||||
for (int i = 0; i < subHnds.Count(); i++) {
|
||||
GfmlNde nde = (GfmlNde)subHnds.Get_at(i);
|
||||
if (String_.Eq(nde.hndTkn.Raw(), hnd)) return;
|
||||
if (StringUtl.Eq(nde.hndTkn.Raw(), hnd)) return;
|
||||
}
|
||||
int endAtrPos = PosOf(false, ";", "}");
|
||||
GfmlTkn bgnParen = GfmlTkn_.new_("(", "");
|
||||
@@ -65,10 +66,10 @@ public class GfmlNde implements GfmlItm {
|
||||
int end = fwd ? subObjs.Len() : 0;
|
||||
int dif = fwd ? 1 : -1;
|
||||
for (int i = bgn; i != end; i+=dif) {
|
||||
GfmlObj subObj = (GfmlObj)subObjs.Get_at(i);
|
||||
GfmlObj subObj = (GfmlObj)subObjs.GetAt(i);
|
||||
GfmlTkn subTkn = GfmlTkn_.as_(subObj);
|
||||
if (subTkn == null) continue;
|
||||
if (String_.In(subTkn.Raw(), find)) {
|
||||
if (StringUtl.In(subTkn.Raw(), find)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -77,7 +78,7 @@ public class GfmlNde implements GfmlItm {
|
||||
public void UpdateAtr(String key, String val) {
|
||||
GfmlAtr atr = (GfmlAtr)subKeys.Get_by(key);
|
||||
if (atr != null) {atr.UpdateAtr(key, val); return;}
|
||||
val = String_.Replace(val, "'", "''");
|
||||
val = StringUtl.Replace(val, "'", "''");
|
||||
GfmlTkn quote = GfmlTkn_.new_("'", "");
|
||||
GfmlTkn keyTkn = GfmlTkn_.raw_(key);
|
||||
GfmlTkn valTkn = GfmlTkn_.composite_("composite", GfmlTknAry_.ary_(quote, GfmlTkn_.raw_(val), quote));
|
||||
@@ -94,18 +95,18 @@ public class GfmlNde implements GfmlItm {
|
||||
subObjs.Add_at(atr, endAtrPos);
|
||||
}
|
||||
|
||||
@gplx.Internal protected void ObjType_set_pragma() {objType = GfmlObj_.Type_prg;}
|
||||
@gplx.Internal protected void KeyTkn_set(GfmlTkn gobj) {keyTkn = gobj;}
|
||||
@gplx.Internal protected void Type_set(GfmlType val) {type = val;}
|
||||
@gplx.Internal protected void SubObjs_Clear() {subObjs.Clear();}
|
||||
@gplx.Internal protected GfmlTkn HndTkn() {return hndTkn;}
|
||||
@gplx.Internal protected void HndTkn_set(GfmlTkn tkn) {hndTkn = tkn;}
|
||||
@gplx.Internal protected void Hnd_set(String v) {hndTkn = String_.Len_eq_0(v) ? GfmlTkn_.Null : GfmlTkn_.val_(v);} // NOTE: v is empty for types with empty fldNames
|
||||
@gplx.Internal protected GfmlNde DocPos_(GfmlDocPos val) {docPos = val; return this;}
|
||||
public void ObjType_set_pragma() {objType = GfmlObj_.Type_prg;}
|
||||
public void KeyTkn_set(GfmlTkn gobj) {keyTkn = gobj;}
|
||||
public void Type_set(GfmlType val) {type = val;}
|
||||
public void SubObjs_Clear() {subObjs.Clear();}
|
||||
public GfmlTkn HndTkn() {return hndTkn;}
|
||||
public void HndTkn_set(GfmlTkn tkn) {hndTkn = tkn;}
|
||||
public void Hnd_set(String v) {hndTkn = StringUtl.IsNullOrEmpty(v) ? GfmlTkn_.Null : GfmlTkn_.val_(v);} // NOTE: v is empty for types with empty fldNames
|
||||
public GfmlNde DocPos_(GfmlDocPos val) {docPos = val; return this;}
|
||||
|
||||
public static GfmlNde as_(Object obj) {return obj instanceof GfmlNde ? (GfmlNde)obj : null;}
|
||||
@gplx.Internal protected static GfmlNde named_(GfmlTkn hndTkn, GfmlType type) {return new GfmlNde(hndTkn, type, false);}
|
||||
@gplx.Internal protected static GfmlNde new_(GfmlTkn hndTkn, GfmlType type, boolean keyedSubObj) {return new GfmlNde(hndTkn, type, keyedSubObj);}
|
||||
public static GfmlNde named_(GfmlTkn hndTkn, GfmlType type) {return new GfmlNde(hndTkn, type, false);}
|
||||
public static GfmlNde new_(GfmlTkn hndTkn, GfmlType type, boolean keyedSubObj) {return new GfmlNde(hndTkn, type, keyedSubObj);}
|
||||
GfmlNde(GfmlTkn hndTkn, GfmlType type, boolean keyedSubObj) {
|
||||
this.hndTkn = hndTkn; this.type = type; this.keyedSubObj = keyedSubObj;}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
package gplx.gfml;
|
||||
import gplx.types.commons.lists.CompareAbleUtl;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
import gplx.types.basics.lists.List_adp;
|
||||
import gplx.types.basics.lists.List_adp_;
|
||||
interface GfmlScopeItm {
|
||||
String Key();
|
||||
GfmlDocPos DocPos();
|
||||
|
||||
Reference in New Issue
Block a user