GfmlTkn.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2017 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.gfml;
  13. import gplx.types.commons.String_bldr;
  14. import gplx.types.commons.String_bldr_;
  15. public interface GfmlTkn extends GfmlObj {
  16. String TknType();
  17. String Raw();
  18. String Val();
  19. GfmlTkn[] SubTkns();
  20. GfmlBldrCmd Cmd_of_Tkn();
  21. GfmlTkn MakeNew(String raw, String val);
  22. }
  23. class GfmlTknAry_ {
  24. public static final GfmlTkn[] Empty = new GfmlTkn[0];
  25. public static GfmlTkn[] ary_(GfmlTkn... ary) {return ary;}
  26. public static String XtoRaw(GfmlTkn[] ary) {
  27. String_bldr sb = String_bldr_.new_();
  28. for (GfmlTkn tkn : ary)
  29. sb.Add(tkn.Raw());
  30. return sb.ToStr();
  31. }
  32. public static String XtoVal(GfmlTkn[] ary) {return XtoVal(ary, 0, ary.length);}
  33. static String XtoVal(GfmlTkn[] ary, int bgn, int end) {
  34. String_bldr sb = String_bldr_.new_();
  35. for (int i = bgn; i < end; i++) {
  36. GfmlTkn tkn = ary[i];
  37. sb.Add(tkn.Val());
  38. }
  39. return sb.ToStr();
  40. }
  41. }