コード例 #1
0
 public int Make_tkn(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos) {
   Xop_tkn_itm tkn = tkn_mkr.Brack_bgn(bgn_pos, cur_pos);
   ctx.Subs_add_and_stack(root, tkn);
   return cur_pos;
 }
コード例 #2
0
ファイル: Xop_para_wkr.java プロジェクト: qq98982/xowa
 public int Process_pre(
     Xop_ctx ctx,
     Xop_tkn_mkr tkn_mkr,
     Xop_root_tkn root,
     byte[] src,
     int src_len,
     int bgn_pos,
     int cur_pos,
     int txt_pos) {
   Dd_clear(ctx);
   Btrie_slim_mgr tblw_ws_trie = ctx.App().Utl_trie_tblw_ws();
   Object o = tblw_ws_trie.Match_bgn(src, txt_pos, src_len);
   if (o != null) { // tblw_ws found
     Xop_tblw_ws_itm ws_itm = (Xop_tblw_ws_itm) o;
     byte tblw_type = ws_itm.Tblw_type();
     switch (tblw_type) {
       case Xop_tblw_ws_itm.Type_nl: // \n\s
         if (cur_mode == Mode_pre) { // already in pre; just process "\n\s"
           ctx.Subs_add(root, tkn_mkr.NewLine(bgn_pos, bgn_pos, Xop_nl_tkn.Tid_char, 1));
           prv_nl_pos =
               bgn_pos; // NOTE: must update prv_nl_pos; PAGE:en.w:Preferred_number DATE:2014-06-24
           return txt_pos;
         }
         break;
       case Xop_tblw_ws_itm.Type_xnde:
         int nxt_pos = tblw_ws_trie.Match_pos();
         if (nxt_pos < src_len) { // bounds check
           switch (src[
               nxt_pos]) { // check that next char is "end" of xnde name; guard against false
               // matches like "<trk" PAGE:de.v:Via_Jutlandica/Gpx DATE:2014-11-29
             case Byte_ascii.Space:
             case Byte_ascii.Nl:
             case Byte_ascii.Tab: // whitespace
             case Byte_ascii.Slash:
             case Byte_ascii.Gt: // end node
             case Byte_ascii.Quote:
             case Byte_ascii.Apos: // quotes
               if (bgn_pos != Xop_parser_.Doc_bgn_bos)
                 ctx.Para().Process_nl(ctx, root, src, bgn_pos, cur_pos);
               return ctx.Xnde().Make_tkn(ctx, tkn_mkr, root, src, src_len, txt_pos, txt_pos + 1);
           }
         }
         break;
       default:
         {
           int tblw_rv =
               ctx.Tblw()
                   .Make_tkn_bgn(
                       ctx,
                       tkn_mkr,
                       root,
                       src,
                       src_len,
                       bgn_pos,
                       txt_pos + ws_itm.Hook_len(),
                       false,
                       tblw_type,
                       Xop_tblw_wkr.Called_from_pre,
                       -1,
                       -1);
           if (tblw_rv
               != -1) // \n\s| is valid tblw tkn and processed; otherwise process pre-code below;
             // EX:w:Wikipedia:WikiProject_History/CategoryExample; DATE:2014-04-14
             return tblw_rv;
           break;
         }
     }
   }
   // NOTE: pre lxr emulates MW for "\n\s" by (1) calling Process nl for "\n"; (2) anticipating
   // next line by setting prv_ws_bgn
   // EX: "\na\n b\n"; note that "\n " is cur
   if (bgn_pos != Xop_parser_.Doc_bgn_bos) // if bos, then don't close 1st para
   Process_nl(
         ctx,
         root,
         src,
         bgn_pos,
         bgn_pos + 1); // note that tkn is \n\s; so, bgn_pos -> bgn_pos + 1 is \n ...
   if (cur_mode == Mode_pre) // in pre_mode
   ctx.Subs_add(
         root,
         tkn_mkr.Space(
             root, cur_pos,
             txt_pos)); // cur_pos to start after \s; do not capture "\s" in "\n\s"; (not sure why
   // not before \s)
   prv_ws_bgn = txt_pos - cur_pos + 1;
   return txt_pos;
 }